Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RestoreCustomerGroupId.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Customer\Helper\Address as CustomerAddress;
14 
19 {
26 
30  public function __construct(CustomerAddress $customerAddressHelper)
31  {
32  $this->customerAddressHelper = $customerAddressHelper;
33  }
34 
41  public function execute(Observer $observer)
42  {
44  $shippingAssignment = $observer->getEvent()->getShippingAssignment();
46  $quote = $observer->getEvent()->getQuote();
47 
48  $address = $shippingAssignment->getShipping()->getAddress();
49  $configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType();
50  // Restore initial customer group ID in quote only if VAT is calculated based on shipping address
51  if ($address->hasPrevQuoteCustomerGroupId() &&
52  $configAddressType == AbstractAddress::TYPE_SHIPPING
53  ) {
54  $quote->setCustomerGroupId($address->getPrevQuoteCustomerGroupId());
55  $address->unsPrevQuoteCustomerGroupId();
56  }
57  }
58 }
$quote
$address
Definition: customer.php:38