4

I am using checkout_cart_product_add_after and checkout_cart_product_update_after events for making customization using observer on front-end this works properly there but in admin side this events are not working.

I guess this events are only for front-end. can any one please tell me how to implement this event observer in admin or any other event which is equivalent to this events.

2 Answers 2

5

Best idea to use sales_quote_product_add_after .

$this->_eventManager->dispatch('sales_quote_product_add_after', ['items' => $items]);

This event is fire when an item will added in and when item will be update

For this event, you can current quote items list using $observer->getItems()

This event is fire both for frontend and backend

0
1

Where is your events.xml situated? In etc, etc/frontend or etc/adminhtml? If it's only in etc/frontend you need to move you events.xml to etc, or add an events.xml-file to your etc/adminhtml-folder with a similar event.

Another thing could be that the checkout is indeed something that is frontend-only. If you're using the admin, you're not using a checkout, but you're creating a quote / order. In that case you might want to take a look at Magento\Sales\Controller\Adminhtml\Order\Create\Save(). This is the controller that handles the saving of an order from the admin and might be a good starting point.

If I'm running through the code I finally come to a method called Magento\Sales\Model\AdminOrder\Create::createOrder(). This order dispatches an event called checkout_submit_all_after, but because it's a public method as well you could also use a plugin / interceptor for this, depending on your needs. Make sure to put your di.xml or events.xml in the etc/adminhtml-folder, otherwise they might collide with your previously checkout-related events. It could be even possible that if you hook into this method, the checkout-events can already be obsolete.

I hope this helps you a bit. I haven't tried it out, but I think it should do the trick.

1

Your Answer

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

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