<?php
require_once __DIR__ . '/app/bootstrap.php';
class Payreminder implements MagentoFrameworkAppInterface
{
protected $orderRepository;
protected $storeManager;
protected $scopeConfig;
protected $inlineTranslation;
protected $transportBuilder;
protected $state;
public function __construct(
\Magento\Framework\App\State $state,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
)
{
$state->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
$this->orderRepository = $orderRepository;
$this->storeManager = $storeManager;
$this->scopeConfig = $scopeConfig;
$this->inlineTranslation = $inlineTranslation;
$this->transportBuilder = $transportBuilder;
}
public function launch()
{
$order = $this->orderRepository->get(1);
$storeId = $order->getStoreId();
$templateOptions = array('area' => MagentoFrameworkAppArea::AREA_FRONTEND, 'store' => $storeId);
$templateVars = array(
'store' => $this->storeManager->getStore($order->getStoreId()),
'order' => $order,
);
$this->inlineTranslation->suspend();
$to = array($order->getCustomerEmail());
$sender = [
'name' => $this->scopeConfig->getValue(
'trans_email/ident_sales/name',
MagentoStoreModelScopeInterface::SCOPE_STORE
),
'email' => $this->scopeConfig->getValue(
'trans_email/ident_sales/email',
MagentoStoreModelScopeInterface::SCOPE_STORE
)
];
$transport = $this->transportBuilder->setTemplateIdentifier('payreminder_email_general_email')
->setTemplateOptions($templateOptions)
->setTemplateVars($templateVars)
->setFrom($sender)
->addTo($to)
->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
die();
}
public function catchException(
MagentoFrameworkAppBootstrap $bootstrap,
Exception $exception)
{
echo "expcetionn";
return true;
}
}
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('Payreminder');
$bootstrap->run($app);