【问题标题】:Prestashop SQL Query to display category names of just the active languagePrestashop SQL 查询仅显示活动语言的类别名称
【发布时间】:2017-03-03 18:22:38
【问题描述】:

我有一个几年前开发的 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>

对不起,我不是程序员,只是一名网页设计师,所以我需要明确的帮助。

【问题讨论】:

    标签: php sql smarty prestashop-1.6


    【解决方案1】:

    将 $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;
    

    【讨论】:

      猜你喜欢
      • 2021-01-02
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多