Esempio n. 1
1
 /**
  * Post user question
  *
  * @return void
  * @throws \Exception
  */
 public function execute()
 {
     $post = $this->getRequest()->getPostValue();
     if (!$post) {
         $this->_redirect('*/*/');
         return;
     }
     $this->inlineTranslation->suspend();
     try {
         $postObject = new \Magento\Framework\DataObject();
         $postObject->setData($post);
         $error = false;
         if (!\Zend_Validate::is(trim($post['contact_email']), 'EmailAddress')) {
             $error = true;
         }
         if (!\Zend_Validate::is(trim($post['contact_question']), 'NotEmpty')) {
             $error = true;
         }
         if ($error) {
             throw new \Exception();
         }
         $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
         $transport = $this->_transportBuilder->setTemplateIdentifier($this->scopeConfig->getValue(self::XML_PATH_EMAIL_TEMPLATE, $storeScope))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['data' => $postObject])->setFrom($this->scopeConfig->getValue(self::XML_PATH_EMAIL_SENDER, $storeScope))->addTo($this->scopeConfig->getValue(self::XML_PATH_EMAIL_RECIPIENT, $storeScope))->setReplyTo($post['contact_email'])->getTransport();
         $transport->sendMessage();
         $this->inlineTranslation->resume();
         $this->messageManager->addSuccess(__('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.'));
         $this->_redirect('delivery-charges');
         return;
     } catch (\Exception $e) {
         $this->inlineTranslation->resume();
         $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.'));
         $this->_redirect('delivery-charges');
         return;
     }
 }
Esempio n. 2
0
 public function sendNotification($data)
 {
     if (!$data) {
         return false;
     }
     $this->inlineTranslation->suspend();
     try {
         $postObject = new \Magento\Framework\DataObject();
         $postObject->setData($data);
         $error = false;
         $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
         /* $from = [
                'name' => '',
                'email' => ''
            ];*/
         $email_template = $this->scopeConfig->getValue('cadou/email/template');
         if (empty($email_template)) {
             $email_template = (string) 'cadou_email_template';
             // this code we have mentioned in the email_templates.xml
         }
         $transport = $this->_transportBuilder->setTemplateIdentifier($email_template)->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $this->storeManager->getDefaultStoreView()->getId()])->setTemplateVars(['data' => $postObject, 'subject' => $data['productname']])->setFrom($this->scopeConfig->getValue('contact/email/sender_email_identity', $storeScope))->addTo($data['email'], isset($data['fullname']) ? $data['fullname'] : $data['name'])->getTransport();
         $transport->sendMessage();
         $this->inlineTranslation->resume();
         /*$this->messageManager->addSuccess(
               __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
           );*/
         return TRUE;
     } catch (\Exception $e) {
         $this->inlineTranslation->resume();
         $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.' . $e->getMessage()));
         return FALSE;
     }
 }
Esempio n. 3
0
 protected function _sendEmail($from, $to, $templateId, $vars, $store, $area = \Magento\Framework\App\Area::AREA_FRONTEND)
 {
     $this->inlineTranslation->suspend();
     $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => $area, 'store' => $store->getId()])->setTemplateVars($vars)->setFrom($from)->addTo($to['email'], $to['name']);
     $transport = $this->_transportBuilder->getTransport();
     $transport->sendMessage();
     $this->inlineTranslation->resume();
 }
Esempio n. 4
0
 public function testIsAllowed()
 {
     $this->assertTrue($this->_model->isAllowed());
     $this->assertTrue($this->_model->isAllowed($this->_storeId));
     $this->assertTrue($this->_model->isAllowed(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($this->_storeId)));
     $this->state->suspend();
     $this->assertFalse($this->_model->isAllowed());
     $this->assertFalse($this->_model->isAllowed($this->_storeId));
     $this->assertFalse($this->_model->isAllowed(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($this->_storeId)));
 }
Esempio n. 5
0
 /**
  * Send Log Clean Warnings
  *
  * @return $this
  */
 protected function _sendLogCleanEmail()
 {
     if (!$this->_errors) {
         return $this;
     }
     if (!$this->_scopeConfig->getValue(self::XML_PATH_EMAIL_LOG_CLEAN_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
         return $this;
     }
     $this->inlineTranslation->suspend();
     $transport = $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_LOG_CLEAN_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId()])->setTemplateVars(['warnings' => join("\n", $this->_errors)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_LOG_CLEAN_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_LOG_CLEAN_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->getTransport();
     $transport->sendMessage();
     $this->inlineTranslation->resume();
     return $this;
 }
Esempio n. 6
0
 public function testStop()
 {
     // Test data
     $initArea = 'initial area';
     $initTheme = 'initial design theme';
     $initLocale = 'initial locale code';
     $initialStore = 1;
     $initTranslateInline = false;
     $this->inlineTranslationMock->expects($this->once())->method('isEnabled')->willReturn($initTranslateInline);
     $this->viewDesignMock->expects($this->once())->method('getArea')->willReturn($initArea);
     $this->viewDesignMock->expects($this->once())->method('getDesignTheme')->willReturn($initTheme);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->once())->method('getStoreId')->willReturn($initialStore);
     $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn($initLocale);
     $this->model->storeCurrentEnvironmentInfo();
     // Expectations
     $this->inlineTranslationMock->expects($this->once())->method('resume')->with($initTranslateInline);
     $this->viewDesignMock->expects($this->once())->method('setDesignTheme')->with($initTheme, $initArea);
     $this->storeManagerMock->expects($this->once())->method('setCurrentStore')->with($initialStore);
     $this->localeResolverMock->expects($this->once())->method('setLocale')->with($initLocale);
     $this->translateMock->expects($this->once())->method('setLocale')->with($initLocale);
     $this->translateMock->expects($this->once())->method('loadData')->with($initArea);
     // Test
     $this->model->stopEnvironmentEmulation();
 }
Esempio n. 7
0
 /**
  * @param mixed $schedule
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function scheduledUpdateCurrencyRates($schedule)
 {
     $importWarnings = [];
     if (!$this->_scopeConfig->getValue(self::IMPORT_ENABLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) || !$this->_scopeConfig->getValue(self::CRON_STRING_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
         return;
     }
     $errors = [];
     $rates = [];
     $service = $this->_scopeConfig->getValue(self::IMPORT_SERVICE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($service) {
         try {
             $importModel = $this->_importFactory->create($service);
             $rates = $importModel->fetchRates();
             $errors = $importModel->getMessages();
         } catch (\Exception $e) {
             $importWarnings[] = __('FATAL ERROR:') . ' ' . __('We can\'t initialize the import model.');
         }
     } else {
         $importWarnings[] = __('FATAL ERROR:') . ' ' . __('Please specify the correct Import Service.');
     }
     if (sizeof($errors) > 0) {
         foreach ($errors as $error) {
             $importWarnings[] = __('WARNING:') . ' ' . $error;
         }
     }
     if (sizeof($importWarnings) == 0) {
         $this->_currencyFactory->create()->saveRates($rates);
     } else {
         $this->inlineTranslation->suspend();
         $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $importWarnings)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
         $transport = $this->_transportBuilder->getTransport();
         $transport->sendMessage();
         $this->inlineTranslation->resume();
     }
 }
Esempio n. 8
0
 /**
  * Generate sitemaps
  *
  * @return void
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function scheduledGenerateSitemaps()
 {
     $errors = [];
     // check if scheduled generation enabled
     if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_GENERATION_ENABLED, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
         return;
     }
     $collection = $this->_collectionFactory->create();
     /* @var $collection \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection */
     foreach ($collection as $sitemap) {
         /* @var $sitemap \Magento\Sitemap\Model\Sitemap */
         try {
             $sitemap->generateXml();
         } catch (\Exception $e) {
             $errors[] = $e->getMessage();
         }
     }
     if ($errors && $this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
         $translate = $this->_translateModel->getTranslateInline();
         $this->_translateModel->setTranslateInline(false);
         $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $errors)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
         $transport = $this->_transportBuilder->getTransport();
         $transport->sendMessage();
         $this->inlineTranslation->resume();
     }
 }
Esempio n. 9
0
 /**
  * @param bool $isEnabled
  * @param bool $isActive
  * @param bool $isDevAllowed
  * @param null|string $scope
  */
 protected function prepareIsAllowed($isEnabled, $isActive, $isDevAllowed, $scope = null)
 {
     $scopeMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface', [], [], '', false);
     $this->stateMock->expects($this->any())->method('isEnabled')->will($this->returnValue($isEnabled));
     $this->scopeResolverMock->expects($this->once())->method('getScope')->with($scope)->will($this->returnValue($scopeMock));
     $this->configMock->expects($this->once())->method('isActive')->with($scopeMock)->will($this->returnValue($isActive));
     $this->configMock->expects($this->exactly((int) $isActive))->method('isDevAllowed')->will($this->returnValue($isDevAllowed));
 }
Esempio n. 10
0
 public function testExecuteValidPost()
 {
     $post = ['name' => 'Name', 'comment' => 'Comment', 'email' => '*****@*****.**', 'hideit' => null];
     $this->_request->expects($this->any())->method('getPostValue')->will($this->returnValue($post));
     $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface', [], [], '', false);
     $this->_transportBuilder->expects($this->once())->method('setTemplateIdentifier')->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('setTemplateVars')->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('setFrom')->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('addTo')->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('setReplyTo')->with($post['email'])->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('getTransport')->will($this->returnValue($transport));
     $transport->expects($this->once())->method('sendMessage');
     $this->_inlineTranslation->expects($this->once())->method('resume');
     $this->_inlineTranslation->expects($this->once())->method('suspend');
     $this->_controller->execute();
 }
 protected function sendEmailCheck()
 {
     $storeModel = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface');
     $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true);
     $this->transportBuilder->expects($this->once())->method('setTemplateIdentifier')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setTemplateOptions')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setTemplateVars')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setFrom')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('addTo')->willReturnSelf();
     $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
     $storeModel->expects($this->any())->method('getId')->willReturn(1);
     $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport);
     $transport->expects($this->once())->method('sendMessage')->willReturnSelf();
     $this->inlineTranslation->expects($this->once())->method('suspend')->willReturnSelf();
     $this->inlineTranslation->expects($this->once())->method('resume')->willReturnSelf();
     return $this;
 }
Esempio n. 12
0
 public function testExecuteValidPost()
 {
     $post = ['name' => 'Name', 'comment' => 'Comment', 'email' => '*****@*****.**', 'hideit' => null];
     $this->_request->expects($this->any())->method('getPost')->will($this->returnValue($post));
     $store = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId', '__sleep', '__wakeup'], [], '', false);
     $store->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface', [], [], '', false);
     $this->_transportBuilder->expects($this->once())->method('setTemplateIdentifier')->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 1])->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('setTemplateVars')->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('setFrom')->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('addTo')->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('setReplyTo')->with($post['email'])->will($this->returnSelf());
     $this->_transportBuilder->expects($this->once())->method('getTransport')->will($this->returnValue($transport));
     $transport->expects($this->once())->method('sendMessage');
     $this->_inlineTranslation->expects($this->once())->method('resume');
     $this->_inlineTranslation->expects($this->once())->method('suspend');
     $this->_controller->execute();
 }
Esempio n. 13
0
 /**
  * Send email id payment was failed
  *
  * @param \Magento\Sales\Model\Quote $checkout
  * @param string $message
  * @param string $checkoutType
  * @return $this
  */
 public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
 {
     $this->inlineTranslation->suspend();
     $template = $this->_scopeConfig->getValue('checkout/payment_failed/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
     $copyMethod = $this->_scopeConfig->getValue('checkout/payment_failed/copy_method', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $bcc = array();
     if ($copyTo && $copyMethod == 'bcc') {
         $bcc = $copyTo;
     }
     $_receiver = $this->_scopeConfig->getValue('checkout/payment_failed/receiver', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $sendTo = array(array('email' => $this->_scopeConfig->getValue('trans_email/ident_' . $_receiver . '/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()), 'name' => $this->_scopeConfig->getValue('trans_email/ident_' . $_receiver . '/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId())));
     if ($copyTo && $copyMethod == 'copy') {
         foreach ($copyTo as $email) {
             $sendTo[] = array('email' => $email, 'name' => null);
         }
     }
     $shippingMethod = '';
     if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
         $data = explode('_', $shippingInfo);
         $shippingMethod = $data[0];
     }
     $paymentMethod = '';
     if ($paymentInfo = $checkout->getPayment()) {
         $paymentMethod = $paymentInfo->getMethod();
     }
     $items = '';
     foreach ($checkout->getAllVisibleItems() as $_item) {
         /* @var $_item \Magento\Sales\Model\Quote\Item */
         $items .= $_item->getProduct()->getName() . '  x ' . $_item->getQty() . '  ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
     }
     $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
     foreach ($sendTo as $recipient) {
         $transport = $this->_transportBuilder->setTemplateIdentifier($template)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()))->setTemplateVars(array('reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => $this->_localeDate->date(), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => $this->_scopeConfig->getValue('carriers/' . $shippingMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'paymentMethod' => $this->_scopeConfig->getValue('payment/' . $paymentMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'items' => nl2br($items), 'total' => $total))->setFrom($this->_scopeConfig->getValue('checkout/payment_failed/identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()))->addTo($recipient['email'], $recipient['name'])->addBcc($bcc)->getTransport();
         $transport->sendMessage();
     }
     $this->inlineTranslation->resume();
     return $this;
 }
Esempio n. 14
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;
     }
 }
Esempio n. 15
0
 /**
  * After getPdf processing
  *
  * @return void
  */
 protected function _afterGetPdf()
 {
     $this->inlineTranslation->resume();
 }
Esempio n. 16
0
 /**
  * Restore initial inline translation state
  *
  * @param bool $initialTranslate
  * @return $this
  */
 protected function _restoreInitialInlineTranslation($initialTranslate)
 {
     $this->inlineTranslation->resume($initialTranslate);
     return $this;
 }
Esempio n. 17
0
 /**
  * @return $this
  * @throws CoreException
  */
 public function send()
 {
     if ($this->isExceedLimit()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('You\'ve met your limit of %1 sends in an hour.', $this->getMaxSendsToFriend()));
     }
     $this->inlineTranslation->suspend();
     $message = nl2br(htmlspecialchars($this->getSender()->getMessage()));
     $sender = ['name' => $this->_escaper->escapeHtml($this->getSender()->getName()), 'email' => $this->_escaper->escapeHtml($this->getSender()->getEmail())];
     foreach ($this->getRecipients()->getEmails() as $k => $email) {
         $name = $this->getRecipients()->getNames($k);
         $this->_transportBuilder->setTemplateIdentifier($this->_sendfriendData->getEmailTemplate())->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId()])->setFrom($sender)->setTemplateVars(['name' => $name, 'email' => $email, 'product_name' => $this->getProduct()->getName(), 'product_url' => $this->getProduct()->getUrlInStore(), 'message' => $message, 'sender_name' => $sender['name'], 'sender_email' => $sender['email'], 'product_image' => $this->_catalogImage->init($this->getProduct(), 'sendfriend_small_image')->getUrl()])->addTo($email, $name);
         $transport = $this->_transportBuilder->getTransport();
         $transport->sendMessage();
     }
     $this->inlineTranslation->resume();
     $this->_incrementSentCount();
     return $this;
 }
Esempio n. 18
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');
     }
 }
Esempio n. 19
0
 /**
  * Sends out unsubscription email
  *
  * @return $this
  */
 public function sendUnsubscriptionEmail()
 {
     if ($this->getImportMode()) {
         return $this;
     }
     if (!$this->_scopeConfig->getValue(self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) || !$this->_scopeConfig->getValue(self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
         return $this;
     }
     $this->inlineTranslation->suspend();
     $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_UNSUBSCRIBE_EMAIL_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId()])->setTemplateVars(['subscriber' => $this])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_UNSUBSCRIBE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->getEmail(), $this->getName());
     $transport = $this->_transportBuilder->getTransport();
     $transport->sendMessage();
     $this->inlineTranslation->resume();
     return $this;
 }
 /**
  * Produce and return block's html output
  *
  * This method should not be overridden. You can override _toHtml() method in descendants if needed.
  *
  * @return string
  */
 public function toHtml()
 {
     $this->_eventManager->dispatch('view_block_abstract_to_html_before', ['block' => $this]);
     if ($this->_scopeConfig->getValue('advanced/modules_disable_output/' . $this->getModuleName(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
         return '';
     }
     $html = $this->_loadCache();
     if ($html === false) {
         if ($this->hasData('translate_inline')) {
             $this->inlineTranslation->suspend($this->getData('translate_inline'));
         }
         $this->_beforeToHtml();
         $html = $this->_toHtml();
         $this->_saveCache($html);
         if ($this->hasData('translate_inline')) {
             $this->inlineTranslation->resume();
         }
     }
     $html = $this->_afterToHtml($html);
     return $html;
 }
Esempio n. 21
0
 /**
  * Send email to administrator if error
  *
  * @return $this
  */
 protected function _sendErrorEmail()
 {
     if (count($this->_errors)) {
         if (!$this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
             return $this;
         }
         $this->inlineTranslation->suspend();
         $transport = $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $this->_errors)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->getTransport();
         $transport->sendMessage();
         $this->inlineTranslation->resume();
         $this->_errors[] = [];
     }
     return $this;
 }