TWDesign Posted May 3, 2012 Share Posted May 3, 2012 Pretty easy. Just 3 steps. 1. In /classes/Product.php find the constructor function (starts line 294 in my PS1.4.7.0 install) add the TPL variable $this->defcat_name = Product::defCat((int)$this->id_category_default); so it looks like this: public function __construct($id_product = NULL, $full = false, $id_lang = NULL) { 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); $this->supplier_name = Supplier::getNameById((int)$this->id_supplier); $this->defcat_name = Product::defCat((int)$this->id_category_default); // HERE IS CUSTOM 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); } 2. At the very bottom of Product.php (before the closing } symbol) add this function public function defCat($id_category_default) { $category = new Category($id_category_default); $defcat_name = $category->getName(); return $defcat_name; } 3. In your product.tpl file add this where ever it needs to go. <!-- Display default category --> {$product->defcat_name|escape:'htmlall':'UTF-8'} THATS IT ! Don't forget to recompile by choosing Preferences-Performance-Force Compile in the BO. Of course steps 1 and 2 are not future proofed. The correct way to do it would be to create an override file, which you can do if you like and post about how to do it below. 1 Link to comment Share on other sites More sharing options...
gwenn Posted October 31, 2012 Share Posted October 31, 2012 Thank's a lot for your solution TWDesign. Do you have some idea to make the same, but with the Default Category in Product.tpl? Link to comment Share on other sites More sharing options...
piotrwojciechowski Posted October 29, 2013 Share Posted October 29, 2013 Dear TwDesign is there any simple solution to show category_default in product-ist.tpl not product.tpl i would like to add this variable to search results and specials also. Link to comment Share on other sites More sharing options...
Drulik Posted April 2, 2014 Share Posted April 2, 2014 Thanks, but do you have the solution for 1.5.4? 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