Files

100 lines
2.5 KiB
PHP

<?php
namespace Lts\Sales\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Helper\Context;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Exception\MailException;
use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\Translate\Inline\StateInterface;
use Psr\Log\LoggerInterface;
use Magento\Framework\App\Area;
use JR\NetSuite\Logger\Logger;
class Email extends AbstractHelper
{
public function __construct(
protected Context $context,
protected StoreManagerInterface $storeManager,
protected TransportBuilder $transportBuilder,
protected StateInterface $inlineTranslation,
protected Logger $logger
)
{
parent::__construct($context);
}
/**
* Send Mail
*
* @return $this
*
* @throws LocalizedException
* @throws MailException
* @throws LocalizedException
*/
public function sendMail(string $orders, string $syncFailData)
{
$email = 'netsuite.admins@ltsecurityinc.com';
// $email = 'fengliang2626@vip.qq.com';
$this->inlineTranslation->suspend();
$storeId = $this->getStoreId();
/* email template */
$template = 'sales_order_sync_nesuite';
$vars = [
'syncFailData' => $syncFailData,
'orders' => $orders,
'store' => $this->getStore()
];
$transport = $this->transportBuilder->setTemplateIdentifier(
$template
)->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->getStoreId()
]
)->setTemplateVars(
$vars
)->setFromByScope(
'general'
)->addTo(
$email
)->addBcc(
['344531331@qq.com']
)->getTransport();
try {
$transport->sendMessage();
} catch (\Exception $exception) {
$this->logger->critical($exception->getMessage());
}
$this->inlineTranslation->resume();
return $this;
}
/*
* get Current store id
*/
public function getStoreId()
{
return $this->storeManager->getStore()->getId();
}
/*
* get Current store Info
*/
public function getStore()
{
return $this->storeManager->getStore();
}
}