Example #1
0
 public function beforeSubscribeCustomerById($subscriber, $customerId)
 {
     $subscriber->loadByCustomerId($customerId);
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMonkeyEnabled($storeId)) {
         $customer = $this->_customer->load($customerId);
         $mergeVars = $this->_helper->getMergeVars($customer);
         $api = $this->_api;
         $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
         if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) {
             $status = 'pending';
         } else {
             $status = 'subscribed';
         }
         if ($mergeVars) {
             $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => $mergeVars);
         } else {
             $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status);
         }
         $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
         if (isset($return->id)) {
             $subscriber->setMagemonkeyId($return->id);
         }
     }
     return [$customerId];
 }
Example #2
0
 /**
  * Confirm customer account by id and confirmation key
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     if ($this->session->isLoggedIn()) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     try {
         $customerId = $this->getRequest()->getParam('id', false);
         $key = $this->getRequest()->getParam('key', false);
         if (empty($customerId) || empty($key)) {
             throw new \Exception(__('Bad request.'));
         }
         // log in and send greeting email
         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
         $customer = $this->customerAccountManagement->activate($customerEmail, $key);
         $this->session->setCustomerDataAsLoggedIn($customer);
         $this->messageManager->addSuccess($this->getSuccessMessage());
         $resultRedirect->setUrl($this->getSuccessRedirect());
         return $resultRedirect;
     } catch (StateException $e) {
         $this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('There was an error confirming the account'));
     }
     $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
     return $resultRedirect->setUrl($this->_redirect->error($url));
 }
Example #3
0
 /**
  * Login post action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     if ($this->session->isLoggedIn() || !$this->formKeyValidator->validate($this->getRequest())) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     if ($this->getRequest()->isPost()) {
         $login = $this->getRequest()->getPost('login');
         if (!empty($login['username']) && !empty($login['password'])) {
             try {
                 $customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
                 $this->session->setCustomerDataAsLoggedIn($customer);
                 $this->session->regenerateId();
             } catch (EmailNotConfirmedException $e) {
                 $value = $this->customerUrl->getEmailConfirmationUrl($login['username']);
                 $message = __('This account is not confirmed.' . ' <a href="%1">Click here</a> to resend confirmation email.', $value);
                 $this->messageManager->addError($message);
                 $this->session->setUsername($login['username']);
             } catch (AuthenticationException $e) {
                 $message = __('Invalid login or password.');
                 $this->messageManager->addError($message);
                 $this->session->setUsername($login['username']);
             } catch (\Exception $e) {
                 $this->messageManager->addError(__('Invalid login or password.'));
             }
         } else {
             $this->messageManager->addError(__('A login and a password are required.'));
         }
     }
     return $this->accountRedirect->getRedirect();
 }
Example #4
0
 /**
  * Clear wishlist helper property
  */
 protected function tearDown()
 {
     $this->_wishlistHelper = null;
     if ($this->_customerSession->isLoggedIn()) {
         $this->_customerSession->logout();
     }
 }
 /**
  * Send confirmation link to specified email
  *
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     if ($this->session->isLoggedIn()) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     // try to confirm by email
     $email = $this->getRequest()->getPost('email');
     if ($email) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         try {
             $this->customerAccountManagement->resendConfirmation($email, $this->storeManager->getStore()->getWebsiteId());
             $this->messageManager->addSuccess(__('Please check your email for confirmation key.'));
         } catch (InvalidTransitionException $e) {
             $this->messageManager->addSuccess(__('This email does not require confirmation.'));
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('Wrong email.'));
             $resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]);
             return $resultRedirect;
         }
         $this->session->setUsername($email);
         $resultRedirect->setPath('*/*/index', ['_secure' => true]);
         return $resultRedirect;
     }
     /** @var \Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->getLayout()->getBlock('accountConfirmation')->setEmail($this->getRequest()->getParam('email', $email));
     return $resultPage;
 }
 /**
  * Set configuration for AdyenHPP payemnt method
  *
  * @return array
  */
 public function getConfig()
 {
     // set to active
     $config = ['payment' => [self::CODE => ['isActive' => true, 'redirectUrl' => $this->_urlBuilder->getUrl('adyen/process/redirect', ['_secure' => $this->_getRequest()->isSecure()])]]];
     // get customer
     if ($this->_customerSession->isLoggedIn()) {
         $gender = \Adyen\Payment\Model\Gender::getAdyenGenderFromMagentoGender($this->_customerSession->getCustomerData()->getGender());
         // format to calendar date
         $dob = $this->_customerSession->getCustomerData()->getDob();
         $dob = strtotime($dob);
         $dob = date('m/d/Y', $dob);
     } else {
         $gender = "";
         $dob = "";
     }
     // add to config
     $config['payment']['adyenHpp']['gender'] = $gender;
     $config['payment']['adyenHpp']['dob'] = $dob;
     // gender types
     $config['payment']['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes();
     $paymentMethodSelectionOnAdyen = $this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
     $config['payment']['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen;
     $config['payment']['adyenHpp']['showGender'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_gender');
     $config['payment']['adyenHpp']['showDob'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_dob');
     $config['payment']['adyenHpp']['showTelephone'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_telephone');
     return $config;
 }
 /**
  * {@inheritdoc}
  */
 public function toHtml()
 {
     if ($this->customerSession->isLoggedIn() || !$this->registration->isAllowed() || !$this->accountManagement->isEmailAvailable($this->getEmailAddress()) || !$this->validateAddresses()) {
         return '';
     }
     return parent::toHtml();
 }
 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         /** @var  \Magento\Customer\Api\Data\CustomerInterface $customer */
         $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         if ($defaultShipping = $customer->getDefaultShipping()) {
             /** @var  \Magento\Customer\Model\Data\Address $address */
             $address = $this->addressRepository->getById($defaultShipping);
             if ($address) {
                 $this->_customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
             }
         }
         if ($defaultBilling = $customer->getDefaultBilling()) {
             $address = $this->addressRepository->getById($defaultBilling);
             if ($address) {
                 $this->_customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
             }
         }
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
Example #9
0
 /**
  * Reset quote reward point amount
  *
  * @param \Magento\Customer\CustomerData\Customer $subject
  * @param \Closure $proceed
  *
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetSectionData(\Magento\Customer\CustomerData\Customer $subject, \Closure $proceed)
 {
     /** unset customer first name  */
     if (!$this->customerSession->isLoggedIn() && $this->persistentData->isEnabled() && $this->persistentSession->isPersistent()) {
         return [];
     }
     return $proceed();
 }
 /**
  * @param \Magento\Checkout\Model\DefaultConfigProvider $subject
  * @param array $result
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result)
 {
     if ($this->persistentHelper->isEnabled() && $this->persistentSession->isPersistent() && !$this->customerSession->isLoggedIn()) {
         /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
         $quoteIdMask = $this->quoteIdMaskFactory->create();
         $result['quoteData']['entity_id'] = $quoteIdMask->load($this->checkoutSession->getQuote()->getId(), 'quote_id')->getMaskedId();
     }
     return $result;
 }
 /**
  * Set quote to be loaded even if not active
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && !$this->_persistentData->isShoppingCartPersist())) {
         return;
     }
     if ($this->_checkoutSession) {
         $this->_checkoutSession->setLoadInactive();
     }
 }
 /**
  * Make persistent quote to be guest
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     /** @var $action \Magento\Persistent\Controller\Index */
     $action = $observer->getEvent()->getControllerAction();
     if ($action instanceof \Magento\Persistent\Controller\Index) {
         if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() || $this->_persistentData->isShoppingCartPersist()) {
             $this->quoteManager->setGuest(true);
         }
     }
 }
 /**
  * @param $productId
  * @return bool|void
  */
 public function processViews($productId)
 {
     if (!$this->_config->isEnabled()) {
         return false;
     }
     if ($this->_customerSession->isLoggedIn()) {
         return $this->_eventClient->saveCustomerViewProduct($this->_customerSession->getCustomerId(), $productId);
     }
     return false;
 }
 /**
  * Apply persistent data
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute($observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent() || $this->_customerSession->isLoggedIn()) {
         return $this;
     }
     /** @var \Magento\Persistent\Model\Persistent\Config $persistentConfig */
     $persistentConfig = $this->_persistentConfigFactory->create();
     $persistentConfig->setConfigFilePath($this->_persistentData->getPersistentConfigFilePath())->fire();
     return $this;
 }
 /**
  * Prevent clear checkout session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var $action \Magento\Persistent\Controller\Index */
     $action = $observer->getEvent()->getControllerAction();
     if ($action instanceof \Magento\Persistent\Controller\Index) {
         if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() || !$this->_persistentData->isShoppingCartPersist()) {
             $action->setClearCheckoutSession(false);
         }
     }
 }
Example #16
0
 public function dispatch(RequestInterface $request)
 {
     if (!$this->session->isLoggedIn()) {
         return $this->_redirect('customer/account/login');
     }
     if (!$this->config->isEnabled()) {
         return $this->_redirect($this->_redirect->getRefererUrl());
     }
     return parent::dispatch($request);
 }
Example #17
0
 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute($observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         $customer = $this->_customerAccountService->getCustomer($this->_persistentSession->getSession()->getCustomerId());
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
Example #18
0
 /**
  * Get user email
  *
  * @return string
  */
 public function getUserEmail()
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return '';
     }
     /**
      * @var CustomerInterface $customer
      */
     $customer = $this->_customerSession->getCustomerDataObject();
     return $customer->getEmail();
 }
 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
 /**
  * Check and clear session data if persistent session expired
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer)) {
         return;
     }
     if ($this->_persistentData->isEnabled() && !$this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && $this->_checkoutSession->getQuoteId() && !$observer->getControllerAction() instanceof \Magento\Checkout\Controller\Onepage) {
         $this->_eventManager->dispatch('persistent_session_expired');
         $this->quoteManager->expire();
         $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null);
     }
 }
 /**
  * Unset persistent cookie and make customer's quote as a guest
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent()) {
         return;
     }
     $this->_persistentSession->getSession()->removePersistentCookie();
     if (!$this->_customerSession->isLoggedIn()) {
         $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null);
     }
     $this->quoteManager->setGuest();
 }
 /**
  * Renew persistent cookie
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isEnabled() || !$this->_persistentSession->isPersistent()) {
         return;
     }
     /** @var $request \Magento\Framework\App\RequestInterface */
     $request = $observer->getEvent()->getRequest();
     if ($this->_customerSession->isLoggedIn() || $request->getFullActionName() == 'customer_account_logout') {
         $this->_sessionFactory->create()->renewPersistentCookie($this->_persistentData->getLifeTime(), $this->_customerSession->getCookiePath());
     }
 }
Example #23
0
 /**
  * @param \Magento\Sales\Model\Order $order
  * @return bool
  */
 public function canReorder(\Magento\Sales\Model\Order $order)
 {
     if (!$this->isAllowed($order->getStore())) {
         return false;
     }
     if ($this->_customerSession->isLoggedIn()) {
         return $order->canReorder();
     } else {
         return true;
     }
 }
 /**
  * Check the customer has an account and send the order product colllection
  * to PredictionIO
  *
  * @param Observer $observer
  */
 public function execute(Observer $observer)
 {
     if (!$this->_config->isEnabled()) {
         return;
     }
     $order = $observer->getEvent()->getOrder();
     $productCollection = $order->getItems();
     if ($this->_customerSession->isLoggedIn()) {
         $this->_sendPurchaseEvent($productCollection);
         return;
     }
 }
 /**
  * Adds New Relic custom parameters per request for store, website, and logged in user if applicable
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->newRelicWrapper->addCustomParameter(Config::STORE, $this->storeManager->getStore()->getName());
         $this->newRelicWrapper->addCustomParameter(Config::WEBSITE, $this->storeManager->getWebsite()->getName());
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_ID, $customer->getId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_NAME, $customer->getFirstname() . ' ' . $customer->getLastname());
         }
     }
 }
Example #26
0
 /**
  * Customer register form page
  *
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function executeInternal()
 {
     if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/*');
         return $resultRedirect;
     }
     /** @var \Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     return $resultPage;
 }
 /**
  * Add Product to Compare Products List action
  *
  * Reset count of compared products cache
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $productId = $observer->getEvent()->getProduct()->getId();
     $viewData = ['product_id' => $productId];
     if ($this->_customerSession->isLoggedIn()) {
         $viewData['customer_id'] = $this->_customerSession->getCustomerId();
     } else {
         $viewData['visitor_id'] = $this->_customerVisitor->getId();
     }
     $this->_productCompFactory->create()->setData($viewData)->save()->calculate();
     $this->eventSaver->save(\Magento\Reports\Model\Event::EVENT_PRODUCT_COMPARE, $productId);
 }
Example #28
0
 /**
  * Check is it possible to reorder
  *
  * @param int $orderId
  * @return bool
  */
 public function canReorder($orderId)
 {
     $order = $this->orderRepository->get($orderId);
     if (!$this->isAllowed($order->getStore())) {
         return false;
     }
     if ($this->customerSession->isLoggedIn()) {
         return $order->canReorder();
     } else {
         return true;
     }
 }
 /**
  * Customer login action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return $this;
     }
     $visitorId = $this->_customerVisitor->getId();
     $customerId = $this->_customerSession->getCustomerId();
     $eventModel = $this->_eventFactory->create();
     $eventModel->updateCustomerType($visitorId, $customerId);
     $this->_productCompFactory->create()->updateCustomerFromVisitor()->calculate();
     $this->_productIndexFactory->create()->updateCustomerFromVisitor()->calculate();
     return $this;
 }
Example #30
0
 /**
  * Customer login form page
  *
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     if ($this->session->isLoggedIn()) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     /** @var \Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->setHeader('Login-Required', 'true');
     return $resultPage;
 }