AppDev
AppDev

Reputation: 2907

Magento - How to check when a item has been added to cart

I would like to know if anyone can answer the following question. How can you check when an item has been added to the cart?
I need to do some highlighting when a item has been added, but i can't figure out how.

Anyone know?

I'm rather new at magento, so sorry for my noobish question :)

Upvotes: 2

Views: 1907

Answers (1)

user971401
user971401

Reputation:

You can retrieve the cart items like this :

$items = Mage::getSingleton('checkout/cart')->getItems();
foreach($items as $item) {
    $product = Mage::getModel('catalog/product')
               ->loadByAttribute('sku',$item->getSku());
    //... 
}

or another way would be to handle the product add to cart event, maybe it fits your needs better, as Mage will do this :

Mage::dispatchEvent('checkout_cart_product_add_after',
                    array('quote_item' => $result, 'product' => $product));

right after adding the product to the cart.

Upvotes: 4

Related Questions