Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerLoggedInObserver.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Tax\Observer;
7 
16 
18 {
22  protected $customerSession;
23 
27  protected $taxHelper;
28 
34  private $moduleManager;
35 
41  private $cacheConfig;
42 
46  private $groupRepository;
47 
53  private $addressManager;
54 
63  public function __construct(
64  GroupRepositoryInterface $groupRepository,
67  Manager $moduleManager,
68  Config $cacheConfig,
69  TaxAddressManagerInterface $addressManager
70  ) {
71  $this->groupRepository = $groupRepository;
72  $this->customerSession = $customerSession;
73  $this->taxHelper = $taxHelper;
74  $this->moduleManager = $moduleManager;
75  $this->cacheConfig = $cacheConfig;
76  $this->addressManager = $addressManager;
77  }
78 
84  public function execute(Observer $observer)
85  {
86  if ($this->moduleManager->isEnabled('Magento_PageCache')
87  && $this->cacheConfig->isEnabled()
88  && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()
89  ) {
91  $customer = $observer->getData('customer');
92  $customerGroupId = $customer->getGroupId();
93  $customerGroup = $this->groupRepository->getById($customerGroupId);
94  $customerTaxClassId = $customerGroup->getTaxClassId();
95  $this->customerSession->setCustomerTaxClassId($customerTaxClassId);
96 
97  $addresses = $customer->getAddresses();
98  if (isset($addresses)) {
99  $this->addressManager->setDefaultAddressAfterLogIn($addresses);
100  }
101  }
102  }
103 }
$groupRepository
$customer
Definition: customers.php:11
$addresses
Definition: address_list.php:7
$moduleManager
Definition: products.php:75
__construct(GroupRepositoryInterface $groupRepository, Session $customerSession, Data $taxHelper, Manager $moduleManager, Config $cacheConfig, TaxAddressManagerInterface $addressManager)