MAGENTO 2:未传递必需的参数“ THEME_DIR”

今天我们将讨论以下错误必需参数'theme_dir'未通过当我们试图从cron作业执行代码或使用CLI通过CLI命令手动运行时遇到的错误以下命令-:

php bin/magento scommerce:custom:sendcustomemails

请看一下我们下面的自定义命令类,该类已经到位并引发以下异常-:

Required parameter 'theme_dir' was not passed error
/**
 * @var State
 */
private $_state;
 
/**
 * @var CustomClass
 */
private $_customClass;
 
/**
 * __construct
 *
 * @param CustomClass $customClass
 * @param State $state
 */
public function __construct(
    CustomClass $customClass,
    State $state
 
) {
    parent::__construct();
    $this->_customClass = $customClass;
    $this->_state = $state;
}
 
/**
 * Configure to send custom emails
 */
protected function configure()
{
    $this->setName("scommerce:custom:sendcustomemails")->setDescription('Send Custom Emails');
    parent::configure();
}
 
/**
 * @param InputInterface $input
 * @param OutputInterface $output
 * @return int|null
 */
protected function execute(InputInterface $input, OutputInterface $output)
{
    $this->_state->emulateAreaCode(Area::AREA_ADMINHTML, [$this->_customClass, 'sendCustomEmailUsingCollection']);
    return Cli::RETURN_SUCCESS;
}

经过详细调查,我们发现email_templates.xml文件中的电子邮件模板具有以下条目

<template id="scommerce_custom_email_to_customers"
label="Scommerce Custom Email To Customers"
file="scommerce_custom_email_to_customers.html"
type="html" module="Scommerce_Custom"
area="frontend"/>

请注意,电子邮件模板的定义区域被定义为“前端”,而在上述命令PHP类中,在emulateAreaCode函数下其作为AREA_ADMINHTML传递,因此我们在命令类中将区域代码从ADMINHTML更改FRONTEND,如下所示

/**
 * @param InputInterface $input
 * @param OutputInterface $output
 * @return int|null
 */
protected function execute(InputInterface $input, OutputInterface $output)
{
    $this->_state->emulateAreaCode(Area::AREA_FRONTEND, [$this->_customClass, 'sendCustomEmailUsingCollection']);
    return Cli::RETURN_SUCCESS;
}

未传递必需的参数“ theme_dir”,错误消失了。这里要注意的关键是我们应该确保我们的Cron Jobs和命令设置有适当的区号,以使它们顺利运行。此设置区号文章将帮助您在命令类中正确设置区号。

希望本文对您有所帮助。请留下您的评论,让我们知道您的想法?谢谢。

版权属于: sbboke版权所有。

转载时必须以链接形式注明作者和原始出处及本声明。

张贴在magento2教程标签:

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论