Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddVatRequestParamsOrderComment.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  $orderInstance = $observer->getOrder();
46  $orderAddress = $this->_getVatRequiredSalesAddress($orderInstance);
47  if (!$orderAddress instanceof Address) {
48  return;
49  }
50 
51  $vatRequestId = $orderAddress->getVatRequestId();
52  $vatRequestDate = $orderAddress->getVatRequestDate();
53  if (is_string($vatRequestId)
54  && !empty($vatRequestId)
55  && is_string($vatRequestDate)
56  && !empty($vatRequestDate)
57  ) {
58  $orderHistoryComment = __('VAT Request Identifier')
59  . ': ' . $vatRequestId . '<br />'
60  . __('VAT Request Date') . ': ' . $vatRequestDate;
61  $orderInstance->addStatusHistoryComment($orderHistoryComment, false);
62  }
63  }
64 
72  protected function _getVatRequiredSalesAddress($order, $store = null)
73  {
74  $configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType($store);
75  $requiredAddress = $configAddressType === AbstractAddress::TYPE_SHIPPING
76  ? $order->getShippingAddress()
77  : $order->getBillingAddress();
78 
79  return $requiredAddress;
80  }
81 }
$order
Definition: order.php:55
__()
Definition: __.php:13