Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
TaxAddressManager Class Reference
Inheritance diagram for TaxAddressManager:
TaxAddressManagerInterface

Public Member Functions

 __construct (Session $customerSession)
 
 setDefaultAddressAfterSave (Address $address)
 
 setDefaultAddressAfterLogIn (array $addresses)
 

Detailed Description

Class to save address in customer session.

Definition at line 15 of file TaxAddressManager.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Session  $customerSession)
Parameters
Session$customerSession

Definition at line 27 of file TaxAddressManager.php.

28  {
29  $this->customerSession = $customerSession;
30  }

Member Function Documentation

◆ setDefaultAddressAfterLogIn()

setDefaultAddressAfterLogIn ( array  $addresses)

Set default Tax Shipping and Billing addresses into customer session after login.

Parameters

Implements TaxAddressManagerInterface.

Definition at line 66 of file TaxAddressManager.php.

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  }
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38

◆ setDefaultAddressAfterSave()

setDefaultAddressAfterSave ( Address  $address)

Set default Tax Billing and Shipping address into customer session after address save.

Parameters
Address$address
Returns
void

Implements TaxAddressManagerInterface.

Definition at line 38 of file TaxAddressManager.php.

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  }
$address
Definition: customer.php:38

The documentation for this class was generated from the following file: