Php 发送产品';订单确认电子邮件中的自定义功能
我想在prestashop中发送确认邮件中的“每盒单位”自定义功能 下面是一个例子,如果我想做什么Php 发送产品';订单确认电子邮件中的自定义功能,php,arrays,smarty,prestashop,Php,Arrays,Smarty,Prestashop,我想在prestashop中发送确认邮件中的“每盒单位”自定义功能 下面是一个例子,如果我想做什么 $myprod = new Product($product['id_product']); $features = $myprod->getFrontFeatures(1)); foreach(from=$features item=feature) { if ($feature.name == "Units per box") { $UnitsPerBox = $fe
$myprod = new Product($product['id_product']);
$features = $myprod->getFrontFeatures(1));
foreach(from=$features item=feature)
{
if ($feature.name == "Units per box")
{
$UnitsPerBox = $feature.value|escape:'htmlall':'UTF-8';
}
}
但是,我需要在php文件(PaymentModule.php
)而不是tpl文件中执行此操作,这样代码就无法工作。
如果有人能为我指出如何用php实现这一目标的正确方向,我将不胜感激
编辑:
我使用了提供的示例代码,该代码似乎位于数组内部,但不返回任何值
当我运行这样的测试代码时
$myprod = new Product($product['id_product']);
$features = $myprod->getFrontFeatures(1);
$UnitsPerBox .= '100';
foreach ($features as $feature)
{
$UnitsPerBox .= '200';
if ($feature->name == 'Units Per Box')
{
$UnitsPerBox .= htmlentities($feature->value, 'ENT_QUOTES', 'UTF-8');
$UnitsPerBox .= $feature->name;
}
else
{
$UnitsPerBox .= $feature->name;
$UnitsPerBox .= htmlentities($feature->name, 'ENT_QUOTES', 'UTF-8');
$UnitsPerBox .= htmlentities($feature->value, 'ENT_QUOTES', 'UTF-8');
}
}
我得到这个输出:“100200200200”
任何帮助都会很好,谢谢
谢谢,
安德鲁
编辑:解决方案
最后终于成功了,谢谢你的帮助
$myprod = new Product($product['id_product']);
$features = $myprod->getFrontFeatures(1);
foreach ($features as $feature)
{
foreach ($feature as $key => $value)
{
if($value == "Units per box")
{
$UnitsPerBox = $feature['value'];
}
}
}这看起来像Smarty模板代码。在这种情况下,您要查找的函数是
htmlentities()
:
我已经修改了我的文件
classes/PaymentModule.php
我可以打印产品的长短描述,但我无法将产品的功能放在订单确认邮件模板上,我想出了一个使用此页面的解决方案,还有这个,使用最后一个解决方案,我只能打印订单确认的ID
我在第353行周围添加了以下内容
$lesfeatures = Product::getFrontFeaturesStatic((int)$id_lang, `$product['id_product']);`
foreach ($lesfeatures as $key => $lafeature) {
$machin .= print_r($lafeature);
$machin .= $lafeature['id_feature'].'name:'.$lafeature['name'].'value:'.$lafeature['value'].'<br>';}
$lesfeatures=Product::getFrontFeaturesStatic((int)$id\u lang,`$Product['id\u Product'])`
foreach($lesfeatures as$key=>$lafeature){
$machin.=打印($lafeature);
$machin.=$lafeature['id_feature'].'name:'.$lafeature['name'].'value:'.$lafeature['value'].
';}
然后在第400行附近进行以下操作
。$product['name'](isset($product['attributes'])?-。$product['attributes']:''。。$machin.
'
那时我才拿到订单ID
这是我目前在第400行的工作代码,用于打印说明
<strong>
Cantidad de Piezas: '.$product['quantity'].'
<br/>
'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'
<br/>Descripci贸n: '.$product['description_short'].'
</strong>
Cantidad de Piezas:“.$产品[‘数量’]”
“.$product['name'](isset($product['attributes'])?”-“.$product['attributes']:”。”
贸n:“.$product['description_short']”
您好,非常感谢,这似乎包含在功能阵列中,但没有得到任何值。我编辑了我的问题,以展示正在发生的事情,如果您有任何想法,那么很高兴听到这些想法,谢谢。在您的foreach
循环之前,var\u dump($features)
查看数组实际包含的对象。似乎它没有你所期望的那样。另外,$UnitsPerBox
以“100”开头,您可以在循环中使用=
操作符来继续追加“200”。您可能只是想要=
。谢谢。阵列中有更多的阵列,我正试图获取这些阵列。
$lesfeatures = Product::getFrontFeaturesStatic((int)$id_lang, `$product['id_product']);`
foreach ($lesfeatures as $key => $lafeature) {
$machin .= print_r($lafeature);
$machin .= $lafeature['id_feature'].'name:'.$lafeature['name'].'value:'.$lafeature['value'].'<br>';}
<strong>
Cantidad de Piezas: '.$product['quantity'].'
<br/>
'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'
<br/>Descripci贸n: '.$product['description_short'].'
</strong>