Get Id of product being removed from Product Compare
-
16-10-2019 - |
سؤال
I am trying to get the id of the product being removed from the Compare Products list. I have successfullye caught the event catalog_product_compare_remove_product
but when i try to the the id of the product using $productId = $observer->getEvent()->getProduct()->getId();
all I get is a counter that increases with one every time i delete a product from the Compare Products list.
Doing the same when catching the event catalog_product_compare_add_product
returns the product ID as expected.
So, my question is: What is this counter and how can i get the actual prouduct Id
المحلول
Try with
$productId = $observer->getEvent()->getProduct()->getProductId();
In this case the entity passed to the observer is not an instance of Mage_Catalog_Model_Product
. It is an instance of Mage_Catalog_Model_Product_Compare_Item
.
When calling getId
on that you get the increment id of the item to compare from the table catalog_compare_item
.