Question

Ive got an issue where grouped products are not being recognized as the same thing as the downloadable product being added to the cart which makes different cart items instead of just increasing the quantity on the last cart item.

So just to explain that a bit more:

  • Grouped Product (sku: dog-stuff)
    • Downloadable Product linked to group product (sku: dog-bone)

I then programmatically add dog-bone to the cart..

My Cart shows:

  • dog-bone from grouped product
  • dog-bone from downloadable product

Hopefully that makes sense. Im trying to get them to group as the same cart item with a quantity of 2 instead of seperate items..

Here is my code to add product to cart..

    $sku = isset($_POST['sku']) ? $_POST['sku']:null;
    if(is_null($sku)){
        echo json_encode(false);
        exit;
    }
    $storeId = Mage::app()->getStore()->getId();
    $product = Mage::getModel('catalog/product')->load(Mage::getModel('catalog/product')->getIdBySku($sku))->setStoreId($storeId);
    $qty = 1;
    $quote = Mage::getSingleton('checkout/session')->getQuote();
    $item = $quote->addProduct($product, $qty);
    $quote->save();
Was it helpful?

Solution

This does the trick..

            $storeId = Mage::app()->getStore()->getId();
            $parentId = Mage::getModel('catalog/product')->getIdBySku($parentSku);
            $childId = Mage::getModel('catalog/product')->getIdBySku($childSku);
            $superGroup = array($childId => 1); //1 is qty
            $params = array('super_group' => $superGroup);


            $product = Mage::getModel('catalog/product')->load($parentId)->setStoreId($storeId);
            $cart = Mage::getModel('checkout/cart');
            $cart->addProduct($product, $qty)->save();
            Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top