You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PrestaShop 1.6自定义邮件模板缺失订单商品详情问题求助

Hey there, let's figure out why your custom order email is missing product details in PrestaShop 1.6. I've tackled this exact issue before, so here's a step-by-step fix tailored to your setup:

Fixing Missing Product Details in Custom PrestaShop 1.6 Order Emails

Step 1: Correct the sendEmail() Method in Your Overridden OrderHistory.php

The root issue is almost certainly that your rewritten sendEmail() method isn't passing order product data to the template. The default PrestaShop method handles this, but if you overwrote it without preserving this logic, the template won't receive the product array.

Update your override/classes/order/OrderHistory.php file's sendEmail() method like this:

public function sendEmail($order, $template_vars = array(), $id_lang = null, $force = false)
{
    // Set default language if not provided
    if (!$id_lang) {
        $id_lang = $order->id_lang;
    }

    // Fetch full order product data
    $products = $order->getProducts();
    
    // Optional: Format prices to match store currency settings
    foreach ($products as &$product) {
        $product['formatted_price'] = Tools::displayPrice($product['price'], $order->id_currency);
        $product['formatted_total'] = Tools::displayPrice($product['total'], $order->id_currency);
    }

    // Add products and critical order data to template variables
    $template_vars['products'] = $products;
    $template_vars['order'] = $order;
    $template_vars['currency'] = new Currency($order->id_currency);
    $template_vars['customer'] = new Customer($order->id_customer);

    // Call the parent method to handle the rest of the email sending logic
    return parent::sendEmail($order, $template_vars, $id_lang, $force);
}

Note: If you completely replaced the parent method instead of extending it, make sure you pass the $template_vars array directly into the Mail::Send() call within your custom logic.

Step 2: Update Your Custom Email Templates

Now you need to display the products array in both your HTML and plain-text templates.

HTML Template (your_custom_order_conf.tpl)

Add this table to render product details:

<table cellpadding="0" cellspacing="0" width="100%" style="margin-top: 20px;">
    <thead>
        <tr>
            <th style="padding: 10px; text-align: left; border-bottom: 1px solid #ddd;">{l s='Product'}</th>
            <th style="padding: 10px; text-align: center; border-bottom: 1px solid #ddd;">{l s='Quantity'}</th>
            <th style="padding: 10px; text-align: right; border-bottom: 1px solid #ddd;">{l s='Unit Price'}</th>
            <th style="padding: 10px; text-align: right; border-bottom: 1px solid #ddd;">{l s='Total'}</th>
        </tr>
    </thead>
    <tbody>
        {foreach from=$products item=product}
        <tr>
            <td style="padding: 10px; border-top: 1px solid #eee;">
                {$product.name}
                {if $product.attributes}
                    <br><small style="color: #666;">{$product.attributes}</small>
                {/if}
            </td>
            <td style="padding: 10px; text-align: center; border-top: 1px solid #eee;">{$product.product_quantity}</td>
            <td style="padding: 10px; text-align: right; border-top: 1px solid #eee;">{$product.formatted_price}</td>
            <td style="padding: 10px; text-align: right; border-top: 1px solid #eee;">{$product.formatted_total}</td>
        </tr>
        {/foreach}
    </tbody>
</table>

Plain-Text Template (your_custom_order_conf.txt)

Add this section to show products in the text version:

{l s='Order Products:'}
{foreach from=$products item=product}
- {$product.name} {if $product.attributes}({$product.attributes}){/if}: {$product.product_quantity} x {$product.formatted_price} = {$product.formatted_total}
{/foreach}

Step 3: Clear Cache and Test

PrestaShop's Smarty cache can prevent changes from showing up immediately:

  • Delete all files in cache/smarty/compile and cache/smarty/cache
  • Verify your OrderHistory.php override is correctly placed in override/classes/order/
  • Switch an order to your custom status and check the sent email

Quick Troubleshooting Tips

  • If products still don't show up, add var_dump($products); die; in your sendEmail() method to confirm the product array is being fetched correctly.
  • Double-check variable names in your templates (e.g., make sure you're using $products not $product in the foreach loop).
  • Ensure you didn't accidentally remove any critical order data from $template_vars that the template relies on.

内容的提问来源于stack exchange,提问作者Agnes Tom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:09:24