/**
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_default 1
  * @magentoAppArea frontend
  * @magentoAppIsolation enabled
  */
 public function testEmulateWelcomeBlock()
 {
     $this->_customerSession->loginById(1);
     $httpContext = new \Magento\Framework\App\Http\Context();
     $httpContext->setValue(Context::CONTEXT_AUTH, 1, 1);
     $block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]);
     $this->_observer->emulateWelcomeBlock($block);
     $customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())));
     $translation = __('Welcome, %1!', $customerName);
     $this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
     $this->_customerSession->logout();
 }
Example #2
0
 /**
  * Emulate 'welcome' block with persistent data
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @return $this
  */
 public function emulateWelcomeBlock($block)
 {
     $escapedName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())), null);
     $this->_applyAccountLinksPersistentData();
     $welcomeMessage = __('Welcome, %1!', $escapedName) . ' ' . $this->_layout->getBlock('header.additional')->toHtml();
     $block->setWelcome($welcomeMessage);
     return $this;
 }
Example #3
0
 /**
  * @param \Magento\Customer\Api\Data\CustomerInterface $customerData
  * @param string $expectedCustomerName
  * @param bool $isPrefixAllowed
  * @param bool $isMiddleNameAllowed
  * @param bool $isSuffixAllowed
  * @dataProvider getCustomerNameDataProvider
  */
 public function testGetCustomerName($customerData, $expectedCustomerName, $isPrefixAllowed = false, $isMiddleNameAllowed = false, $isSuffixAllowed = false)
 {
     $visibleAttribute = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface');
     $visibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(true));
     $invisibleAttribute = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface');
     $invisibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(false));
     $this->_customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValueMap([['prefix', $isPrefixAllowed ? $visibleAttribute : $invisibleAttribute], ['middlename', $isMiddleNameAllowed ? $visibleAttribute : $invisibleAttribute], ['suffix', $isSuffixAllowed ? $visibleAttribute : $invisibleAttribute]]));
     $this->assertEquals($expectedCustomerName, $this->_helper->getCustomerName($customerData), 'Full customer name is invalid');
 }
Example #4
0
 /**
  * Return the full name of the customer currently logged in
  *
  * @return string|null
  */
 public function getCustomerName()
 {
     try {
         $customer = $this->customerRepository->getById($this->currentCustomer->getCustomerId());
         return $this->escapeHtml($this->_viewHelper->getCustomerName($customer));
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
 }
Example #5
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 #6
0
 /**
  * @dataProvider getCustomerServiceDataProvider
  */
 public function testGetCustomerName($prefix, $firstName, $middleName, $lastName, $suffix, $result)
 {
     $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $customerData->expects($this->any())->method('getPrefix')->will($this->returnValue($prefix));
     $customerData->expects($this->any())->method('getFirstname')->will($this->returnValue($firstName));
     $customerData->expects($this->any())->method('getMiddlename')->will($this->returnValue($middleName));
     $customerData->expects($this->any())->method('getLastname')->will($this->returnValue($lastName));
     $customerData->expects($this->any())->method('getSuffix')->will($this->returnValue($suffix));
     $this->assertEquals($result, $this->object->getCustomerName($customerData));
 }
Example #7
0
 /**
  * Get user name
  *
  * @return string
  */
 public function getUserName()
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return '';
     }
     /**
      * @var \Magento\Customer\Api\Data\CustomerInterface $customer
      */
     $customer = $this->_customerSession->getCustomerDataObject();
     return trim($this->_customerViewHelper->getCustomerName($customer));
 }
Example #8
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 #9
0
 /**
  * Retrieve username for form field
  *
  * @return string
  */
 public function getUserName()
 {
     $name = $this->getFormData()->getData('sender/name');
     if (!empty($name)) {
         return trim($name);
     }
     /* @var $session \Magento\Customer\Model\Session */
     $session = $this->_customerSession;
     if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
         return $this->_customerViewHelper->getCustomerName($session->getCustomerDataObject());
     }
     return '';
 }
Example #10
0
 /**
  * Load search results
  *
  * @return $this
  */
 public function load()
 {
     $result = [];
     if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
         $this->setResults($result);
         return $this;
     }
     $this->searchCriteriaBuilder->setCurrentPage($this->getStart());
     $this->searchCriteriaBuilder->setPageSize($this->getLimit());
     $searchFields = ['firstname', 'lastname', 'company'];
     $filters = [];
     foreach ($searchFields as $field) {
         $filters[] = $this->filterBuilder->setField($field)->setConditionType('like')->setValue($this->getQuery() . '%')->create();
     }
     $this->searchCriteriaBuilder->addFilters($filters);
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchResults = $this->customerRepository->getList($searchCriteria);
     foreach ($searchResults->getItems() as $customer) {
         $customerAddresses = $customer->getAddresses();
         /** Look for a company name defined in default billing address */
         $company = null;
         foreach ($customerAddresses as $customerAddress) {
             if ($customerAddress->getId() == $customer->getDefaultBilling()) {
                 $company = $customerAddress->getCompany();
                 break;
             }
         }
         $result[] = ['id' => 'customer/1/' . $customer->getId(), 'type' => __('Customer'), 'name' => $this->_customerViewHelper->getCustomerName($customer), 'description' => $company, 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', ['id' => $customer->getId()])];
     }
     $this->setResults($result);
     return $this;
 }
 /**
  * Create an object with data merged from Customer and CustomerSecure
  *
  * @param CustomerInterface $customer
  * @return \Magento\Customer\Model\Data\CustomerSecure
  */
 private function getFullCustomerObject($customer)
 {
     // No need to flatten the custom attributes or nested objects since the only usage is for email templates and
     // object passed for events
     $mergedCustomerData = $this->customerRegistry->retrieveSecureData($customer->getId());
     $customerData = $this->dataProcessor->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class);
     $mergedCustomerData->addData($customerData);
     $mergedCustomerData->setData('name', $this->customerViewHelper->getCustomerName($customer));
     return $mergedCustomerData;
 }
Example #12
0
 /**
  * Retrieve the header text, either the name of an existing customer or 'New Customer'.
  *
  * @return \Magento\Framework\Phrase|string
  */
 public function getHeaderText()
 {
     $customerId = $this->getCustomerId();
     if ($customerId) {
         $customerData = $this->customerRepository->getById($customerId);
         return $this->escapeHtml($this->_viewHelper->getCustomerName($customerData));
     } else {
         return __('New Customer');
     }
 }
Example #13
0
 /**
  * Retrieve the header text, either the name of an existing customer or 'New Customer'.
  *
  * @return string
  */
 public function getHeaderText()
 {
     $customerId = $this->getCustomerId();
     if ($customerId) {
         $customerData = $this->_customerAccountService->getCustomer($customerId);
         return $this->escapeHtml($this->_viewHelper->getCustomerName($customerData));
     } else {
         return __('New Customer');
     }
 }
Example #14
0
 /**
  * Get user name
  *
  * @return string
  */
 public function getUserName()
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return '';
     }
     /**
      * @var Customer $customer
      */
     $customer = $this->_customerSession->getCustomerDataObject();
     return trim($this->_customerViewHelper->getCustomerName($customer));
 }
Example #15
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 #16
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testSend()
 {
     $this->_objectManager->configure(['Magento\\ProductAlert\\Model\\Email' => ['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);
     $this->_emailModel = $this->_objectManager->create('Magento\\ProductAlert\\Model\\Email');
     /** @var \Magento\Store\Model\Website $website */
     $website = $this->_objectManager->create('Magento\\Store\\Model\\Website');
     $website->load(1);
     $this->_emailModel->setWebsite($website);
     /** @var \Magento\Customer\Service\V1\Data\Customer $customer */
     $customer = $this->_customerAccountService->getCustomer(1);
     $this->_emailModel->setCustomerData($customer);
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
     $product->load(1);
     $this->_emailModel->addPriceProduct($product);
     $this->_emailModel->send();
     /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */
     $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock');
     $this->assertStringMatchesFormat('%AHello ' . $this->_customerViewHelper->getCustomerName($customer) . '%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent());
 }
Example #17
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 #18
0
 /**
  * Initialize add new review
  *
  * @return void
  */
 protected function _construct()
 {
     $this->_addButtonLabel = __('New Review');
     parent::_construct();
     $this->_blockGroup = 'Magento_Review';
     $this->_controller = 'adminhtml';
     // lookup customer, if id is specified
     $customerId = $this->getRequest()->getParam('customerId', false);
     $customerName = '';
     if ($customerId) {
         $customer = $this->customerRepository->getById($customerId);
         $customerName = $this->escapeHtml($this->_customerViewHelper->getCustomerName($customer));
     }
     $productId = $this->getRequest()->getParam('productId', false);
     $productName = null;
     if ($productId) {
         $product = $this->_productFactory->create()->load($productId);
         $productName = $this->escapeHtml($product->getName());
     }
     if ($this->_coreRegistry->registry('usePendingFilter') === true) {
         if ($customerName) {
             $this->_headerText = __('Pending Reviews of Customer `%1`', $customerName);
         } else {
             $this->_headerText = __('Pending Reviews');
         }
         $this->buttonList->remove('add');
     } else {
         if ($customerName) {
             $this->_headerText = __('All Reviews of Customer `%1`', $customerName);
         } elseif ($productName) {
             $this->_headerText = __('All Reviews of Product `%1`', $productName);
         } else {
             $this->_headerText = __('All Reviews');
         }
     }
 }
Example #19
0
 /**
  * Retrieve default value for giftmessage sender
  *
  * @return string
  */
 public function getDefaultSender()
 {
     if (!$this->getEntity()) {
         return '';
     }
     if ($this->_getSession()->hasCustomerId() && $this->_getSession()->getCustomerId()) {
         $customerData = $this->_customerService->getCustomer($this->_getSession()->getCustomerId());
         return $this->_customerViewHelper->getCustomerName($customerData);
     }
     $object = $this->getEntity();
     if ($this->getEntity()->getQuote()) {
         $object = $this->getEntity()->getQuote();
     }
     return $object->getBillingAddress()->getName();
 }
Example #20
0
 /**
  * Retrieve default value for giftmessage sender
  *
  * @return string
  */
 public function getDefaultSender()
 {
     if (!$this->getEntity()) {
         return '';
     }
     if ($this->_getSession()->hasCustomerId() && $this->_getSession()->getCustomerId()) {
         // TODO to change email on id
         $customer = $this->customerRepository->getById($this->_getSession()->getCustomerId());
         return $this->_customerViewHelper->getCustomerName($customer);
     }
     $object = $this->getEntity();
     if ($this->getEntity()->getQuote()) {
         $object = $this->getEntity()->getQuote();
     }
     return $object->getBillingAddress()->getName();
 }
Example #21
0
 /**
  * Loads customers info to collection
  *
  * @return void
  */
 protected function _addCustomersData()
 {
     if ($this->_loadCustomersDataFlag) {
         return;
     }
     $this->_loadCustomersDataFlag = true;
     foreach ($this->getItems() as $item) {
         if ($item->getCustomerId()) {
             $customerId = $item->getCustomerId();
             try {
                 $customer = $this->customerRepository->getById($customerId);
                 $problems = $this->getItemsByColumnValue('customer_id', $customerId);
                 $customerName = $this->_customerView->getCustomerName($customer);
                 foreach ($problems as $problem) {
                     $problem->setCustomerName($customerName)->setCustomerFirstName($customer->getFirstName())->setCustomerLastName($customer->getLastName());
                 }
             } catch (NoSuchEntityException $e) {
                 // do nothing if customer is not found by id
             }
         }
     }
 }
Example #22
0
 /**
  * Retrieve customer name
  *
  * @return string|void
  */
 public function getCustomerName()
 {
     return $this->getCustomer() ? $this->_customerViewHelper->getCustomerName($this->getCustomer()) : null;
 }
Example #23
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 #24
0
 /**
  * Render additional header html
  *
  * @return string
  */
 protected function _toHtml()
 {
     $persistentName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->_customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId())));
     return '<span><a ' . $this->getLinkAttributes() . ' >' . $this->escapeHtml(__('(Not %1?)', $persistentName)) . '</a></span>';
 }
Example #25
0
 /**
  * Get the full name of a customer
  *
  * @return string full name
  */
 public function getName()
 {
     return $this->_helperView->getCustomerName($this->getCustomer());
 }
Example #26
0
 /**
  * Get customer name by his ID.
  *
  * @param int $customerId
  * @return string
  */
 protected function _getCustomerName($customerId)
 {
     $customerData = $this->_customerAccountService->getCustomer($customerId);
     return $this->_customerViewHelper->getCustomerName($customerData);
 }
Example #27
0
 /**
  * Send customer email
  *
  * @return bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function send()
 {
     if ($this->_website === null || $this->_customer === null) {
         return false;
     }
     if ($this->_type == 'price' && count($this->_priceProducts) == 0 || $this->_type == 'stock' && count($this->_stockProducts) == 0) {
         return false;
     }
     if (!$this->_website->getDefaultGroup() || !$this->_website->getDefaultGroup()->getDefaultStore()) {
         return false;
     }
     if ($this->_customer->getStoreId() > 0) {
         $store = $this->_storeManager->getStore($this->_customer->getStoreId());
     } else {
         $store = $this->_website->getDefaultStore();
     }
     $storeId = $store->getId();
     if ($this->_type == 'price' && !$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_PRICE_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) {
         return false;
     } elseif ($this->_type == 'stock' && !$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_STOCK_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) {
         return false;
     }
     if ($this->_type != 'price' && $this->_type != 'stock') {
         return false;
     }
     $this->_appEmulation->startEnvironmentEmulation($storeId);
     if ($this->_type == 'price') {
         $this->_getPriceBlock()->setStore($store)->reset();
         foreach ($this->_priceProducts as $product) {
             $product->setCustomerGroupId($this->_customer->getGroupId());
             $this->_getPriceBlock()->addProduct($product);
         }
         $block = $this->_getPriceBlock();
         $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_PRICE_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
     } else {
         $this->_getStockBlock()->setStore($store)->reset();
         foreach ($this->_stockProducts as $product) {
             $product->setCustomerGroupId($this->_customer->getGroupId());
             $this->_getStockBlock()->addProduct($product);
         }
         $block = $this->_getStockBlock();
         $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_STOCK_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
     }
     $alertGrid = $this->_appState->emulateAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND, [$block, 'toHtml']);
     $this->_appEmulation->stopEnvironmentEmulation();
     $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])->setTemplateVars(['customerName' => $this->_customerHelper->getCustomerName($this->_customer), 'alertGrid' => $alertGrid])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($this->_customer->getEmail(), $this->_customerHelper->getCustomerName($this->_customer))->getTransport();
     $transport->sendMessage();
     return true;
 }
Example #28
0
 /**
  * Concatenate all customer name parts into full customer name.
  *
  * @return string
  */
 public function getCustomerName()
 {
     $customer = $this->_customerAccountService->getCustomer($this->_customerSession->getCustomerId());
     return $this->_viewHelper->getCustomerName($customer);
 }
Example #29
0
 /**
  * Get customer name by his ID
  *
  * @param int $customerId
  * @return string
  */
 protected function _getCustomerName($customerId)
 {
     $customerData = $this->customerRepository->getById($customerId);
     return $this->_customerViewHelper->getCustomerName($customerData);
 }
Example #30
0
 /**
  * Retrieve username for form field
  *
  * @return string
  */
 public function getUserName()
 {
     return $this->_customerView->getCustomerName($this->_customerSession->getCustomerDataObject());
 }