Jump to content

(RESOLU) Afficher le nom de la catégorie par defaut du produit


Recommended Posts

Bonjour, 

Dans ma page produit je cherche à afficher le nom de la catégorie par défaut de mon produit.

 

J'arrive à afficher la catégorie courante avec {$category->name|escape:'html':'UTF-8'} mais pour la catégorie par défaut, il n'y a pas de variable existante.

 

J'ai tenté cette solution: http://www.prestashop.com/forums/topic/123589-afficher-le-nom-de-la-category-par-defaut-dun-produit/

 

Mais ça ne marche pas pour moi car surement que cette méthode ne convient pas à la 1.6.

 

Quelqu'un connait t'il la solution?

 

Merci

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

Alors je viens de trouver donc je donne l'astuce qui marche pour la version 1.6.0.8

 

Créez un fichier Product.php dans override > classes avec à l'intérieur:

<?php

class Product extends ProductCore
{


	/**
	* Get prices drop
	*
	* @param integer $id_lang Language id
	* @param integer $pageNumber Start from (optional)
	* @param integer $nbProducts Number of products to return (optional)
	* @param boolean $count Only in order to get total number (optional)
	* @return array Prices drop
	*/
	public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
	{
		parent::__construct($id_product, $id_lang, $id_shop);
		if (!$context)
			$context = Context::getContext();

		if ($full && $this->id)
		{
			$this->isFullyLoaded = $full;
			$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); // Ajout pour afficher le nom de la catégorie par defaut du produit
			 $address = null;
			if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null)
				$address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};

			$this->tax_rate = $this->getTaxesRate(new Address($address));

			$this->new = $this->isNew();

			// keep base price
			$this->base_price = $this->price;

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

			$this->loadStockData();
		}

		if ($this->id_category_default)
			$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
	}		
	public function defCat($id_category_default)
	{
		$category = new Category($id_category_default);
		$defcat_name = $category->getName();
			return $defcat_name;
	}
}

Et ensuite utilisez cette variable sur votre fichier tpl

{$product->defcat_name}

Comme je ne maîtrise pas bien l'override, ce n'est peut-être pas très propre ou pas bien optimisé donc si quelqu'un pense faire mieux, qu'il n'hésite pas à partager.

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

Alors je viens de trouver donc je donne l'astuce qui marche pour la version 1.6.0.8

 

Créez un fichier Product.php dans override > classes avec à l'intérieur:

<?php

class Product extends ProductCore
{


	/**
	* Get prices drop
	*
	* @param integer $id_lang Language id
	* @param integer $pageNumber Start from (optional)
	* @param integer $nbProducts Number of products to return (optional)
	* @param boolean $count Only in order to get total number (optional)
	* @return array Prices drop
	*/
	public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
	{
		parent::__construct($id_product, $id_lang, $id_shop);
		if (!$context)
			$context = Context::getContext();

		if ($full && $this->id)
		{
			$this->isFullyLoaded = $full;
			$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); // Ajout pour afficher le nom de la catégorie par defaut du produit
			 $address = null;
			if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null)
				$address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};

			$this->tax_rate = $this->getTaxesRate(new Address($address));

			$this->new = $this->isNew();

			// keep base price
			$this->base_price = $this->price;

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

			$this->loadStockData();
		}

		if ($this->id_category_default)
			$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
	}		
	public function defCat($id_category_default)
	{
		$category = new Category($id_category_default);
		$defcat_name = $category->getName();
			return $defcat_name;
	}
}

Et ensuite utilisez cette variable sur votre fichier tpl

{$product->defcat_name}

Comme je ne maîtrise pas bien l'override, ce n'est peut-être pas très propre ou pas bien optimisé donc si quelqu'un pense faire mieux, qu'il n'hésite pas à partager.

Merci cela marche sur 1.606. Par contre j'aimerai changer la couleur de la police et l'insérer dans un background..A tu une idée? Merci

Link to comment
Share on other sites

Et bien pour moi par exemple: 

 

dans le tpl 

<div id="top5">
<p>{l s='in category'} {$product->defcat_name|escape:'htmlall':'UTF-8'}</p>
</div> 

dans le css

#top5 p{
    margin-top: 70px;
    padding:0;
    padding-left: 15px;
    font-size: 11px;
    line-height: 11px;}

Mais pour faire ce que vous voulez, il faut un minimum de connaissance en architecture html et css.

 

Cordialement

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

Et bien pour moi par exemple: 

 

dans le tpl 

<div id="top5">
<p>{l s='in category'} {$product->defcat_name|escape:'htmlall':'UTF-8'}</p>
</div> 

dans le css

#top5 p{
    margin-top: 70px;
    padding:0;
    padding-left: 15px;
    font-size: 11px;
    line-height: 11px;}

Mais pour faire ce que vous voulez, il faut un minimum de connaissance en architecture html et css.

 

Cordialement

Merci j'ai rajouté les codes et sa marche a merveille. Merci pour tout

Link to comment
Share on other sites

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...