【问题标题】:Can't add {message} variable to order_conf mail template无法将 {message} 变量添加到 order_conf 邮件模板
【发布时间】:2016-07-20 06:08:54
【问题描述】:

在我的classes/PaymentModule.php 上,我已经声明了'{message}' => $customer_message(在其他变量之间),但我的客户仍然在他们收到的邮件中看到Wiadomość: {message}

我做错了什么?也许在 PaymentModule.php 中声明 {message} var 还不够?

UDPATE:

这是 Prestashop 1.6.2.1 中的标准 PaymentModule.php 代码,添加了 {message} 变量:

$customer_message = $order->getFirstMessage();
$data = array(
            '{firstname}' => $this->context->customer->firstname,
            '{lastname}' => $this->context->customer->lastname,
            '{email}' => $this->context->customer->email,
            '{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"),
            '{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"),
            '{delivery_block_html}' => $this->_getFormatedAddress($delivery, '<br />', array(
                'firstname'    => '<span style="font-weight:bold;">%s</span>',
                'lastname'    => '<span style="font-weight:bold;">%s</span>'
            )),
            '{invoice_block_html}' => $this->_getFormatedAddress($invoice, '<br />', array(
                    'firstname'    => '<span style="font-weight:bold;">%s</span>',
                    'lastname'    => '<span style="font-weight:bold;">%s</span>'
            )),
            '{delivery_company}' => $delivery->company,
            '{delivery_firstname}' => $delivery->firstname,
            '{delivery_lastname}' => $delivery->lastname,
            '{delivery_address1}' => $delivery->address1,
            '{delivery_address2}' => $delivery->address2,
            '{delivery_city}' => $delivery->city,
            '{delivery_postal_code}' => $delivery->postcode,
            '{delivery_country}' => $delivery->country,
            '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '',
            '{delivery_phone}' => ($delivery->phone) ? $delivery->phone : $delivery->phone_mobile,
            '{delivery_other}' => $delivery->other,
            '{invoice_company}' => $invoice->company,
            '{invoice_vat_number}' => $invoice->vat_number,
            '{invoice_firstname}' => $invoice->firstname,
            '{invoice_lastname}' => $invoice->lastname,
            '{invoice_address2}' => $invoice->address2,
            '{invoice_address1}' => $invoice->address1,
            '{invoice_city}' => $invoice->city,
            '{invoice_postal_code}' => $invoice->postcode,
            '{invoice_country}' => $invoice->country,
            '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '',
            '{invoice_phone}' => ($invoice->phone) ? $invoice->phone : $invoice->phone_mobile,
            '{invoice_other}' => $invoice->other,
            '{order_name}' => $order->getUniqReference(),
            '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), null, 1),
            '{carrier}' => ($virtual_product || !isset($carrier->name)) ? Tools::displayError('No carrier') : $carrier->name,
            '{payment}' => Tools::substr($order->payment, 0, 32),
            '{products}' => $product_list_html,
            '{products_txt}' => $product_list_txt,
            '{discounts}' => $cart_rules_list_html,
            '{discounts_txt}' => $cart_rules_list_txt,
            '{total_paid}' => Tools::displayPrice($order->total_paid, $this->context->currency, false),
            '{total_products}' => Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $order->total_products : $order->total_products_wt, $this->context->currency, false),
            '{total_discounts}' => Tools::displayPrice($order->total_discounts, $this->context->currency, false),
            '{total_shipping}' => Tools::displayPrice($order->total_shipping, $this->context->currency, false),
            '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $this->context->currency, false),
            '{message}' => $customer_message,
            '{total_tax_paid}' => Tools::displayPrice(($order->total_products_wt - $order->total_products) + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $this->context->currency, false));

在 order_conf.html 中:

...
Wiadomość: {message}
....

【问题讨论】:

  • 你能显示一些代码吗?声明 smarty 变量的代码和使用该变量的模板。
  • 我在您的$data 数组中看不到{message} 声明。
  • 哦,对不起,我用其他商店复制了干净的代码...已添加

标签: php smarty prestashop prestashop-1.6


【解决方案1】:

如果你还没有使用下面的函数,你应该使用它。 示例:

$id_lang = (int)$this->context->language->id;
$heading = Mail::l('Message Received', (int)$id_lang);
Mail::Send(
                (int)$id_lang,
                'order_conf',
                $heading,
                $data,
                $this->context->customer->email,
                null,
                null,
                $this->context->shop->name,
                null,
                null,
                _PS_MODULE_DIR_.'mymodule/mail/',
                false,
                1
                );

邮件模板应位于 'mymodule/mail/en/order_conf.html' 根据您的语言制作语言目录,例如 /en 、 /fr 、 /nl

【讨论】:

    【解决方案2】:

    使用 Prestashop 1.7,我已经用

    进行了测试
    '{message}'  => 'hello',
    

    它显示在电子邮件中:你好

    你确定你在$customer_message 里有东西吗?

    使用一些变量可能会更复杂。看看$product_list_html

    你会看到它是一个数组,并且有:

    $product_list_html = $this->getEmailTemplateContent('order_conf_product_list.tpl', Mail::TYPE_HTML, $product_var_tpl_list);
    

    它使用另一个模板来构建产品列表(order_conf_product_list.tpl)

    【讨论】:

      【解决方案3】:

      我知道该帖子已有 3 年历史,但解决方案未使用

      $customer_message
      

      但是

      $customer_message->message
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-28
        • 2014-01-16
        • 2023-01-13
        • 2015-03-22
        • 2012-03-01
        • 2020-06-06
        • 2023-03-25
        • 2015-04-06
        相关资源
        最近更新 更多