本文整理汇总了PHP中Magento\Framework\Mail\Template\TransportBuilder::getTransport方法的典型用法代码示例。如果您正苦于以下问题:PHP TransportBuilder::getTransport方法的具体用法?PHP TransportBuilder::getTransport怎么用?PHP TransportBuilder::getTransport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Mail\Template\TransportBuilder
的用法示例。
在下文中一共展示了TransportBuilder::getTransport方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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();
}
示例2: sendCopyTo
/**
* Prepare and send copy email message
*
* @return void
*/
public function sendCopyTo()
{
$copyTo = $this->identityContainer->getEmailCopyTo();
if (!empty($copyTo) && $this->identityContainer->getCopyMethod() == 'copy') {
foreach ($copyTo as $email) {
$this->configureEmailTemplate();
$this->transportBuilder->addTo($email);
$transport = $this->transportBuilder->getTransport();
$transport->sendMessage();
}
}
}
示例3: execute
public function execute()
{
$email = $this->getRequest()->getParam('email');
$this->_transportBuilder->setTemplateIdentifier(self::EMAIL_TEMPLATE_TEST_ID);
$this->_transportBuilder->setFrom($this->_helper->getTestSender());
$this->_transportBuilder->addTo($email);
$this->_transportBuilder->setTemplateVars([]);
$this->_transportBuilder->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 1]);
$transport = $this->_transportBuilder->getTransport();
$transport->sendMessage();
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData(['error' => 0]);
return $resultJson;
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: testGetTransport
/**
* @dataProvider getTransportDataProvider
* @param int $templateType
* @param string $messageType
* @param string $bodyText
*/
public function testGetTransport($templateType, $messageType, $bodyText)
{
$vars = ['reason' => 'Reason', 'customer' => 'Customer'];
$options = ['area' => 'frontend', 'store' => 1];
$template = $this->getMock('\\Magento\\Framework\\Mail\\TemplateInterface');
$template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->will($this->returnSelf());
$template->expects($this->once())->method('setOptions')->with($this->equalTo($options))->will($this->returnSelf());
$template->expects($this->once())->method('getSubject')->will($this->returnValue('Email Subject'));
$template->expects($this->once())->method('getType')->will($this->returnValue($templateType));
$template->expects($this->once())->method('processTemplate')->will($this->returnValue($bodyText));
$this->templateFactoryMock->expects($this->once())->method('get')->with($this->equalTo('identifier'))->will($this->returnValue($template));
$this->messageMock->expects($this->once())->method('setSubject')->with($this->equalTo('Email Subject'))->will($this->returnSelf());
$this->messageMock->expects($this->once())->method('setMessageType')->with($this->equalTo($messageType))->will($this->returnSelf());
$this->messageMock->expects($this->once())->method('setBody')->with($this->equalTo($bodyText))->will($this->returnSelf());
$transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface');
$this->_mailTransportFactoryMock->expects($this->at(0))->method('create')->with($this->equalTo(['message' => $this->messageMock]))->will($this->returnValue($transport));
$this->objectManagerMock->expects($this->at(0))->method('create')->with($this->equalTo('Magento\\Framework\\Mail\\Message'))->will($this->returnValue($transport));
$this->builder->setTemplateIdentifier('identifier')->setTemplateVars($vars)->setTemplateOptions($options);
$result = $this->builder->getTransport();
$this->assertInstanceOf('Magento\\Framework\\Mail\\TransportInterface', $result);
}
示例7: send
/**
* @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;
}
示例8: sendOrderUpdateEmail
/**
* Send email with order update information
*
* @param boolean $notifyCustomer
* @param string $comment
* @return $this
*/
public function sendOrderUpdateEmail($notifyCustomer = true, $comment = '')
{
$storeId = $this->getStore()->getId();
if (!$this->_salesData->canSendOrderCommentEmail($storeId)) {
return $this;
}
// Get the destination email addresses to send copies to
$copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO);
$copyMethod = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
// Check if at least one recipient is found
if (!$notifyCustomer && !$copyTo) {
return $this;
}
// Retrieve corresponding email template id and customer name
if ($this->getCustomerIsGuest()) {
$templateId = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
$customerName = $this->getBillingAddress()->getName();
} else {
$templateId = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
$customerName = $this->getCustomerName();
}
if ($notifyCustomer) {
$this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('order' => $this, 'comment' => $comment, 'billing' => $this->getBillingAddress(), 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($this->getCustomerEmail(), $customerName);
if ($copyTo && $copyMethod == 'bcc') {
// Add bcc to customer email
foreach ($copyTo as $email) {
$this->_transportBuilder->addBcc($email);
}
}
/** @var \Magento\Framework\Mail\TransportInterface $transport */
$transport = $this->_transportBuilder->getTransport();
$transport->sendMessage();
}
// Email copies are sent as separated emails if their copy method is
// 'copy' or a customer should not be notified
if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) {
foreach ($copyTo as $email) {
$this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('order' => $this, 'comment' => $comment, 'billing' => $this->getBillingAddress(), 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($email)->getTransport()->sendMessage();
}
}
return $this;
}
示例9: sendUnsubscriptionEmail
/**
* 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;
}