Magento 1.9: Get product id from wishlist remove item event -
when remove item wishlist, need product id of item. please me on this.
see code below:
config.xml
<wishlist_item_save_after> <observers> <data_wishlist_delete> <class>data/observer</class> <method>deletefromwishlist</method> </data_wishlist_delete> </observers> </wishlist_item_save_after>
observer.php
public function deletefromwishlist() { $item = mage::app()->getrequest()->getparam('item'); $action = mage::app()->getrequest()->getactionname(); if (($action == 'remove') && !empty($item)) { $resource = mage::getsingleton('core/resource'); $readconnection = $resource->getconnection('core_read'); $query = 'select product_id wishlist_item wishlist_item_id = ' . $item . ' limit 1'; $id = $readconnection->fetchone($query); echo 'product id: ' . $id . '<br/>'; } else { return; } }
the product id not getting here because record in wishlist_item table deleting when remove item wishlist.
we can resolve issue adding observer on wishlist remove event controller_action_predispatch_wishlist_index_remove
config.xml
<events> <controller_action_predispatch_wishlist_index_remove> <observers> <data_wishlist_delete> <class>data/observer</class> <method>deletefromwishlist</method> </data_wishlist_delete> </observers> </controller_action_predispatch_wishlist_index_remove> </events>
and update function in observer.php product id below.
public function deletefromwishlist() { $item = mage::app()->getrequest()->getparam('item'); if($item){ $item = mage::getmodel('wishlist/item')->load($item); $productid = $item->getproductid(); } }
Comments
Post a Comment