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];
 }
 /**
  * Validates the fields in a specified address data object.
  *
  * @param \Magento\Quote\Api\Data\AddressInterface $addressData The address data object.
  * @return bool
  * @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer.
  * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer ID or address ID is not valid.
  */
 public function validate(\Magento\Quote\Api\Data\AddressInterface $addressData)
 {
     //validate customer id
     if ($addressData->getCustomerId()) {
         $customer = $this->customerRepository->getById($addressData->getCustomerId());
         if (!$customer->getId()) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid customer id %1', $addressData->getCustomerId()));
         }
     }
     // validate address id
     if ($addressData->getId()) {
         try {
             $address = $this->addressRepository->getById($addressData->getId());
         } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId()));
         }
         // check correspondence between customer id and address id
         if ($addressData->getCustomerId()) {
             if ($address->getCustomerId() != $addressData->getCustomerId()) {
                 throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId()));
             }
         }
     }
     if ($addressData->getCustomerAddressId()) {
         $applicableAddressIds = array_map(function ($address) {
             /** @var \Magento\Customer\Api\Data\AddressInterface $address */
             return $address->getId();
         }, $this->customerSession->getCustomerDataObject()->getAddresses());
         if (!in_array($addressData->getCustomerAddressId(), $applicableAddressIds)) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getCustomerAddressId()));
         }
     }
     return true;
 }
Example #3
0
 /**
  * @magentoConfigFixture current_store catalog/productalert/allow_price 1
  *
  * @magentoDataFixture Magento/ProductAlert/_files/product_alert.php
  */
 public function testProcess()
 {
     $this->_objectManager->configure(['Magento\\ProductAlert\\Model\\Observer' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'Magento\\ProductAlert\\Model\\Email' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock', 'Magento\\TestFramework\\Mail\\Template\\TransportBuilder' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]);
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     $observer = $this->_objectManager->get('Magento\\ProductAlert\\Model\\Observer');
     $observer->process();
     /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
     $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
     $this->assertStringMatchesFormat('%AHello %A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ',%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent());
 }
Example #4
0
 /**
  * Get user email
  *
  * @return string
  */
 public function getUserEmail()
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return '';
     }
     /**
      * @var CustomerInterface $customer
      */
     $customer = $this->_customerSession->getCustomerDataObject();
     return $customer->getEmail();
 }
Example #5
0
 /**
  * Retrieve welcome text
  *
  * @return string
  */
 public function getWelcome()
 {
     if (empty($this->_data['welcome'])) {
         if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
             $customerName = $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject());
             $this->_data['welcome'] = __('Welcome, %1!', $this->escapeHtml($customerName));
         } else {
             $this->_data['welcome'] = $this->_scopeConfig->getValue('design/header/welcome', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
         }
     }
     return $this->_data['welcome'];
 }
Example #6
0
 /**
  * Load data for customer quote and merge with current quote
  *
  * @return $this
  */
 public function loadCustomerQuote()
 {
     if (!$this->_customerSession->getCustomerId()) {
         return $this;
     }
     $this->_eventManager->dispatch('load_customer_quote_before', ['checkout_session' => $this]);
     try {
         $customerQuote = $this->quoteRepository->getForCustomer($this->_customerSession->getCustomerId());
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $customerQuote = $this->quoteFactory->create();
     }
     $customerQuote->setStoreId($this->_storeManager->getStore()->getId());
     if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
         if ($this->getQuoteId()) {
             $this->quoteRepository->save($customerQuote->merge($this->getQuote())->collectTotals());
         }
         $this->setQuoteId($customerQuote->getId());
         if ($this->_quote) {
             $this->quoteRepository->delete($this->_quote);
         }
         $this->_quote = $customerQuote;
     } else {
         $this->getQuote()->getBillingAddress();
         $this->getQuote()->getShippingAddress();
         $this->getQuote()->setCustomer($this->_customerSession->getCustomerDataObject())->setTotalsCollectedFlag(false)->collectTotals();
         $this->quoteRepository->save($this->getQuote());
     }
     return $this;
 }
 public function beforeSubscribe($subscriber, $email)
 {
     $storeId = $this->_storeManager->getStore()->getId();
     $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $email;
     if (!$isSubscribeOwnEmail) {
         if ($this->_helper->isMonkeyEnabled($storeId)) {
             $subscriber->setImportMode(true);
             $api = $this->_api;
             if ($this->_helper->isDoubleOptInEnabled($storeId)) {
                 $status = 'pending';
             } else {
                 $status = 'subscribed';
             }
             $data = ['list_id' => $this->_helper->getDefaultList(), 'email_address' => $email, 'email_type' => 'html', 'status' => $status, 'merge_fields' => ['EMAIL' => $email]];
             try {
                 $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
                 if (isset($return->id)) {
                     $subscriber->setMagemonkeyId($return->id);
                 }
             } catch (\Exception $e) {
                 $this->_helper->log($e->getMessage());
             }
         }
     }
     return [$email];
 }
Example #8
0
 /**
  * Retrieve current customer
  *
  * @return \Magento\Customer\Api\Data\CustomerInterface|null
  */
 public function getCustomer()
 {
     if (!$this->_currentCustomer && $this->_customerSession->isLoggedIn()) {
         $this->_currentCustomer = $this->_customerSession->getCustomerDataObject();
     }
     return $this->_currentCustomer;
 }
Example #9
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoAppArea frontend
  */
 public function testGetCustomer()
 {
     $expectedCustomer = $this->_customerSession->getCustomerDataObject();
     $actualCustomer = $this->_wishlistHelper->getCustomer();
     $this->assertInstanceOf('Magento\\Customer\\Api\\Data\\CustomerInterface', $actualCustomer);
     $this->assertEquals((int) $expectedCustomer->getId(), (int) $actualCustomer->getId());
     $this->assertEquals((int) $expectedCustomer->getWebsiteId(), (int) $actualCustomer->getWebsiteId());
     $this->assertEquals((int) $expectedCustomer->getStoreId(), (int) $actualCustomer->getStoreId());
     $this->assertEquals((int) $expectedCustomer->getGroupId(), (int) $actualCustomer->getGroupId());
     $this->assertEquals($expectedCustomer->getCustomAttributes(), $actualCustomer->getCustomAttributes());
     $this->assertEquals($expectedCustomer->getFirstname(), $actualCustomer->getFirstname());
     $this->assertEquals($expectedCustomer->getLastname(), $actualCustomer->getLastname());
     $this->assertEquals($expectedCustomer->getEmail(), $actualCustomer->getEmail());
     $this->assertEquals($expectedCustomer->getEmail(), $actualCustomer->getEmail());
     $this->assertEquals((int) $expectedCustomer->getDefaultBilling(), (int) $actualCustomer->getDefaultBilling());
     $this->assertEquals((int) $expectedCustomer->getDefaultShipping(), (int) $actualCustomer->getDefaultShipping());
 }
 public function afterSubscribeCustomerById($subscriber)
 {
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMonkeyEnabled($storeId)) {
         $customer = $this->_customer;
         $mergeVars = $this->_helper->getMergeVars($customer);
         $api = new \Ebizmarts\MageMonkey\Model\Api(array(), $this->_helper);
         $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
         if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) {
             $status = 'pending';
         } else {
             $status = 'subscribed';
         }
         $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $subscriber->getEmail(), 'email_type' => 'html', 'status' => $status);
         $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
         if (isset($return->id)) {
             $subscriber->setMagemonkeyId($return->id)->save();
         }
     }
 }
Example #11
0
 /**
  * @magentoDataFixture Magento/Wishlist/_files/wishlist.php
  */
 public function testSendAction()
 {
     $this->_objectManager->configure(['Magento\\Wishlist\\Controller\\Index\\Send' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock']]);
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     $request = ['form_key' => $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey')->getFormKey(), 'emails' => '*****@*****.**', 'message' => 'message', 'rss_url' => null];
     $this->getRequest()->setPost($request);
     $this->_objectManager->get('Magento\\Framework\\Registry')->register('wishlist', $this->_objectManager->get('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId(1));
     $this->dispatch('wishlist/index/send');
     /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
     $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
     $this->assertStringMatchesFormat('%AThank you, %A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . '%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent());
 }
Example #12
0
 /**
  * @magentoDataFixture Magento/Wishlist/_files/wishlist.php
  */
 public function testSendAction()
 {
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     $request = ['form_key' => $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey')->getFormKey(), 'emails' => '*****@*****.**', 'message' => 'message', 'rss_url' => null];
     $this->getRequest()->setPostValue($request);
     $this->_objectManager->get('Magento\\Framework\\Registry')->register('wishlist', $this->_objectManager->get('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId(1));
     $this->dispatch('wishlist/index/send');
     /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
     $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
     $actualResult = \Zend_Mime_Decode::decodeQuotedPrintable($transportBuilder->getSentMessage()->getBodyHtml()->getContent());
     $this->assertStringMatchesFormat('%A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ' wants to share this Wish List%A', $actualResult);
 }
Example #13
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_increments.php
  * @magentoAppArea frontend
  */
 public function testCustomerTitle()
 {
     $fixtureCustomerId = 1;
     $this->_customerSession->loginById($fixtureCustomerId);
     /** @var \Magento\Wishlist\Model\Wishlist $wishlist */
     $wishlist = $this->_objectManager->create('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId($fixtureCustomerId);
     /** @var \Magento\Framework\App\Helper\Context $contextHelper */
     $contextHelper = $this->_objectManager->create('Magento\\Framework\\App\\Helper\\Context');
     $wishlistHelper = $this->_objectManager->create('Magento\\Wishlist\\Helper\\Rss', ['context' => $contextHelper, 'customerSession' => $this->_customerSession]);
     /** @var \Magento\Catalog\Block\Product\Context $context */
     $contextBlock = $this->_objectManager->create('Magento\\Wishlist\\Block\\Context', ['request' => $contextHelper->getRequest(), 'wishlistHelper' => $wishlistHelper]);
     /** @var \Magento\Framework\App\Request\Http $request */
     $request = $contextHelper->getRequest();
     $request->setParam('wishlist_id', $wishlist->getId());
     $request->setParam('data', $this->_coreData->urlEncode($fixtureCustomerId));
     /** @var \Magento\Wishlist\Block\Rss $block */
     $block = $this->_objectManager->create('Magento\\Wishlist\\Block\\Rss', ['context' => $contextBlock]);
     /** @var \Magento\Framework\Escaper $escaper */
     $escaper = $this->_objectManager->create('Magento\\Framework\\Escaper');
     $expectedSting = '%A' . __("<title><![CDATA[%1 %2's Wishlist]]></title>", $escaper->escapeHtml($this->_customerSession->getCustomerDataObject()->getFirstname()), $escaper->escapeHtml($this->_customerSession->getCustomerDataObject()->getLastname())) . '%A';
     $this->assertStringMatchesFormat($expectedSting, $block->toHtml());
 }
Example #14
0
 public function beforeSubscribe($subscriber, $email)
 {
     $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
     if ($isSubscribeOwnEmail) {
         $subscriber->loadByEmail($email);
     }
     $storeId = $this->_storeManager->getStore()->getId();
     if ($this->_helper->isMageiaEnabled($storeId)) {
         $api = $this->_api;
         $data = ['emails' => json_encode([['email' => $email]])];
         $listId = $this->_helper->getDefaultList();
         $return = $api->listCreateMember($listId, $data);
         if (isset($return->result) && $return->result) {
             $subscriber->setMageiaId($email);
         }
     }
 }
Example #15
0
 /**
  * Initialize review form
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $data = $this->_reviewSession->getFormData(true);
     $data = new \Magento\Framework\Object((array) $data);
     // add logged in customer name as nickname
     if (!$data->getNickname()) {
         $customer = $this->_customerSession->getCustomerDataObject();
         if ($customer && $customer->getId()) {
             $data->setNickname($customer->getFirstname());
         }
     }
     $this->setAllowWriteReviewFlag($this->httpContext->getValue(Context::CONTEXT_AUTH) || $this->_reviewData->getIsGuestAllowToWrite());
     if (!$this->getAllowWriteReviewFlag()) {
         $queryParam = $this->urlEncoder->encode($this->getUrl('*/*/*', ['_current' => true]) . '#review-form');
         $this->setLoginLink($this->getUrl('customer/account/login/', [Url::REFERER_QUERY_PARAM_NAME => $queryParam]));
     }
     $this->setTemplate('form.phtml')->assign('data', $data);
 }
Example #16
0
 /**
  * Load data for customer quote and merge with current quote
  *
  * @return $this
  */
 public function loadCustomerQuote()
 {
     if (!$this->_customerSession->getCustomerId()) {
         return $this;
     }
     $this->_eventManager->dispatch('load_customer_quote_before', array('checkout_session' => $this));
     $customerQuote = $this->_quoteFactory->create()->setStoreId($this->_storeManager->getStore()->getId())->loadByCustomer($this->_customerSession->getCustomerId());
     if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
         if ($this->getQuoteId()) {
             $customerQuote->merge($this->getQuote())->collectTotals()->save();
         }
         $this->setQuoteId($customerQuote->getId());
         if ($this->_quote) {
             $this->_quote->delete();
         }
         $this->_quote = $customerQuote;
     } else {
         $this->getQuote()->getBillingAddress();
         $this->getQuote()->getShippingAddress();
         $this->getQuote()->setCustomerData($this->_customerSession->getCustomerDataObject())->setTotalsCollectedFlag(false)->collectTotals()->save();
     }
     return $this;
 }
Example #17
0
 /**
  * Share wishlist
  *
  * @return ResponseInterface|void
  * @throws NotFoundException
  */
 public function execute()
 {
     if (!$this->_formKeyValidator->validate($this->getRequest())) {
         return $this->_redirect('*/*/');
     }
     $wishlist = $this->wishlistProvider->getWishlist();
     if (!$wishlist) {
         throw new NotFoundException();
     }
     $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit();
     $textLimit = $this->_wishlistConfig->getSharingTextLimit();
     $emailsLeft = $sharingLimit - $wishlist->getShared();
     $emails = explode(',', $this->getRequest()->getPost('emails'));
     $error = false;
     $message = (string) $this->getRequest()->getPost('message');
     if (strlen($message) > $textLimit) {
         $error = __('Message length must not exceed %1 symbols', $textLimit);
     } else {
         $message = nl2br(htmlspecialchars($message));
         if (empty($emails)) {
             $error = __('Email address can\'t be empty.');
         } else {
             if (count($emails) > $emailsLeft) {
                 $error = __('This wishlist can be shared %1 more times.', $emailsLeft);
             } else {
                 foreach ($emails as $index => $email) {
                     $email = trim($email);
                     if (!\Zend_Validate::is($email, 'EmailAddress')) {
                         $error = __('Please input a valid email address.');
                         break;
                     }
                     $emails[$index] = $email;
                 }
             }
         }
     }
     if ($error) {
         $this->messageManager->addError($error);
         $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost());
         $this->_redirect('*/*/share');
         return;
     }
     $this->inlineTranslation->suspend();
     $sent = 0;
     try {
         $customer = $this->_customerSession->getCustomerDataObject();
         $customerName = $this->_customerHelperView->getCustomerName($customer);
         /*if share rss added rss feed to email template*/
         if ($this->getRequest()->getParam('rss_url')) {
             $rss_url = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Rss')->setWishlistId($wishlist->getId())->toHtml();
             $message .= $rss_url;
         }
         $wishlistBlock = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Items')->toHtml();
         $emails = array_unique($emails);
         $sharingCode = $wishlist->getSharingCode();
         try {
             $scopeConfig = $this->_objectManager->get('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
             $storeManager = $this->_objectManager->get('Magento\\Framework\\StoreManagerInterface');
             foreach ($emails as $email) {
                 $transport = $this->_transportBuilder->setTemplateIdentifier($scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeManager->getStore()->getStoreId()))->setTemplateVars(array('customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $wishlistBlock, 'addAllLink' => $this->_url->getUrl('*/shared/allcart', array('code' => $sharingCode)), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', array('code' => $sharingCode)), 'message' => $message, 'store' => $storeManager->getStore()))->setFrom($scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport();
                 $transport->sendMessage();
                 $sent++;
             }
         } catch (\Exception $e) {
             $wishlist->setShared($wishlist->getShared() + $sent);
             $wishlist->save();
             throw $e;
         }
         $wishlist->setShared($wishlist->getShared() + $sent);
         $wishlist->save();
         $this->inlineTranslation->resume();
         $this->_eventManager->dispatch('wishlist_share', array('wishlist' => $wishlist));
         $this->messageManager->addSuccess(__('Your wish list has been shared.'));
         $this->_redirect('*/*', array('wishlist_id' => $wishlist->getId()));
     } catch (\Exception $e) {
         $this->inlineTranslation->resume();
         $this->messageManager->addError($e->getMessage());
         $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost());
         $this->_redirect('*/*/share');
     }
 }
Example #18
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoAppArea frontend
  */
 public function testGetCustomer()
 {
     $this->assertEquals($this->_customerSession->getCustomerDataObject(), $this->_wishlistHelper->getCustomer());
 }
Example #19
0
 /**
  * Subscribes by email
  *
  * @param string $email
  * @throws \Exception
  * @return int
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function subscribe($email)
 {
     $this->loadByEmail($email);
     if (!$this->getId()) {
         $this->setSubscriberConfirmCode($this->randomSequence());
     }
     $isConfirmNeed = $this->_scopeConfig->getValue(self::XML_PATH_CONFIRMATION_FLAG, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) == 1 ? true : false;
     $isOwnSubscribes = false;
     $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $email;
     if (!$this->getId() || $this->getStatus() == self::STATUS_UNSUBSCRIBED || $this->getStatus() == self::STATUS_NOT_ACTIVE) {
         if ($isConfirmNeed === true) {
             // if user subscribes own login email - confirmation is not needed
             $isOwnSubscribes = $isSubscribeOwnEmail;
             if ($isOwnSubscribes == true) {
                 $this->setStatus(self::STATUS_SUBSCRIBED);
             } else {
                 $this->setStatus(self::STATUS_NOT_ACTIVE);
             }
         } else {
             $this->setStatus(self::STATUS_SUBSCRIBED);
         }
         $this->setSubscriberEmail($email);
     }
     if ($isSubscribeOwnEmail) {
         try {
             $customer = $this->customerRepository->getById($this->_customerSession->getCustomerId());
             $this->setStoreId($customer->getStoreId());
             $this->setCustomerId($customer->getId());
         } catch (NoSuchEntityException $e) {
             $this->setStoreId($this->_storeManager->getStore()->getId());
             $this->setCustomerId(0);
         }
     } else {
         $this->setStoreId($this->_storeManager->getStore()->getId());
         $this->setCustomerId(0);
     }
     $this->setStatusChanged(true);
     try {
         if ($isConfirmNeed === true && $isOwnSubscribes === false) {
             $this->sendConfirmationRequestEmail();
         } else {
             $this->sendConfirmationSuccessEmail();
         }
         $this->save();
         return $this->getStatus();
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage());
     }
 }
Example #20
0
 /**
  * Share wishlist
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @throws NotFoundException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     if (!$this->_formKeyValidator->validate($this->getRequest())) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     $wishlist = $this->wishlistProvider->getWishlist();
     if (!$wishlist) {
         throw new NotFoundException(__('Page not found.'));
     }
     $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit();
     $textLimit = $this->_wishlistConfig->getSharingTextLimit();
     $emailsLeft = $sharingLimit - $wishlist->getShared();
     $emails = $this->getRequest()->getPost('emails');
     $emails = empty($emails) ? $emails : explode(',', $emails);
     $error = false;
     $message = (string) $this->getRequest()->getPost('message');
     if (strlen($message) > $textLimit) {
         $error = __('Message length must not exceed %1 symbols', $textLimit);
     } else {
         $message = nl2br(htmlspecialchars($message));
         if (empty($emails)) {
             $error = __('Please enter an email address.');
         } else {
             if (count($emails) > $emailsLeft) {
                 $error = __('This wish list can be shared %1 more times.', $emailsLeft);
             } else {
                 foreach ($emails as $index => $email) {
                     $email = trim($email);
                     if (!\Zend_Validate::is($email, 'EmailAddress')) {
                         $error = __('Please input a valid email address.');
                         break;
                     }
                     $emails[$index] = $email;
                 }
             }
         }
     }
     if ($error) {
         $this->messageManager->addError($error);
         $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue());
         $resultRedirect->setPath('*/*/share');
         return $resultRedirect;
     }
     /** @var \Magento\Framework\View\Result\Layout $resultLayout */
     $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
     $this->addLayoutHandles($resultLayout);
     $this->inlineTranslation->suspend();
     $sent = 0;
     try {
         $customer = $this->_customerSession->getCustomerDataObject();
         $customerName = $this->_customerHelperView->getCustomerName($customer);
         $message .= $this->getRssLink($wishlist->getId(), $resultLayout);
         $emails = array_unique($emails);
         $sharingCode = $wishlist->getSharingCode();
         try {
             foreach ($emails as $email) {
                 $transport = $this->_transportBuilder->setTemplateIdentifier($this->scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->storeManager->getStore()->getStoreId()])->setTemplateVars(['customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $this->getWishlistItems($resultLayout), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', ['code' => $sharingCode]), 'message' => $message, 'store' => $this->storeManager->getStore()])->setFrom($this->scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport();
                 $transport->sendMessage();
                 $sent++;
             }
         } catch (\Exception $e) {
             $wishlist->setShared($wishlist->getShared() + $sent);
             $wishlist->save();
             throw $e;
         }
         $wishlist->setShared($wishlist->getShared() + $sent);
         $wishlist->save();
         $this->inlineTranslation->resume();
         $this->_eventManager->dispatch('wishlist_share', ['wishlist' => $wishlist]);
         $this->messageManager->addSuccess(__('Your wish list has been shared.'));
         $resultRedirect->setPath('*/*', ['wishlist_id' => $wishlist->getId()]);
         return $resultRedirect;
     } catch (\Exception $e) {
         $this->inlineTranslation->resume();
         $this->messageManager->addError($e->getMessage());
         $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue());
         $resultRedirect->setPath('*/*/share');
         return $resultRedirect;
     }
 }
Example #21
0
 /**
  * Gets response from braintree api using the nonce
  *
  * @param string|null $nonce
  * @param array|null $options
  * @param array|null $billingAddress
  * @return $this
  * @throws LocalizedException
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function processNonce($nonce = null, $options = null, $billingAddress = null)
 {
     $customerId = $this->customerSession->getCustomerId();
     if (!$customerId) {
         throw new LocalizedException(__('Invalid Customer ID provided'));
     }
     $billingCountry = null;
     if (is_array($billingAddress)) {
         $collection = $this->countryFactory->create()->addCountryCodeFilter($billingAddress['countryCodeAlpha2']);
         if ($collection->getSize()) {
             $billingCountry = $collection->getFirstItem()->getId();
         }
         if (!$this->config->canUseForCountry($billingCountry)) {
             throw new LocalizedException(__('Selected payment type is not allowed for billing country.'));
         }
     }
     $ccType = null;
     if ($options) {
         $ccType = $options['ccType'];
     }
     if ($ccType) {
         $error = $this->config->canUseCcTypeForCountry($billingCountry, $ccType);
         if ($error) {
             throw new LocalizedException($error);
         }
     }
     $customer = $this->customerFactory->create()->load($customerId);
     $customerId = $this->braintreeHelper->generateCustomerId($customerId, $customer->getEmail());
     if (!$this->exists($customerId)) {
         $customerRequest = ['id' => $customerId, 'firstName' => $billingAddress['firstName'], 'lastName' => $billingAddress['lastName'], 'email' => $this->customerSession->getCustomerDataObject()->getEmail()];
         if (strlen($billingAddress['company'])) {
             $customerRequest['company'] = $billingAddress['company'];
         }
         $result = $this->braintreeCustomer->create($customerRequest);
         if (!$result->success) {
             throw new LocalizedException($this->errorHelper->parseBraintreeError($result));
         }
     }
     //check if customerId is created on braintree
     $requestArray = ['customerId' => $customerId, 'paymentMethodNonce' => $nonce, 'options' => ['makeDefault' => $options['default'] == 'true' ? true : false, 'failOnDuplicatePaymentMethod' => $this->config->allowDuplicateCards() == '1' ? false : true, 'verifyCard' => $this->config->useCvv() == '1' ? true : false]];
     if ($this->config->isFraudDetectionEnabled() && strlen($options['device_data']) > 0) {
         $requestArray['deviceData'] = $options['device_data'];
     }
     if ($options['update'] == 'true') {
         $token = $options['token'];
         unset($requestArray['customerId']);
         unset($requestArray['options']['failOnDuplicatePaymentMethod']);
         $requestArray['billingAddress'] = $billingAddress;
         $result = $this->braintreePaymentMethod->update($token, $requestArray);
         $this->debug($requestArray);
         $this->debug($result);
     } else {
         $result = $this->braintreePaymentMethod->create($requestArray);
         $this->debug($requestArray);
         $this->debug($result);
     }
     if (!$result->success) {
         throw new LocalizedException($this->errorHelper->parseBraintreeError($result));
     }
     return $this;
 }
Example #22
0
 /**
  * @return string
  */
 public function getEmail()
 {
     return (string) $this->_customerSession->getCustomerDataObject()->getEmail();
 }
 /**
  * Retrieve customer object
  *
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 public function getCustomer()
 {
     return $this->_customerSession->getCustomerDataObject();
 }
Example #24
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Wishlist/_files/wishlist.php
  */
 public function testGetWishlistCustomer()
 {
     $this->_customerSession->loginById(1);
     $this->assertEquals($this->_customerSession->getCustomerDataObject(), $this->_block->getWishlistCustomer());
 }