Reputation: 193
I need to create an "add to cart" button in my upsell.phtml file to add two or more products to the cart.
I have the id of those products and now i had to add them to the cart with a single "add to cart" button, quantity is always be 1.
Thanks in advance.
Upvotes: 1
Views: 1804
Reputation: 964
try to use this code
<?php $productids = $_POST['prod_ids']; ?>
<?php foreach($productids as $productid): ?>
<?php $my_product = Mage::getModel('catalog/product')->load($productid); ?>
<?php $cart = Mage::getModel('checkout/cart'); ?>
<?php $cart->init(); ?>
<?php $cart->addProduct($my_product, array('qty' => 1)); ?>
<?php $cart->save(); ?>
<?php Mage::getSingleton('checkout/session')->setCartWasUpdated(true); ?>
<?php endforeach; ?>
Upvotes: 0
Reputation: 896
Do this:
Upvotes: 1