I'm creating an extension which sends email from command console and / or cron.
https://github.com/DominicWatts/BackInStock/tree/develop
In https://github.com/DominicWatts/BackInStock/blob/develop/Helper/Data.php#L168-L226
I've got this
const XML_PATH_EMAIL_TEMPLATE = 'backinstock/email/template';
public function sendTransactionalEmail($vars = [])
{
$email = $vars['email'] ?? null;
if (empty($vars) || !$email) {
return;
}
$this->inlineTranslation->suspend();
try {
$postObject = new \Magento\Framework\DataObject();
$postObject->setData($vars);
$recipient = [
'firstname' => $this->escaper->escapeHtml($vars['firstname']),
'email' => $this->escaper->escapeHtml($vars['email']),
];
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
$this->transportBuilder->setTemplateIdentifier(
$this->scopeConfig->getValue(
self::XML_PATH_EMAIL_TEMPLATE,
$storeScope
)
)->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
]
)->setTemplateVars(
[
'firstname' => $vars['firstname'] ?? null,
'lastname' => $vars['lastname'] ?? null,
'email' => $email,
'productname' => $vars['productname'] ?? null,
'productlink' => $vars['productlink'] ?? null
]
)->setFrom(
$this->scopeConfig->getValue(
self::XML_PATH_EMAIL_IDENTITY,
$storeScope
)
)->addTo(
$recipient['email'],
$recipient['firstname']
);
$transport = $this->transportBuilder->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
return true;
} catch (Exception $e) {
$this->logger->critical($e);
}
return false;
}
https://github.com/DominicWatts/BackInStock/blob/develop/etc/email_templates.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="backinstock_email_template" label="Back In Stock" file="back_in_stock.html" type="html" module="Xigne_BackInStock" area="frontend"/>
</config>
Email template is in place
https://github.com/DominicWatts/BackInStock/blob/develop/view/frontend/email/back_in_stock.html
Then with some dummy data in I try and run
php bin/magento xigen:backinstock:check check
2019-07-08 23:15:04 Start Notification Process
[UnexpectedValueException]
Template file 'back_in_stock.html' is not found.
xigen:backinstock:check <check>
So that says to me my XML and logic is correct.
Magento is just not seeing my email template. Trouble is I just can't see what's wrong. Path looks correct.
Tried clearing cache, di compile, setup upgrade.