jomcdonald Posted July 23, 2014 Share Posted July 23, 2014 (edited) 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 July 26, 2014 by jomcdonald (see edit history) Link to comment Share on other sites More sharing options...
jomcdonald Posted July 25, 2014 Author Share Posted July 25, 2014 Allez un petit up pour bien commencer le week-end. Link to comment Share on other sites More sharing options...
jomcdonald Posted July 26, 2014 Author Share Posted July 26, 2014 (edited) 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 July 26, 2014 by jomcdonald (see edit history) Link to comment Share on other sites More sharing options...
houin Posted July 27, 2014 Share Posted July 27, 2014 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 More sharing options...
jomcdonald Posted July 27, 2014 Author Share Posted July 27, 2014 Pour ça il faut jouer sur le css. Donc suivant ou tu met cette variable, tu modifie le css en fonction. Link to comment Share on other sites More sharing options...
houin Posted July 27, 2014 Share Posted July 27, 2014 Pour ça il faut jouer sur le css. Donc suivant ou tu met cette variable, tu modifie le css en fonction. Merci de ta réponse mais peut tu me donner une exemple , car la je ne trouve pas merci Link to comment Share on other sites More sharing options...
jomcdonald Posted July 27, 2014 Author Share Posted July 27, 2014 (edited) 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 July 27, 2014 by jomcdonald (see edit history) Link to comment Share on other sites More sharing options...
houin Posted July 27, 2014 Share Posted July 27, 2014 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 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