我有几年前开发的Prestashop模块。该模块根据所选类别显示新产品。我最近发现,如果我为商店设置了多种语言(例如en,fr),我会用英语和法语编辑类别名称。该模块将在前端显示两个名称,而不是仅显示基于活动商店语言的名称。
我认为编辑过的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 :(得分: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;