Jump to content

How to show the name of the Default Category in the Product.tpl


TWDesign
 Share

Recommended Posts

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.

  • Like 1

Share this post


Link to post
Share on other sites

  • 5 months later...
  • 11 months later...
  • 5 months 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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More