customerAddressHelper = $customerAddressHelper; } /** * Restore initial customer group ID in quote if needed on collect_totals_after event of quote address * * @param Observer $observer * @return void */ public function execute(Observer $observer) { /** @var ShippingAssignmentInterface $shippingAssignment */ $shippingAssignment = $observer->getEvent()->getShippingAssignment(); /** @var Quote $quote */ $quote = $observer->getEvent()->getQuote(); $address = $shippingAssignment->getShipping()->getAddress(); $configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType(); // Restore initial customer group ID in quote only if VAT is calculated based on shipping address if ($address->hasPrevQuoteCustomerGroupId() && $configAddressType == AbstractAddress::TYPE_SHIPPING ) { $quote->setCustomerGroupId($address->getPrevQuoteCustomerGroupId()); $address->unsPrevQuoteCustomerGroupId(); } } }