2016-09-08 70 views
0

我重寫了一個控制器文件(CartController)...並且我獲得了產品條件(新)並且我將成爲法語站點的「Nouveau」。我使用下面的代碼,但它不起作用。我該如何解決這個問題?如何翻譯控制器文件中的文本Prestashop

在/override/controllers/front/CartController.php

[...] 
$list_product = $cart_current->getProducts(); 
foreach ($list_product as $index => $product){ 
    $product_current = new ProductCore($product['id_product'],true); 
    $result['label'] = $this->l($product_current->condition); /* Translation? */ 
} 
[...] 

回答

1

首先,我會建議,以解決您這樣的代碼:

[...] 
$list_product = $cart_current->getProducts(); 
foreach ($list_product as $index => $product){ 
    $product_current = new Product($product['id_product'],true); // Product not ProductCore 
    $result['label'] = $product_current->condition; // Translation not here in the 'controller' but we make in the 'view' 
} 
[...] 

然後在 '視圖'(購物車.tpl/product.tpl):

[...] 
/* 
You have to comment this translations to avoid displaying. This is a workaround used also for the months. 
{l s='New'} // {l s='New' mod='mymodule'} if you are in your module tpl 
{l s='Used'} // Like above 
*/ 
{l s='%s' sprintf=[$result['label']]} 
[...] 
+0

在控制器文件中有沒有其他方法可以做到這一點? –

+0

你必須使用'Translate'類,但我不建議這麼做......更正確的是,將'邏輯'與'視圖'分開......因爲你有一個'變量'字符串要翻譯,所以你必須首先翻譯所有可能的值。 – sarcom

+0

非常感謝! –

0

It's更好的做法override類/ Cart.php,功能的getProducts 和添加查詢

, p.`condition` 
0

你可以在任何你的模塊翻譯

的添加翻譯文本爲「新建」後嘗試使用下面的翻譯:: getModuleTranslation()

代替

$ this-> l()