I want to get the product SKU while removing it from the cart or when emptying the cart.
1 Answer
Besides the controller pre|post
dispatch events that don't do you much good, though you can still use them controller_action_predispatch_checkout_cart_delete
and controller_action_postdispatch_checkout_cart_delete
, you can use this one
sales_quote_remove_item
.
You can get the sku like this:
public function deleteItem($observer)
{
$item = $observer->getEvent()->getQuoteItem();
$sku = $item->getSku();
//do something with $sku
}
For the empty cart action you will have to use the general controller event controller_action_predispatch_checkout_cart_updatePost
.
And you can get the skus like this:
public function emptyCart($observer)
{
$action = Mage::app()->getRequest()->getParam('update_cart_action');
if ($action == 'empty_cart') {
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
$skus = array();
foreach ($items as $item) {
$skus[] = $item->getSku();
}
//do something with $skus
}
}