{"id":511,"date":"2018-08-21T05:47:11","date_gmt":"2018-08-21T05:47:11","guid":{"rendered":"http:\/\/angelwings.net\/blog\/?p=511"},"modified":"2018-08-21T05:47:11","modified_gmt":"2018-08-21T05:47:11","slug":"prestashop-1-6-breadcrumb-to-display-the-category-that-product-is-currently-in-not-its-default-category","status":"publish","type":"post","link":"https:\/\/angelwings.net\/blog\/prestashop-1-6-breadcrumb-to-display-the-category-that-product-is-currently-in-not-its-default-category\/","title":{"rendered":"Prestashop 1.6: Breadcrumb to display the category that product is currently in (not its default category)"},"content":{"rendered":"<p>Update 20190608: Due to SEO concern, the friendly url of product is configured to not show subcategories, i.e. domain.com\/product-name-1234.html so the following solution does not work as it uses the subcategories in the friendly url as reference<\/p>\n<p>Source: https:\/\/www.prestashop.com\/forums\/topic\/167513-how-to-show-the-full-breadcrumb-to-the-default-category-on-every-product-page\/?do=findComment&amp;comment=2684341<\/p>\n<p><em>Function\u00a0 assignCategory(), preferably in override\/controllers\/front\/ProductController.php<\/em><br \/>\n<code><br \/>\nprotected function assignCategory()<br \/>\n{<br \/>\n\/\/ Assign category to the template<br \/>\nif ($this-&gt;category !== false &amp;&amp; Validate::isLoadedObject($this-&gt;category) &amp;&amp; $this-&gt;category-&gt;inShop() &amp;&amp; $this-&gt;category-&gt;isAssociatedToShop()) {<br \/>\n$path = Tools::getPath($this-&gt;category-&gt;id, $this-&gt;product-&gt;name, true);<br \/>\n$all_product_subs = Product::getProductCategoriesFull($this-&gt;product-&gt;id, $this-&gt;context-&gt;language-&gt;id);<\/code><\/p>\n<p>if(isset($all_product_subs) &amp;&amp; count($all_product_subs)&gt;0)<br \/>\n{<br \/>\nforeach($all_product_subs as $subcat)<br \/>\n$all_product_subs_path = array(); \/\/reset array, only last one is used<br \/>\n$all_product_subs_path[] = Tools::getPath($subcat[&#8216;id_category&#8217;], &#8221;, true);<br \/>\n}<\/p>\n<p>} elseif (Category::inShopStatic($this-&gt;product-&gt;id_category_default, $this-&gt;context-&gt;shop)) {<br \/>\n$this-&gt;category = new Category((int)$this-&gt;product-&gt;id_category_default, (int)$this-&gt;context-&gt;language-&gt;id);<br \/>\nif (Validate::isLoadedObject($this-&gt;category) &amp;&amp; $this-&gt;category-&gt;active &amp;&amp; $this-&gt;category-&gt;isAssociatedToShop()) {<br \/>\n$path = Tools::getPath((int)$this-&gt;product-&gt;id_category_default, $this-&gt;product-&gt;name);<br \/>\n}<br \/>\n}<br \/>\nif (!isset($path) || !$path) {<br \/>\n$path = Tools::getPath((int)$this-&gt;context-&gt;shop-&gt;id_category, $this-&gt;product-&gt;name);<br \/>\n}<\/p>\n<p>if (Validate::isLoadedObject($this-&gt;category)) {<\/p>\n<p>\/\/ various assignements before Hook::exec<br \/>\n$this-&gt;context-&gt;smarty-&gt;assign(array(<br \/>\n&#8216;path&#8217; =&gt; Tools::getPath($this-&gt;category-&gt;id, &#8221;, true),<br \/>\n\/\/THIS CONTAINS ALL PRODUCT SUBCATEGORIES PATH<br \/>\n&#8216;all_product_subs&#8217;=&gt;$all_product_subs_path,<br \/>\n&#8216;category&#8217; =&gt; $this-&gt;category,<br \/>\n&#8216;subCategories&#8217; =&gt; $this-&gt;category-&gt;getSubCategories($this-&gt;context-&gt;language-&gt;id, true),<br \/>\n&#8216;id_category_current&#8217; =&gt; (int)$this-&gt;category-&gt;id,<br \/>\n&#8216;id_category_parent&#8217; =&gt; (int)$this-&gt;category-&gt;id_parent,<br \/>\n&#8216;return_category_name&#8217; =&gt; Tools::safeOutput($this-&gt;category-&gt;name)<br \/>\n));<\/p>\n<p>}<br \/>\n$this-&gt;context-&gt;smarty-&gt;assign(array(&#8216;HOOK_PRODUCT_FOOTER&#8217; =&gt; Hook::exec(&#8216;displayFooterProduct&#8217;, array(&#8216;product&#8217; =&gt; $this-&gt;product, &#8216;category&#8217; =&gt; $this-&gt;category))));<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update 20190608: Due to SEO concern, the friendly url of product is configured to not show subcategories, i.e. domain.com\/product-name-1234.html so the following solution does not work as it uses the subcategories in the friendly url as reference Source: https:\/\/www.prestashop.com\/forums\/topic\/167513-how-to-show-the-full-breadcrumb-to-the-default-category-on-every-product-page\/?do=findComment&amp;comment=2684341 Function\u00a0 assignCategory(), preferably in override\/controllers\/front\/ProductController.php protected function assignCategory() { \/\/ Assign category to the template if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[44,105],"class_list":["post-511","post","type-post","status-publish","format-standard","hentry","category-ecommerce","tag-breadcrumb","tag-prestashop-1-6"],"_links":{"self":[{"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":0,"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"wp:attachment":[{"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/angelwings.net\/blog\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}