在 Prestashop 1.7 中显示作者类别中的作者姓名

Showing author name from Author category in Prestashop 1.7

我正在使用 prestashop 创建在线书店。我在根级别创建了一个类别“作者”,并将作者姓名添加为该类别的子类别。我在 classes/product.php

中创建了以下函数
public static function getProductCategoriesParent($id_product = '', $id_parent = '', $id_lang = null)
{
    if (!$id_lang)
        $id_lang = Context::getContext()->language->id;

        $ret = array();
        $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
            SELECT cp.`id_category`, cl.`name`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'category_product` cp
            LEFT JOIN `'._DB_PREFIX_.'category` c ON (c.id_category = cp.id_category)
            LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cp.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').')
            '.Shop::addSqlAssociation('category', 'c').'
            WHERE cp.`id_product` = '.(int)$id_product.' AND c.`id_parent` = '.(int)$id_parent.' AND cl.`id_lang` = '.(int)$id_lang //<-- bug was in this line - originally there's cl.'id_parent'
        );

        foreach ($row as $val)
            $ret[$val['id_category']] = $val;

        return $ret;
    } 

并在 product.tpl 模板文件中添加以下代码,

<ul>
    {foreach from=Product::getProductCategoriesParent(Tools::getValue('id_product'),[52]) item=cat}
        <li><a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name}</a></li>
    {/foreach}
</ul>

52 是我的类别 ID

但是从性能页面清除缓存后的事件,作者姓名没有出现。我尝试在 $product 对象上使用 var_dump() 函数,但我没有发现该对象有帮助。

任何帮助将不胜感激

它适用于

{foreach from=Product::getProductCategoriesParent(Tools::getValue('id_product'), 52) item=cat}
             <a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name|escape:'htmlall'|nl2br nofilter}</a>
{/foreach}