1

In my Magento 2.1.8 installation, I have few special categories like recommended-by-site-owner AND prices-soon-to-increase. I add few products to these categories on my site every week and remove few others.

I need to track in my orders which product was added to cart from each of these categories or was it added outside of these categories.

If a customer adds a product let's say 'iPhone Darth Vader' casing to a single cart from each of these categories and a third addition from outside of these two special categories. I need to track each category's share in the cart item's quantity.

Can anyone suggest a solution a close-to-requirement extension that I can purchase and customize further.

EDIT :

  1. I also need to track the category if a customer goes to the product detail page from the category page and then adds the product to cart.

  2. I also have a mobile app that is built some another team. I need to provide an API for them as well for this functionality.

1
  • I am also want to implement same logic in my project. can you give me more information to make it. i am using checkout_cart_product_add_after event observer. want to know how to add product in cart with category check.
    – ni3solanki
    May 2, 2018 at 14:08

1 Answer 1

0

Following below steps might be helpful if customer is adding product after landing to the category page:

  1. Add a new columnn product_category in sales_order_item table

  2. Use registry to find the current category of the product like:

    public function getCurrentCategory() { return $this->_registry->registry('current_category'); }

3.Set this value in checkout session as an array value with product_id as key and category as value foreach of the products which are being added to cart, you can achieve this on observer event checkout_cart_product_add_after

4.After the order is placed, set this session value on the newly created column using foreach, this can be achieved by using observer event checkout_submit_all_after

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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