I have created custom checkout_cart_save_before observer in magento by create the following files


<?xml version="1.0"?>
                <Mage_Contacts />


<?xml version="1.0"?>

and app/code/local/Cart/Override/Model/Qtyc/Observer.php

class Cart_Override_Model_Qtyc_Observer extends Varien_Event_Observer

    public function checkout_cart_save_before($observer)
        $action  = Mage::app()->getFrontController()->getAction();
        $product = $observer->getProduct();
        echo "<pre>";
        echo "</pre>";


The observer is working fine, when i click the add to cart button it is going to checkout_cart_save_before function. But i could not get the product values from the observer using the following code inside the checkout_cart_save_before function

$product = $observer->getProduct();

I have to add something for get the product details from the observer parameter?....any guess??

1 Answer 1


The event itself does not have the products directly. See where it is being called:

Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

You only have the cart object as a parameter to the event. You can get the items from the cart and find the product from each item.

$items = $observer->getEvent()->getCart()->getItems()

Will give you the cart items collection.

And then you would need to run this:

foreach($items as $item) {
    $product = $item->getProduct();
    //here you do what you want with the product.
  • 1
    Voting is easier than answering... damn thief :D Commented May 20, 2014 at 17:43
  • @David How to avoid add to cart with an error message in this situation? Can you please help ? Commented Dec 9, 2015 at 8:41

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.