I need to get at cart what category the product came from. The problem is that the product is added to several different categories, and I need the category in which the user accessed to add the product to the cart. I tried many different things but I couldn't get out of the place. Has anyone done something like this before?
1 Answer
magento does not store product category name where user added it. You need to do customise it.
For it you need to create custom column in order_item and quote_item table and with observer (checkout_cart_product_add_before) need to save current category name.
Current category
$category = Mage::registry('current_category');
$categoryid =$category->getId();
-
That's not what I'm looking for. I need to know which categories the product belongs to, which customer used to add to cart. Example: the product is in "Category A" and "Category B". I need to know in the cart which of the two the user used.– lucasCommented May 5, 2022 at 6:58
-
-
yes, but getCategoryIds returns all categories that the product belongs to, and the store I'm working with the product is in too many categories. I need the exact category that was used in the purchase.– lucasCommented May 5, 2022 at 7:03
-
as my knowledge, Magento does not save information that user added product from which categoies pages, You need to customise it with event. You pass your category name in before add to cart events and save it on quote and sales order table.– S.PCommented May 5, 2022 at 7:07
-
1