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:
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_varsarray directly into theMail::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/compileandcache/smarty/cache - Verify your
OrderHistory.phpoverride is correctly placed inoverride/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 yoursendEmail()method to confirm the product array is being fetched correctly. - Double-check variable names in your templates (e.g., make sure you're using
$productsnot$productin theforeachloop). - Ensure you didn't accidentally remove any critical order data from
$template_varsthat the template relies on.
内容的提问来源于stack exchange,提问作者Agnes Tom

