1

I'm trying to create a form to be able to add multiple simple products to the cart with one click like this page:

http://www.bikebandit.com/oem-parts/2015-honda-cbr1000rr/o/m156896#sch907940

all the similar questions I have seen either have no answers are for different versions or suggest using ajax [we are not using ajax]

How can Magento be configured to be able to add multiple products WITH amounts to the cart with one click?

1

You want the feature "grouped products" instead of simple product. Try it!

| improve this answer | |
0

There are many ways you can achieve this. As you mention you want to do it for simple products. You can create your own controller and add products to cart.

You will need to pass product ids in hidden array and create your custom action to add product in cart.

<?php 
class Custom_Module_AddController extends Mage_Core_Controller_Front_Action {

    public function addProductAction() {
        $products = $this->getRequest()->getParam('products');
        $cart = Mage::getModel('checkout/cart');
        $cart->init();
        /* @var $pModel Mage_Catalog_Model_Product */
        foreach ($products as $product_id) {
            if ($product_id == '') {
                continue;
            }
            $pModel = Mage::getModel('catalog/product')->load($product_id);
            if ($pModel->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) {
                try {
                    $cart->addProduct($pModel, array('qty' => '1'));
                }
                catch (Exception $e) {
                    continue;
                }
            }
        }
        $cart->save();
        $this->_redirect('checkout/cart');
    }
 }
?>

You can also pass qty in form with product array.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.