我想在我的 prestashop 确认邮件中发送“每箱单位”自定义功能。
这是我想做的一个例子
$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');
}
}
我得到这个输出:“100200200200200200”
任何帮助都会很棒,谢谢。
谢谢,安德鲁
编辑:解决方案
终于搞定了,谢谢帮助
$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'];
}
}
}