Reputation: 218
I want to call event/observer when user click on "clear shopping cart button" which perform some action on database. i search a lot but didn't find any specific solution. please anyone will give me the solution that Which event is calling on clear shopping cart button in magento?
Upvotes: 3
Views: 939
Reputation: 2669
Try this event controller_action_predispatch_checkout_cart_updatePost
.
And your config.xml file should be,
<?xml version="1.0"?>
<config>
<modules>
<Packagename_ModuleName>
<version>0.1.0</version>
</Packagename_ModuleName>
</modules>
<global>
<helpers>
<modulename>
<class>Packagename_ModuleName_Helper</class>
</modulename>
</helpers>
<models>
<modulename>
<class>Packagename_ModuleName_Model</class>
<resourceModel>modulename_mysql4</resourceModel>
</modulename>
</models>
<events>
<controller_action_predispatch_checkout_cart_updatePost> <!-- identifier of the event we want to catch -->
<observers>
<controller_action_predispatch_checkout_cart_updatePost_handler> <!-- identifier of the event handler -->
<type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
<class>modulename/observer</class> <!-- observers class alias -->
<method>clearCart</method> <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</controller_action_predispatch_checkout_cart_updatePost_handler>
</observers>
</controller_action_predispatch_checkout_cart_updatePost>
</events>
</global>
</config>
And Model/Observer.php :
<?php
class Packagename_ModuleName_Model_Observer
{
public function clearCart(Varien_Event_Observer $observer)
{
//execute only in empty the cart function(all items removed )
$updateAction = (string)Mage::app()->getRequest()->getParam('update_cart_action'); if ($updateAction != 'empty_cart') return;
echo "got it"; exit;
//your stuffs goes here.
}
}
Note: It is not triggered when we clear single cart (product) item . I tested it in my localserver and it is working fine.
Upvotes: 4