• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Template\TransportBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Magento\Framework\Mail\Template\TransportBuilder的典型用法代码示例。如果您正苦于以下问题:PHP TransportBuilder类的具体用法?PHP TransportBuilder怎么用?PHP TransportBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TransportBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * 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;
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:41,代码来源:Post.php


示例2: sendNotification

 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;
     }
 }
开发者ID:alinmiron,项目名称:alin-cadou,代码行数:33,代码来源:Mailer.php


示例3: configureEmailTemplate

 /**
  * Configure email template
  *
  * @return void
  */
 protected function configureEmailTemplate()
 {
     $this->transportBuilder->setTemplateIdentifier($this->templateContainer->getTemplateId());
     $this->transportBuilder->setTemplateOptions($this->templateContainer->getTemplateOptions());
     $this->transportBuilder->setTemplateVars($this->templateContainer->getTemplateVars());
     $this->transportBuilder->setFrom($this->identityContainer->getEmailIdentity());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:SenderBuilder.php


示例4: testSubscribe

 public function testSubscribe()
 {
     $email = '[email protected]';
     $this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']);
     $this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field');
     $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true);
     $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
     $customerDataModel = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel);
     $this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1);
     $customerDataModel->expects($this->any())->method('getEmail')->willReturn($email);
     $this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel);
     $customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1);
     $customerDataModel->expects($this->any())->method('getId')->willReturn(1);
     $this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf();
     $storeModel = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false);
     $this->scopeConfig->expects($this->any())->method('getValue')->willReturn('[email protected]');
     $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
     $storeModel->expects($this->any())->method('getId')->willReturn(1);
     $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface');
     $this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport);
     $transport->expects($this->any())->method('sendMessage')->willReturnSelf();
     $inlineTranslation = $this->getMock('Magento\\Framework\\Translate\\Inline\\StateInterface');
     $inlineTranslation->expects($this->any())->method('resume')->willReturnSelf();
     $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
     $this->assertEquals(1, $this->subscriber->subscribe($email));
 }
开发者ID:opexsw,项目名称:magento2,代码行数:31,代码来源:SubscriberTest.php


示例5: _sendEmail

 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();
 }
开发者ID:swissup,项目名称:testimonials,代码行数:8,代码来源:Admin.php


示例6: execute

 public function execute()
 {
     $email = $this->getRequest()->getParam('email');
     //        $this->_objectManager->get('Ebizmarts\Mandrill\Helper\Data')->sendTestEmail($email);
     $template = "mandrill_test_template";
     $transport = $this->_transportBuilder->setTemplateIdentifier($template)->setFrom($this->_objectManager->get('Ebizmarts\\Mandrill\\Helper\\Data')->getTestSender())->addTo($email)->setTemplateVars([])->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 1])->getTransport();
     $transport->sendMessage();
     $response = new Object();
     $response->setError(0);
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
     $resultJson->setData($response->toArray());
     return $resultJson;
 }
开发者ID:thomas-spigel,项目名称:magento2-mandrill,代码行数:14,代码来源:Test.php


示例7: _sendLogCleanEmail

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Cron.php


示例8: _sendPopupCoupon

 protected function _sendPopupCoupon($storeId)
 {
     $templateId = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_TEMPLATE_XML_PATH, $storeId);
     $mailSubject = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_MAIL_SUBJECT, $storeId);
     $tags = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_MANDRILL_TAG, $storeId) . "_{$storeId}";
     $senderId = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::SENDER, $storeId);
     $sender = array('name' => $this->_helper->getConfig("trans_email/ident_{$senderId}/name", $storeId), 'email' => $this->_helper->getConfig("trans_email/ident_{$senderId}/email", $storeId));
     //coupon vars
     $this->couponamount = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_DISCOUNT, $storeId);
     $this->couponexpiredays = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_EXPIRE, $storeId);
     $this->coupontype = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_DISCOUNTTYPE, $storeId);
     $this->couponlength = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_LENGTH, $storeId);
     $this->couponlabel = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_LABEL, $storeId);
     $collection = $this->_objectManager->create('Ebizmarts\\AbandonedCart\\Model\\Popup')->getCollection()->addFieldToFilter('email', array('neq' => ''))->addFieldToFilter('processed', array('eq' => 0));
     $mandrillHelper = $this->_objectManager->create('Ebizmarts\\Mandrill\\Helper\\Data');
     foreach ($collection as $item) {
         $email = $item->getEmail();
         $emailArr = explode('@', $email);
         $pseudoName = $emailArr[0];
         if ($this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_AUTOMATIC, $storeId) == 2) {
             list($couponCode, $discount, $toDate) = $this->_createNewCoupon($storeId, $email);
             $vars = array('couponcode' => $couponCode, 'discount' => $discount, 'todate' => $toDate, 'name' => $pseudoName, 'tags' => array($tags));
         } else {
             $couponCode = $this->_helper->getConfig(\Ebizmarts\AbandonedCart\Model\Config::POPUP_COUPON_CODE);
             $vars = array('couponcode' => $couponCode, 'name' => $pseudoName, 'tags' => array($tags));
         }
         $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => FrontNameResolver::AREA_CODE, 'store' => $storeId])->setSubject($mailSubject)->setTemplateVars($vars)->setFrom($sender)->addTo($email, $pseudoName)->getTransport();
         $transport->sendMessage();
         $item->setProcessed(1)->save();
         $mandrillHelper->saveMail('review coupon', $email, $pseudoName, $couponCode, $storeId);
     }
 }
开发者ID:lazyguru,项目名称:magento2-abandonedcart,代码行数:32,代码来源:Cron.php


示例9: scheduledGenerateSitemaps

 /**
  * 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();
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:32,代码来源:Observer.php


示例10: scheduledUpdateCurrencyRates

 /**
  * @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();
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:40,代码来源:Observer.php


示例11: testNewAccount

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testNewAccount()
 {
     $customerId = 1;
     $customerStoreId = 2;
     $customerEmail = '[email protected]';
     $customerData = ['key' => 'value'];
     $customerName = 'Customer Name';
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     $customer = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class, [], [], '', false);
     $customer->expects($this->any())->method('getStoreId')->willReturn($customerStoreId);
     $customer->expects($this->any())->method('getId')->willReturn($customerId);
     $customer->expects($this->any())->method('getEmail')->willReturn($customerEmail);
     $this->storeMock->expects($this->any())->method('getId')->willReturn($customerStoreId);
     $this->storeManagerMock->expects($this->once())->method('getStore')->with($customerStoreId)->willReturn($this->storeMock);
     $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecureMock);
     $this->dataProcessorMock->expects($this->once())->method('buildOutputDataArray')->with($customer, \Magento\Customer\Api\Data\CustomerInterface::class)->willReturn($customerData);
     $this->customerViewHelperMock->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName);
     $this->customerSecureMock->expects($this->once())->method('addData')->with($customerData)->willReturnSelf();
     $this->customerSecureMock->expects($this->once())->method('setData')->with('name', $customerName)->willReturnSelf();
     $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with(EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($templateIdentifier);
     $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with(EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($sender);
     $transport = $this->getMock(\Magento\Framework\Mail\TransportInterface::class, [], [], '', false);
     $this->transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('setTemplateVars')->with(['customer' => $this->customerSecureMock, 'back_url' => '', 'store' => $this->storeMock])->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('addTo')->with($customerEmail, $customerName)->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('getTransport')->willReturn($transport);
     $transport->expects($this->once())->method('sendMessage');
     $this->model->newAccount($customer, EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED, '', $customerStoreId);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:35,代码来源:EmailNotificationTest.php


示例12: informCustomer

 public function informCustomer(\Magento\Sales\Model\Order $order, $amount, $currency)
 {
     try {
         if (!($order_increment_id = $order->getRealOrderId()) or !($method_config = $this->_s2pModel->getFullConfigArray())) {
             return false;
         }
         $siteUrl = $order->getStore()->getBaseUrl();
         $siteName = $this->_helper->getStoreName();
         $supportEmail = $this->_helper->getStoreConfig('trans_email/ident_support/email');
         $supportName = $this->_helper->getStoreConfig('trans_email/ident_support/name');
         $payment_details_arr['site_url'] = $siteUrl;
         $payment_details_arr['order_increment_id'] = $order_increment_id;
         $payment_details_arr['site_name'] = $siteName;
         $payment_details_arr['customer_name'] = $order->getCustomerName();
         $payment_details_arr['order_date'] = $order->getCreatedAtFormatted(\IntlDateFormatter::LONG);
         $payment_details_arr['support_email'] = $supportEmail;
         $payment_details_arr['total_paid'] = number_format($amount / 100, 2);
         $payment_details_arr['currency'] = $currency;
         $transport = $this->_transportBuilder->setTemplateIdentifier($method_config['smart2pay_email_payment_confirmation'])->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => $order->getStore()->getId()])->setTemplateVars($payment_details_arr)->setFrom(['name' => $supportName, 'email' => $supportEmail])->addTo($order->getCustomerEmail())->getTransport();
         $transport->sendMessage();
     } catch (\Magento\Framework\Exception\MailException $e) {
         $this->_s2pLogger->write('Error sending customer informational email to [' . $order->getCustomerEmail() . ']', 'email_template');
         $this->_s2pLogger->write($e->getMessage(), 'email_exception');
     } catch (\Exception $e) {
         $this->_s2pLogger->write($e->getMessage(), 'exception');
     }
     return true;
 }
开发者ID:smart2pay,项目名称:magento20,代码行数:28,代码来源:Notification.php


示例13: sendEmailTemplate

 /**
  * Send corresponding email template
  *
  * @param CustomerInterface $customer
  * @param string $template configuration path of email template
  * @param string $sender configuration path of email identity
  * @param array $templateParams
  * @param int|null $storeId
  * @param string $email
  * @return void
  */
 private function sendEmailTemplate($customer, $template, $sender, $templateParams = [], $storeId = null, $email = null)
 {
     $templateId = $this->scopeConfig->getValue($template, 'store', $storeId);
     if ($email === null) {
         $email = $customer->getEmail();
     }
     $transport = $this->transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => 'frontend', 'store' => $storeId])->setTemplateVars($templateParams)->setFrom($this->scopeConfig->getValue($sender, 'store', $storeId))->addTo($email, $this->customerViewHelper->getCustomerName($customer))->getTransport();
     $transport->sendMessage();
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:20,代码来源:EmailNotification.php


示例14: sendEmailTemplate

 /**
  * Send corresponding email template
  *
  * @param CustomerInterface $customer
  * @param string $template configuration path of email template
  * @param string $sender configuration path of email identity
  * @param array $templateParams
  * @param int|null $storeId
  * @param string $email
  * @return $this
  */
 protected function sendEmailTemplate($customer, $template, $sender, $templateParams = [], $storeId = null, $email = null)
 {
     $templateId = $this->scopeConfig->getValue($template, ScopeInterface::SCOPE_STORE, $storeId);
     if ($email === null) {
         $email = $customer->getEmail();
     }
     $transport = $this->transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])->setTemplateVars($templateParams)->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))->addTo($email, $this->customerViewHelper->getCustomerName($customer))->getTransport();
     $transport->sendMessage();
     return $this;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:21,代码来源:EmailNotification.php


示例15: prepareEmailSend

 /**
  * @param $email
  * @param $templateIdentifier
  * @param $sender
  * @param $storeId
  * @param $customerName
  */
 protected function prepareEmailSend($email, $templateIdentifier, $sender, $storeId, $customerName)
 {
     $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock();
     $this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('setTemplateOptions')->with(['area' => Area::AREA_FRONTEND, 'store' => $storeId])->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('setTemplateVars')->with(['customer' => $this->customerSecure, 'store' => $this->store])->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('setFrom')->with($sender)->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('addTo')->with($email, $customerName)->willReturnSelf();
     $this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport);
     $transport->expects($this->any())->method('sendMessage');
 }
开发者ID:nja78,项目名称:magento2,代码行数:18,代码来源:AccountManagementTest.php


示例16: testSendPasswordResetConfirmationEmail

    /**
     * @return void
     */
    public function testSendPasswordResetConfirmationEmail()
    {
        $storeId = 0;
        $email = '[email protected]';
        $firstName = 'Foo';
        $lastName = 'Bar';

        $this->model->setEmail($email);
        $this->model->setFirstname($firstName);
        $this->model->setLastname($lastName);

        $this->configMock->expects($this->at(0))
            ->method('getValue')
            ->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_TEMPLATE)
            ->willReturn('templateId');
        $this->configMock->expects($this->at(1))
            ->method('getValue')
            ->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY)
            ->willReturn('sender');
        $this->transportBuilderMock->expects($this->once())
            ->method('setTemplateModel')
            ->with($this->equalTo('Magento\Email\Model\BackendTemplate'))
            ->willReturnSelf();
        $this->transportBuilderMock->expects($this->once())
            ->method('setTemplateOptions')
            ->willReturnSelf();
        $this->transportBuilderMock->expects($this->once())
            ->method('setTemplateVars')
            ->with(['user' => $this->model, 'store' => $this->storetMock])
            ->willReturnSelf();
        $this->transportBuilderMock->expects($this->once())
            ->method('addTo')
            ->with($this->equalTo($email), $this->equalTo($firstName . ' ' . $lastName))
            ->willReturnSelf();
        $this->transportBuilderMock->expects($this->once())
            ->method('setFrom')
            ->with('sender')
            ->willReturnSelf();
        $this->transportBuilderMock->expects($this->once())
            ->method('setTemplateIdentifier')
            ->with('templateId')
            ->willReturnSelf();
        $this->transportBuilderMock->expects($this->once())
            ->method('getTransport')
            ->willReturn($this->transportMock);
        $this->transportMock->expects($this->once())->method('sendMessage');

        $this->storeManagerMock->expects($this->once())
            ->method('getStore')
            ->with($storeId)
            ->willReturn($this->storetMock);

        $this->assertInstanceOf('\Magento\User\Model\User', $this->model->sendPasswordResetConfirmationEmail());
    }
开发者ID:razbakov,项目名称:magento2,代码行数:57,代码来源:UserTest.php


示例17: testSendNotificationEmailsIfRequired

 /**
  * @param int $testNumber
  * @param string $oldEmail
  * @param string $newEmail
  * @param bool $isPasswordChanged
  *
  * @dataProvider sendNotificationEmailsDataProvider
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testSendNotificationEmailsIfRequired($testNumber, $oldEmail, $newEmail, $isPasswordChanged)
 {
     $customerId = 1;
     $customerStoreId = 2;
     $customerWebsiteId = 1;
     $customerData = ['key' => 'value'];
     $customerName = 'Customer Name';
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     switch ($testNumber) {
         case 1:
             $xmlPathTemplate = EmailNotification::XML_PATH_RESET_PASSWORD_TEMPLATE;
             $expects = $this->once();
             break;
         case 2:
             $xmlPathTemplate = EmailNotification::XML_PATH_CHANGE_EMAIL_TEMPLATE;
             $expects = $this->exactly(2);
             break;
         case 3:
             $xmlPathTemplate = EmailNotification::XML_PATH_CHANGE_EMAIL_AND_PASSWORD_TEMPLATE;
             $expects = $this->exactly(2);
             break;
     }
     $origCustomer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $origCustomer->expects($this->any())->method('getStoreId')->willReturn(0);
     $origCustomer->expects($this->any())->method('getId')->willReturn($customerId);
     $origCustomer->expects($this->any())->method('getWebsiteId')->willReturn($customerWebsiteId);
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->any())->method('getId')->willReturn($customerStoreId);
     $this->storeManagerMock->expects(clone $expects)->method('getStore')->willReturn($storeMock);
     $websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->setMethods(['getStoreIds'])->getMock();
     $websiteMock->expects($this->any())->method('getStoreIds')->willReturn([$customerStoreId]);
     $this->storeManagerMock->expects(clone $expects)->method('getWebsite')->with($customerWebsiteId)->willReturn($websiteMock);
     $customerSecureMock = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->getMock();
     $this->customerRegistryMock->expects(clone $expects)->method('retrieveSecureData')->with($customerId)->willReturn($customerSecureMock);
     $this->dataProcessorMock->expects(clone $expects)->method('buildOutputDataArray')->with($origCustomer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData);
     $this->customerViewHelperMock->expects($this->any())->method('getCustomerName')->with($origCustomer)->willReturn($customerName);
     $customerSecureMock->expects(clone $expects)->method('addData')->with($customerData)->willReturnSelf();
     $customerSecureMock->expects(clone $expects)->method('setData')->with('name', $customerName)->willReturnSelf();
     $savedCustomer = clone $origCustomer;
     $origCustomer->expects($this->any())->method('getEmail')->willReturn($oldEmail);
     $savedCustomer->expects($this->any())->method('getEmail')->willReturn($newEmail);
     $this->scopeConfigMock->expects($this->any())->method('getValue')->withConsecutive([$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], [\Magento\Customer\Helper\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], [$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], [\Magento\Customer\Helper\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId])->willReturnOnConsecutiveCalls($templateIdentifier, $sender, $templateIdentifier, $sender);
     $this->transportBuilderMock->expects(clone $expects)->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf();
     $this->transportBuilderMock->expects(clone $expects)->method('setTemplateOptions')->with(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf();
     $this->transportBuilderMock->expects(clone $expects)->method('setTemplateVars')->with(['customer' => $customerSecureMock, 'store' => $storeMock])->willReturnSelf();
     $this->transportBuilderMock->expects(clone $expects)->method('setFrom')->with($sender)->willReturnSelf();
     $this->transportBuilderMock->expects(clone $expects)->method('addTo')->withConsecutive([$oldEmail, $customerName], [$newEmail, $customerName])->willReturnSelf();
     $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock();
     $this->transportBuilderMock->expects(clone $expects)->method('getTransport')->willReturn($transport);
     $transport->expects(clone $expects)->method('sendMessage');
     $this->assertEquals($this->helper, $this->helper->sendNotificationEmailsIfRequired($origCustomer, $savedCustomer, $isPasswordChanged));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:62,代码来源:EmailNotificationTest.php


示例18: _processBirthday

 /**
  * @param $storeId
  */
 public function _processBirthday($storeId)
 {
     $days = $this->_helper->getConfig(Config::BIRTHDAY_DAYS, $storeId);
     $customerGroups = explode(",", $this->_helper->getConfig(Config::BIRTHDAY_CUSTOMER_GROUPS, $storeId));
     $senderId = $this->_helper->getConfig(Config::GENERAL_SENDER, $storeId);
     $sender = array('name' => $this->_helper->getConfig("trans_email/ident_{$senderId}/name", $storeId), 'email' => $this->_helper->getConfig("trans_email/ident_{$senderId}/email", $storeId));
     $templateId = $this->_helper->getConfig(Config::BIRTHDAY_TEMPLATE, $storeId);
     $mailSubject = $this->_helper->getConfig(Config::BIRTHDAY_SUBJECT, $storeId);
     $tags = $this->_helper->getConfig(Config::BIRTHDAY_MANDRILL_TAG, $storeId) . "_{$storeId}";
     $sendCoupon = $this->_helper->getConfig(Config::BIRTHDAY_COUPON, $storeId);
     $customerGroupsCoupon = explode(",", $this->_helper->getConfig(Config::BIRTHDAY_CUSTOMER_COUPON, $storeId));
     $collection = $this->_customerCollection;
     $date2 = date("Y-m-d H:i:s", strtotime(" + {$days} days"));
     $month = date("m", strtotime($date2));
     $day = date("d", strtotime($date2));
     $moreSelect = "MONTH(at_dob.value) = {$month} AND DAY(at_dob.value) = {$day}";
     $collection->addAttributeToFilter('dob', array('neq' => 'null'))->addFieldToFilter('store_id', array('eq' => $storeId));
     if (count($customerGroups)) {
         $collection->addFieldToFilter('group_id', array('in' => $customerGroups));
     }
     $collection->getSelect()->where($moreSelect);
     $mandrillHelper = $this->_objectManager->get('\\Ebizmarts\\Mandrill\\Helper\\Data');
     foreach ($collection as $customer) {
         $cust = $this->_objectManager->create('Magento\\Customer\\Model\\Customer')->load($customer->getEntityId());
         $email = $cust->getEmail();
         $name = $cust->getFirstname() . ' ' . $cust->getLastname();
         if ($mandrillHelper->isSubscribed($email, 'birthday', $storeId)) {
             $vars = array();
             $url = $this->_storeManager->getStore($storeId)->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK) . 'mandrill/autoresponder/unsubscribe?list=birthday&email=' . $email . '&store=' . $storeId;
             $couponCode = '';
             if ($sendCoupon && in_array($customer->getGroupId(), $customerGroupsCoupon)) {
                 if ($this->_helper->getConfig(Config::BIRTHDAY_AUTOMATIC, $storeId) == Config::COUPON_AUTOMATIC) {
                     $this->_couponAmount = $this->_helper->getConfig(Config::BIRTHDAY_DISCOUNT, $storeId);
                     $this->_couponExpireDays = $this->_helper->getConfig(Config::BIRTHDAY_EXPIRE, $storeId);
                     $this->_couponType = $this->_helper->getConfig(Config::BIRTHDAY_DISCOUNT_TYPE, $storeId);
                     $this->_couponLength = $this->_helper->getConfig(Config::BIRTHDAY_LENGTH, $storeId);
                     $this->_couponLabel = $this->_helper->getConfig(Config::BIRTHDAY_COUPON_LABEL, $storeId);
                     list($couponCode, $discount, $toDate) = $this->_createNewCoupon($storeId, $email, 'Birthday coupon');
                     $vars = array('couponcode' => $couponCode, 'discount' => $discount, 'todate' => $toDate, 'name' => $name, 'tags' => array($tags), 'url' => $url);
                 } else {
                     $couponCode = $this->_helper->getConfig(Config::BIRTHDAY_COUPON_CODE);
                     $vars = array('couponcode' => $couponCode, 'name' => $name, 'tags' => array($tags), 'url' => $url);
                 }
             }
             $transport = $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $storeId])->setTemplateVars($vars)->setFrom($sender)->addTo($email, $name)->getTransport();
             $transport->sendMessage();
             $mandrillHelper->saveMail('happy birthday', $email, $name, $couponCode, $storeId);
         }
     }
 }
开发者ID:ebizmarts,项目名称:magento2-autoresponder,代码行数:53,代码来源:Cron.php


示例19: execute

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Math\Random类代码示例发布时间:2022-05-23
下一篇:
PHP Locale\ResolverInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap