0

I want to remove the bundle product from cart programmatically I am using

`$skunew="demobundle";
     $bundled_product_id = Mage::getModel("catalog/product")->loadByAttribute('sku',trim($skunew));
     $cartHelper = Mage::helper('checkout/cart');
        $items = $cartHelper->getCart()->getItems();
        foreach ($items as $item) {
            if ($item->getProduct()->getId() == $bundled_product_id) {
                $itemId = $item->getItemId();
                $cartHelper->getCart()->removeItem($itemId)->save();     
                break;
            }
        }`

In my cart bundle product sku="demobundle-demoprod1-demoprod4-demoprod5" give me some solution.how to remove or how to update this bundle.

3
  • And what is the problem with your code? Does it not remove the item? Does it do something else? Do you get an error Commented Aug 1, 2016 at 14:38
  • @fschmengler actually I am updating bundle product programmatically from cart and adding it to cart but it is creating one more product with error message of some selections are missing.so want to remove the product from cart.
    – coder
    Commented Aug 2, 2016 at 4:39
  • sounds like an xy-problem to me. Instead of removing a product that you did not want to add in the first place it would be better to fix your code to not add this product. Commented Aug 2, 2016 at 16:08

1 Answer 1

0

Please try the following code.

$cart = Mage::getModel('checkout/cart')->getQuote();
$items = $cart->getAllItems();

foreach ($items as $_item){
   $_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());

   if($_product->getTypeId()=== Mage_Catalog_Model_Product_Type::TYPE_BUNDLE){
       $options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
       Mage::helper('checkout/cart')->getCart()->removeItem($options['info_buyRequest']['product'])->save();
   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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