I have a product that belongs to two categories "rings" and "collections->waves" (category->subcategory)
I can show the default category and it link like this
<a href="{$link->getCategoryLink($product->id_category_default,$product->category)}" title="{$product->category}">{$product->category}</a>
But I can't show the (non default) associated categories anyhow. Is there any array with the associated categories in the object $product?
Because I know that all the categories are in the variable $categories (not the subcategories, it could be a problem, cause waves is a subcategory)
Thanks for everything
Look to the Product class, it has nice function:
/**
 * getProductCategories return an array of categories which this product belongs to
 *
 * @return array of categories
 */
public static function getProductCategories($id_product = '')
{
    $ret = array();
    if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
    SELECT `id_category` FROM `'._DB_PREFIX_.'category_product`
    WHERE `id_product` = '.(int)$id_product)
    )
        foreach ($row as $val)
            $ret[] = $val['id_category'];
    return $ret;
}
Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With