2011-05-17 60 views
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']; 
    } 
} 

}

+0

你'foreach'循環之前,'的var_dump($功能)',看看哪些對象的數組實際上包含。好像它沒有你期望的那樣。另外,'$ UnitsPerBox'開始爲「100」,並且您在循環中使用'。='運算符來保持附加「200」。你可能只想要'='。 – 2011-05-18 12:51:43

+0

謝謝。數組內部有更多的數組,這是我試圖獲得的那些數組。 – 2011-05-18 13:47:52

回答

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'); 
    } 
} 
+0

嗨,萬分感謝,這似乎進入功能數組內,但沒有得到任何值。我編輯了我的問題以顯示正在發生的事情,如果您有任何想法,聽到他們會很高興,謝謝。 – 2011-05-18 10:41:59

1

這看起來像Smarty模板代碼。在這種情況下,你要尋找的功能是htmlentities()

foreach($features as $feature) 
{ 
    if ($feature->name == "Units per box") 
    { 
    $UnitsPerBox = htmlentities($feature->value, ENT_QUOTES, 'UTF-8'); 
    } 
}