Namespace_Modulename_Model_ObserverI need to create an event/observer to clear cart before a product is being added. The checkout process will include only one product. Could anybody give me a hand?
I have the following code so far, but I'm doing something wrong:
In config.xml I have:
<frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<clear_cart_observer>
<type>singleton</type>
<class>Namespace_Modulename_Model_Observer</class>
<method>clearCart</method>
</clear_cart_observer>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
Also, I have created an observer file which contains:
public function clearCart($observer)
{
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ) {
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
}
}
I don't get any error in my system.log, but it doesn't trigger. Any ideas?
You likely need to fix this:
<class>Namespace_Modulename_Model_Observer</class>
And ensure that you have the module loaded in:
app/etc/modules/Namespace_Modulename.xml
Don't forget to flush cache.