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 1


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.
    – lucas
    May 5 at 6:58
  • Are you looking for order item's category name right?
    – S.P
    May 5 at 7:01
  • 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.
    – lucas
    May 5 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.P
    May 5 at 7:07
  • 1
    Let us continue this discussion in chat.
    – S.P
    May 5 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.