Maria Gonzalez Posted May 9, 2024 Share Posted May 9, 2024 (edited) Bonjour, Je développe un module prestashop 8 pour afficher une étiquette sur un produit, mais uniquement si le produit a la caractéristique "HOT" égale à 1. Voici mon code : public function hookDisplayProductPriceBlock($params) { $product = $params['product']; if ($product->HOT == 1) { return $this->display(__FILE__, 'views/templates/hook/hotproduct.tpl'); } } public function hookDisplayProductPriceBlock($params) { $product = $params['product']; if ($product->HOT == 1) { return $this->display(__FILE__, 'views/templates/hook/hotproduct.tpl'); } } Il ne montre rien sur un produit avec l'attribut HOT à 1. Si je supprime la condition, il s'affiche ! J'ai également essayé cela public function hookDisplayProductPriceBlock($params) { $product = $params['product']; // Obtener las características del producto $features = $product->getFrontFeatures($this->context->language->id); // Buscar la característica "HOT" entre las características del producto $hotValue = null; foreach ($features as $feature) { if ($feature['name'] === 'HOT') { return $this->display(__FILE__, 'views/templates/hook/hotproduct.tpl'); break; } } //if ($product->HOT == 1) { // return $this->display(__FILE__, 'views/templates/hook/hotproduct.tpl'); // } } Mais cela me donne cette erreur : PHP Fatal error: Uncaught Error: Call to undefined method PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductLazyArray::getFrontFeatures() Avez-vous une idée ? Edited May 9, 2024 by Maria Gonzalez (see edit history) Link to comment Share on other sites More sharing options...
Knowband Plugins Posted May 9, 2024 Share Posted May 9, 2024 Salut, Il semble qu'il puisse y avoir un problème avec les substitutions. Veuillez essayer d'utiliser la fonction getFeaturesStatic de la classe de produit : $product = $params['product']; $productFeatures = MyModule::getFeaturesStatic($product->id); // Recherche de la caractéristique "HOT" parmi les caractéristiques du produit $hotValue = null; foreach ($productFeatures as $feature) { // En supposant que 'HOT' est le nom de la caractéristique que vous recherchez if ($feature['custom'] === 'HOT') { return $this->display(__FILE__, 'views/templates/hook/hotproduct.tpl'); break; } } Espérons que cela vous aidera. Link to comment Share on other sites More sharing options...
Maria Gonzalez Posted May 9, 2024 Author Share Posted May 9, 2024 7 hours ago, Knowband Plugins said: Salut, Il semble qu'il puisse y avoir un problème avec les substitutions. Veuillez essayer d'utiliser la fonction getFeaturesStatic de la classe de produit : $product = $params['product']; $productFeatures = MyModule::getFeaturesStatic($product->id); // Recherche de la caractéristique "HOT" parmi les caractéristiques du produit $hotValue = null; foreach ($productFeatures as $feature) { // En supposant que 'HOT' est le nom de la caractéristique que vous recherchez if ($feature['custom'] === 'HOT') { return $this->display(__FILE__, 'views/templates/hook/hotproduct.tpl'); break; } } Espérons que cela vous aidera. Bonjour, J'ai eu cet erreur : PHP message: PHP Fatal error: Uncaught Error: Call to undefined method HotProduct::getFeaturesStatic() in 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