Jump to content

Display categories to which product belongs in product DETAIL page


Belinda999

Recommended Posts

Hi,

If you need display all categories associate with product in product detail, i can help you. Im inspired here

http://www.prestashop.com/forums/topic/122213-solved-display-categories-to-which-product-belongs-in-product-listing-page/ reply number #8 and attach the result below

 

classes/Product.php

1. step (for me it's row 234)

 

public function __construct($id_product = NULL, $full = false, $id_lang = NULL) // MOI naplneni $product pro product.tpl
{
global $cart;

parent::__construct($id_product, $id_lang);
if ($full AND $this->id)
{
$this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)
$this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer); //volani funkce pro ziskani jmena
$this->supplier_name = Supplier::getNameById((int)$this->id_supplier);
$this->moi_2 = Supplier::getNameById((int)$this->id_supplier); // MOI testovaci promena
$this->moi_categories_names = Product::Moicat($id_product); // HERE IS VARIABLE FOR TPL
self::$_tax_rules_group[$this->id] = $this->id_tax_rules_group;
if (is_object($cart) AND $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != NULL)
$this->tax_rate = Tax::getProductTaxRate($this->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
else
$this->tax_rate = Tax::getProductTaxRate($this->id, NULL);
$this->new = $this->isNew();
$this->price = Product::getPriceStatic((int)($this->id), false, NULL, 6, NULL, false, true, 1, false, NULL, NULL, NULL, $this->specificPrice);
$this->unit_price = ($this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0);
if ($this->id)
$this->tags = Tag::getProductTags((int)$this->id);
}

if ($this->id_category_default)
$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
}

 

 

 

classes/Product.php

2. adding function (for me it's end of file, before last } )

 

public function Moicat($id_product)
{
// MOI funkce pro zobrazení jména kategorii
$categories_ids = Product::getProductCategories($id_product); /*nejdriv se zjistují ID (jedno nebo vice)
category pres
funkci getProductCategorie pro produkt indetifikovany pres id_product */
$categories_names = array(); //vytvori se pole nazvy kateg.
foreach ($categories_ids AS $id)
// kazde policko z $categories_ids se ulozi do $ID
{$category = new Category($id); // docasna promena se $category(objekt) se naplni třídou proměných Category(ID)
$categories_names[] = $category->getName();// pro policko pole $categories_names se ziska jmeno (funkci tridy getName()) kategorie pres jeji ID z $category
}// A znova ;konec foreach

return $categories_names; //definice promene pro smartyho
}

 

Display in product.tpl

<!-- Display categories -->
{foreach from=$product->moi_categories_names item=moi_category_name}
{$moi_category_name|escape:'htmlall':'UTF-8'}
{/foreach}

 

 

Please,comments, try it and reply.

  • Like 2
Link to comment
Share on other sites

  • 2 months later...
  • 4 weeks later...
  • 1 month later...
  • 2 months later...
  • 2 months later...
  • 1 month later...
  • 2 months later...

I can't make it work - I'm uploading the module, but it's nowhere to be found under Modules :( I'm using PS 1.4.4.1 - is this the problem?

 

Thanks for your help!

 

It's called Product categories, you should find it under Modules > Front Office functionnalities

Haven't tested on PS 1.4.4.1, but it should work

Link to comment
Share on other sites

It's called Product categories, you should find it under Modules > Front Office functionnalities

Haven't tested on PS 1.4.4.1, but it should work

 

Unfortunately it's not there :) The folder is on my server, but the module does not appear on my PS dashboard so I could activate it... Editing the product.php gives me just a fatal error here: $this->moi_2 =Supplier::getNameById((int)$this->id_supplier);

 

Is there anything I could do, any advice will be much appreciated :)

Edited by Zmey05 (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...