proconcept Posted January 14, 2019 Share Posted January 14, 2019 Hello everyone, I am trying to display a list of subcategories in product.tpl (prestashop 1.7) but the function getProductCategoriesFull returns all categories any ideas on how to filter the depth of subcategories to display ?? For my case I want to display only 3rd level categories in that list. Thanks in advance ! <label class="label">{l s='Compatible Printer Models :' d='Shop.Theme.Catalog'} </label> <ul class="productcats"> {foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat name=cats} <li class="billakos"><a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name}</a></li> {/foreach} Link to comment Share on other sites More sharing options...
proconcept Posted January 25, 2019 Author Share Posted January 25, 2019 just modify the geProductCategoriesFull in prestashop installation > controllers> Product.php to public static function getProductCategoriesFull($id_product = '', $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 cl.`id_lang` = '.(int)$id_lang.' AND `level_depth` > 3 ORDER BY `level_depth` '.ASC ); foreach ($row as $val) { $ret[$val['id_category']] = $val; } return $ret; } changing the value from AND `level_depth` > 3 *your filtering to whatever level you want to display ! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now