2017-03-03 4 views
1

私は数年前に開発されたPrestashopモジュールを持っています。モジュールは、選択されたカテゴリに基づいて新しい製品を表示します。私は最近、店舗の言語設定が複数ある場合(例:en、fr)、英語とフランス語でカテゴリ名を編集することを発見しました。モジュールはアクティブなショップ言語に基づいて名前を表示するのではなく、フロントエンドに両方の名前を表示します。Prestashop SQLアクティブな言語のみのカテゴリ名を表示するクエリ

私は、以下の編集した内部のコードがカテゴリリストを取得blocknewproduct.php考える

public function hookdisplayHome($params) 
{ 
    $list_id_category= Tools::jsonDecode(Configuration::get('PS_NB_NEW_PRODUCT_CATEGORY')); 
    $resuilt_category=array(); 
    if($list_id_category) 
    { 
     $sql="select distinct id_category,name from "._DB_PREFIX_."category_lang where id_category in (".implode(',',$list_id_category).")"; 
     $categories=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); 
    } 
    if (!$this->isCached('blocknewproducts_home.tpl', $this->getCacheId('blocknewproducts-home'))) 
     BlockNewProducts1::$cache_new_products = $this->getNewProducts(); 
    { 
     $this->smarty->assign(array(
      'new_products' => BlockNewProducts1::$cache_new_products, 
      'categories' =>$categories, 
      'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 
      'homeSize' => Image::getSize(ImageType::getFormatedName('home')) 
     )); 
    } 

    if (BlockNewProducts1::$cache_new_products === false) 
     return false; 
    $this->pagination(count($this->getAllNewProducts($this->context->language->id))); // by ats_edited 

    return $this->display(__FILE__, 'blocknewproducts_home.tpl', $this->getCacheId('blocknewproducts-home')); 
} 

誰でもへのアクティブな言語の唯一のカテゴリ名を取得するために編集する必要があり、このコードの何行お勧めできます表示されます。

blocknewproducts_home.tplファイルでは、このコードを使用してリストを表示します。

<ul class="list-category-new-product plists"> 
        <li class="plist {if !isset($id_category_select) || !$id_category_select}active{/if}"><a href="#" data-id="0" title="{l s='All' mod='blocknewproducts1'}">{l s='All' mod='blocknewproducts1'}</a></li> 
        {foreach from=$categories item='category'} 
         <li class="plist {if $category.id_category==$id_category_select}active{/if}"><a href="#" data-id="{$category.id_category}" title="{$category.name}">{$category.name}</a></li> 
        {/foreach} 
       </ul> 

申し訳ありません私はプログラマーではなく、ウェブデザイナーなので、私は明確な支援が必要です。

答えて

0

変更$のSQLへ:私はそれをしたいと

$sql="select distinct id_category,name from "._DB_PREFIX_."category_lang where id_category in (".implode(',',$list_id_category).") and id_lang = ".(int) $this->context->language->id; 
+0

は、これは完全に働きました。ありがとう! – atsngr

関連する問題