1

I am using this event: sales_quote_save_after This is my function code:

public function myFunction(Varien_Event_Observer $o){
    $quote = $o->getEvent()->getQuote();
}

I have simple products and bundle products. I would like to remove only simple products. How can I do that?

Thx

1
  • 1
    This will require you removing items from the quote, then re-saving the quote which will trigger a sales_quote_save_after event again. This is dangerous grounds for an infinite loop unless you're careful. Your best bet is to remove the items before saving the quote. Commented Mar 3, 2017 at 9:15

1 Answer 1

0

Try below code :

 $quote = $o->getEvent()->getQuote();
 $quoteItems=$quote->getAllItems();
 if(count($quoteItems)>0){
    foreach($quoteItems as $oneItem){
        $product = Mage::getModel('catalog/product')->load($oneItem->getProductId());
        $productType=$product ->getTypeId();
        if($productType=='simple'){
          $quote->removeItem($oneItem->getId());
        }
    }
   $quote->collectTotals()->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.