Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxAddressManager.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Tax\Model;
7 
11 
16 {
22  private $customerSession;
23 
27  public function __construct(Session $customerSession)
28  {
29  $this->customerSession = $customerSession;
30  }
31 
39  {
40  if ($this->isDefaultBilling($address)) {
41  $this->customerSession->setDefaultTaxBillingAddress(
42  [
43  'country_id' => $address->getCountryId(),
44  'region_id' => $address->getRegion() ? $address->getRegionId() : null,
45  'postcode' => $address->getPostcode(),
46  ]
47  );
48  }
49  if ($this->isDefaultShipping($address)) {
50  $this->customerSession->setDefaultTaxShippingAddress(
51  [
52  'country_id' => $address->getCountryId(),
53  'region_id' => $address->getRegion() ? $address->getRegionId() : null,
54  'postcode' => $address->getPostcode(),
55  ]
56  );
57  }
58  }
59 
66  public function setDefaultAddressAfterLogIn(array $addresses)
67  {
68  $defaultShippingFound = false;
69  $defaultBillingFound = false;
70  foreach ($addresses as $address) {
71  if ($address->isDefaultBilling()) {
72  $defaultBillingFound = true;
73  $this->customerSession->setDefaultTaxBillingAddress(
74  [
75  'country_id' => $address->getCountryId(),
76  'region_id' => $address->getRegion() ? $address->getRegionId() : null,
77  'postcode' => $address->getPostcode(),
78  ]
79  );
80  }
81  if ($address->isDefaultShipping()) {
82  $defaultShippingFound = true;
83  $this->customerSession->setDefaultTaxShippingAddress(
84  [
85  'country_id' => $address->getCountryId(),
86  'region_id' => $address->getRegion() ? $address->getRegionId() : null,
87  'postcode' => $address->getPostcode(),
88  ]
89  );
90  }
91  if ($defaultShippingFound && $defaultBillingFound) {
92  break;
93  }
94  }
95  }
96 
103  private function isDefaultBilling(Address $address)
104  {
105  return $address->getId() && $address->getId() == $address->getCustomer()->getDefaultBilling()
106  || $address->getIsPrimaryBilling()
107  || $address->getIsDefaultBilling();
108  }
109 
116  private function isDefaultShipping(Address $address)
117  {
118  return $address->getId() && $address->getId() == $address->getCustomer()->getDefaultShipping()
119  || $address->getIsPrimaryShipping()
120  || $address->getIsDefaultShipping();
121  }
122 }
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38
__construct(Session $customerSession)