Jump to content

Category product page


Recommended Posts

Hi,

It depends on what you mean by category. If you mean the default one, the category id is already assigned to the product, and you should be able to acccess it with $product->id_category_default.

Then you can simply call $link->getCategoryLink with the id to get that link

Link to comment
Share on other sites

I try to explain it in English.

I want on the product page, there are links that lead back to the product categories.

 

many thanks for explanation.

Additional (and last) question: you want to display links only for default category, or for all categories to which the product belongs ?

  • Like 1
Link to comment
Share on other sites

Well in that case I suggest you use a module

 

Hook ite somewhere in the product page (perhaps product footer)

 

then, inside the module grab the product id by using Tools::getValue('id_product')

 

Now with that id, make a query and select all categories (ids, names, rewrites) from category product where id_product equals than one

 

It should work

Link to comment
Share on other sites

Hmmm I think in this case it does not significantly affect the loading of the page. Product::getProductCategoriesFull uses only one simple query with 2 joins. I think that there is nothing to worry about.

 

The difference in the charging page certainly is, but it's a matter of milliseconds :P

  • Like 1
Link to comment
Share on other sites

I think that many css files is a bad idea. One small separated css file (no matter how big it is) = new apache connection to download it to browser while browsing website.

 

In my opinion - you should put own css styles to the global.css file.

Link to comment
Share on other sites

  • 2 years later...

What method are you using to retrieve them?
If you use getCategories, you can add a 5th parameter as 'cl.name'

 public static function getCategories($id_lang = false, $active = true, $order = true, $sql_filter = '', $sql_sort = '', $sql_limit = '')

Link to comment
Share on other sites

Hello Nemo,

 

thanks for your answer. I use the "getCategoriesFull" method as seen in the post from vekia above:

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
				
        );

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

        return $ret;
    }

I think i have to insert an "ORDER BY xxx ASC" somewhere. I tried everything, but i can´t figure out WHAT to use instead of "xxx" and WHERE to insert the ORDER BY snippet. I´m really a php an sql noob :-(

Link to comment
Share on other sites

×
×
  • Create New...