session = $session; $this->checkoutSession = $checkoutSession; $this->eventManager = $eventManager; } /** * Login customer by data * * @param CustomerInterface $customerData */ public function login(CustomerInterface $customerData) { $this->dispatchAuthenticationEvent(); if ($customerData->getId() != $this->session->getId() || !$this->session->isLoggedIn()) { $this->session->setCustomerDataAsLoggedIn($customerData); $this->session->regenerateId(); $this->checkoutSession->loadCustomerQuote(); } } /** * Login customer by id * * @param integer $customerId */ public function loginById($customerId) { $this->dispatchAuthenticationEvent(); $this->session->loginById($customerId); $this->session->regenerateId(); } /** * For compatibility with customer_customer_authenticated event dispatched from standard login controller. * The observers are also attached to this with the exception of password related ones. */ protected function dispatchAuthenticationEvent() { $this->eventManager->dispatch('amazon_customer_authenticated'); } /** * Set validation credentials in session * * @param ValidationCredentials $credentials */ public function setValidationCredentials(ValidationCredentials $credentials) { $this->session->setAmazonValidationCredentials($credentials); } /** * Get validation credentials from session * * @return ValidationCredentials|null */ public function getValidationCredentials() { $credentials = $this->session->getAmazonValidationCredentials(); return ($credentials) ?: null; } /** * Check if Magento account is logged in * * @return bool */ public function isLoggedIn() { return $this->session->isLoggedIn(); } /** * Check if user is logged in to Amazon * * @return bool */ public function isAmazonLoggedIn() { return $this->session->getIsAmazonLoggedIn(); } /** * @return void */ public function setIsAmazonLoggedIn($isLoggedIn) { if ($isLoggedIn) { $this->session->setIsAmazonLoggedIn(true); } else { $this->session->unsIsAmazonLoggedIn(); } } /** * @param AmazonCustomerInterface $amazonCustomer * @return void */ public function setAmazonCustomer(AmazonCustomerInterface $amazonCustomer) { $this->session->setAmazonCustomer($amazonCustomer); } /** * @return void */ public function clearAmazonCustomer() { $this->session->unsAmazonCustomer(); } /** * @return AmazonCustomerInterface|null */ public function getAmazonCustomer() { $amazonCustomer = $this->session->getAmazonCustomer(); if ($amazonCustomer && (!$amazonCustomer instanceof AmazonCustomerInterface)) { $this->clearAmazonCustomer(); $amazonCustomer = null; } return $amazonCustomer; } }