I have an observer which is configured in my module
File : app\code\MStack\Exchange\etc\frontend\events.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_quote_address_collect_totals_after">
<observer name="changeTaxTotal" instance="MStack\Exchange\Observer\ChangeTaxTotal"/>
</event>
</config>
File : app\code\MStack\Exchange\Observer\ChangeTaxTotal.php
<?php
namespace MStack\Exchange\Observer;
use \Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\Event\Observer;
class ChangeTaxTotal implements ObserverInterface
{
public $additionalTaxAmt = 2;
public function execute(Observer $observer)
{
/** @var Magento\Quote\Model\Quote\Address\Total */
$total = $observer->getData('total');
$total->addTotalAmount('tax', $this->additionalTaxAmt);
return $this;
}
}
As you can see, I am listening to the event sales_quote_address_collect_totals_after
. I am checking this from cart page and obviously this event is firing from there.
I can see that, my event is listening when page loads. But it is not listening for api calls which are asserted by Magento in order to calculate totals (for example, if you try to use : Estimate Shipping and Tax). I can point out the urls which are not firing my observer.
www.mydomain.com/index.php/rest/default/V1/guest-carts/e192be2e994b1228be16487655004adc/totals-information
So why my observer is not listening for such API request ? How can I change my code so that it will work for API request ?