2017-03-03 48 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