Looking at events.xml
of Magento_SalesRule
there are two events,
<event name="sales_order_place_after">
<observer name="salesrule" instance="Magento\SalesRule\Observer\SalesOrderAfterPlaceObserver" />
</event>
<event name="sales_model_service_quote_submit_before">
<observer name="salesrule" instance="Magento\SalesRule\Observer\AddSalesRuleNameToOrderObserver" />
</event>
but none looks like the one i need. I needed the same for when adding a coupon but i managed to do something if "pluggin in" the canProcessRule
method of Magento\SalesRule\Model\Utility
but i cant find something similar for when the coupon is removed
Theese operations like add and remove a coupon are made only in JS? There is a controller that process this?
Looking at checkout_index_index.xml
layout it pass an item argument Magento_SalesRule/js/view/payment/discount
which then loads theese two js
Magento_SalesRule/js/action/set-coupon-code
Magento_SalesRule/js/action/cancel-coupon
That by the name itself looks pretty straightforward, one to add and one to remove the coupon
In the cancel-coupon JS doing a console.log to url return:
rest/default/V1/guest-carts/21229ffad7bf01311b645a4423a4ae22/coupons
This is using rest web services? (Kind of same url for when adding a coupon)
There is a way to know when a coupon is removed from the quote/cart?