Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Identifying only the items modified in a cart update
 
crashrox
Jr. Member
 
Total Posts:  6
Joined:  2013-04-01
 

I have an observer on “checkout_cart_update_items_after\. I’d like to identify which items were modified/deleted in the cart. I’ve been playing with ->getEvent()->getCart()->getQuote()->getAllItems() but its a full list of the items in the cart. I had originally hoped that “checkout_cart_product_update_after” would have been fired for each individual item that was modified, but that doesn’t seem to be the case. Are there any methods for identifying just the items that changed?

 
Magento Community Magento Community
Magento Community
Magento Community
 
crashrox
Jr. Member
 
Total Posts:  6
Joined:  2013-04-01
 

I came up with a pretty simple solution that seems to be working. Added an observer to checkout_cart_save_after with the following code:

public function cart_save_after(Varien_Event_Observer $observer{
    $quote 
$observer->getEvent()->getCart()->getQuote();
    
$items $quote->getAllItems();

    foreach(
$items as $item{
        
if(!count($item->getOrigData())) {
            
// New Item
        
elseif(count($item->getOrigData()) && $item->getQty() != $item->getOrigData('qty')) {
            
// Modified Item
        
}
    }   
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top