1

我想在我的 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'];
    }
}

}

4

3 回答 3

1
$myprod = new Product($product['id_product']);
$features = $myprod->getFrontFeatures(1);

foreach ($features as $feature) {
   if ($feature->name == 'Units per box') {
      $UnitsPerBox = htmlentities($feature->value, 'ENT_QUOTES', 'UTF-8');
   }
}
于 2011-05-17T13:31:41.267 回答
1

这看起来像 Smarty 模板代码。在这种情况下,您正在寻找的功能是htmlentities()

foreach($features as $feature)
{
  if ($feature->name == "Units per box")
  {
     $UnitsPerBox = htmlentities($feature->value, ENT_QUOTES, 'UTF-8');
  }
}
于 2011-05-17T13:35:24.267 回答
0

我修改了我的文件

classes/PaymentModule.php 

我可以打印产品的简短和详细描述,但我只是无法将产品的功能放在订单确认邮件模板上,我想出了一个使用这个页面和这个https://www的解决方案.prestashop.com/forums/topic/658353-15-add-products-features-in-order-confirmation-email/,使用最后一个解决方案,我只能打印订单确认的 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>';}

然后在第 400 行左右

<strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'</strong>'.$machin.'

那是我刚得到订单ID的时候

这是我目前在第 400 行打印描述的工作代码

<strong>
Cantidad de Piezas: '.$product['quantity'].'
<br/>
'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'
<br/>Descripci贸n: '.$product['description_short'].'
</strong>
于 2018-04-06T23:35:36.320 回答