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';
  }
}

PaymentModule.phpただし、コードが機能しないように、tpl ファイルではなくphp ファイル () 内でこれを行う必要があります。誰かが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

これは 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 に答える
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 に答える