Abhijit Dutta Abhijit Dutta - 1 month ago 13
PHP Question

Magento Add multiple products to cart from cms page

I am trying to add multiple products to cart from a cms page.How to achieve this.
Here is my code:

<div class="bulkorder">

<div class="container">

<h1 class="text-uppercase">Customer Portal</h1>

<div class="text-right">

<button type="button" title="Add to Cart" class="button btn-cart" onclick="addmultiple()"><span><span>Add to Cart</span></span></button>

</div>

<div class="table-responsive">

<table class="table table-bordered">
<!-- <caption>Optional table caption.</caption>-->
<thead>

<tr>
<th>&nbsp;</th>

<th>SKU</th>

<th>Product Name</th>

<th>Qty</th>

<th>Price</th>

</tr>

</thead>

<tbody>

<?php

$collection = Mage::getModel('catalog/product')->getCollection();

foreach ($collection as $_product) :

$_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($_product->getId());


if($_product->getTypeId() == "configurable"):

$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);

$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();

foreach($simple_collection as $simple_product){
echo $simple_product->getId().',';

?>
<tr>
<th><input type="checkbox"></th>

<td><?php echo $simple_product->getSku(); ?></td>
<td>

<?php echo $simple_product->getName(); ?>

<?php // echo 'color'. $simple_product->getResource()->getAttribute('color')->getFrontend()->getValue($simple_product); ?>

</td>
<td><select class="csselect">

<option>1</option>
</select>


</td>
<td>

<?php echo Mage::helper('core')->currency($simple_product->getPrice()); ?>

<?php $c=$simple_product->getData('color');echo $additional = array("color"=> $c);
?>
<button type="button" id="addcart<?php echo $simple_product->getId() ?>" onclick="setLocation('<?php echo (string)Mage::helper('checkout/cart')->getAddUrl(Mage::getModel('catalog/product')->load($simple_product->getId()),$additional);?>')" class="submit">

<span>ADD To Cart</span><img src="<?php echo $this->getSkinUrl('images/add-to-cart.png'); ?>">

</button>

</td>

</tr>

<?php

}
endif;

endforeach ?>
</tbody>

</table>

</div>

<div class="text-right">


<button type="button" title="Add to Cart" class="button btn-cart" onclick="addmultiple()"><span><span>Add to Cart</span></span>

</button>

</div>
</div>
</div>


I tried using query string to add multiple products. But it is not working. If ajax call can be used that would be great . I also need the quantity for each product to be different .

Answer

What means 'Sorting with pagination'?

When you get data from your database, let's say, using SQL, you may get already sorted data.

Something like SELECT * FROMTABLEORDER BYSOMETHINGASC