Adding multiple products to the cart simultaneously in Magento (Part 2)

A while ago I wrote about adding multiple products to the shopping cart simultaneously. It turns out this seems to have stopped working from Magento 1.4 or so. Up until now, I’ve not really had the time to look in detail to figure out why. Finally, this evening, I got some time. So I dug deeper.

It turns out there seems to have been some changes in the way models persist their data, and unsetting and unloading/resetting them didn’t seem to cut it any more. Anyway, below is a fixed version of the previous post. Tested on and

This is a replacement for the file app/code/local/BTS/AddMultipleProducts/controllers/AddController.php;

        $cart = Mage::getModel('checkout/cart');
        /* @var $pModel Mage_Catalog_Model_Product */
        foreach ($products as $product_id) {
            if ($product_id == '') {
            $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) {
        if ($this->getRequest()->isXmlHttpRequest()) {


Join the Conversation


  1. Thanks, but i can not add product to cart if product is “Configurable Product” my store have an “size” Attribute

Leave a comment

Your email address will not be published. Required fields are marked *