Mawan81 Posted September 16, 2010 Share Posted September 16, 2010 BonsoirCe que je veux faire peut paraitre bizarre mas j'aimerais que les produits appartenant à une certaine catégorie ne soient pas affichés dans la page promotion lorsqu'ils sont soldés...J'ai bien cherché avant de posté et la solution serait de rajouter une condition dans la classe getPriceDrop dans le fichier classes->Product.phpJ'ai rajouter la condition WHERE cp.id_category!=13Ca fonctionne pour les produits uniquement dans cette catégorie car cp renvoi à la table category_product qui liste les id_category et les id_product. Saut que j'ai des produits qui sont dans cette catégorie et dans une autre, je me retrouve donc avec un enregistrement: id_category=13 id_product=1445 et un autre id_category=17 id_product=1445 Donc forcément le produit s'affiche vu que le script prend en compte le second enregistrerment.Quelqu'un saurait comment faire pour qu'a partir du moment où un produit est dans la catégorie 13 il ne s'affiche pas dans la page promo?Merci d'avance Link to comment Share on other sites More sharing options...
Pixel carré Posted January 19, 2016 Share Posted January 19, 2016 Bonjour, Ce post date pas mal... mais je suis à la recherche d'une solution, sous 1.6 pour exclure une catégorie de l'affichage du bloc promotion. Est-ce que quelqu'un a une solution svp ? Link to comment Share on other sites More sharing options...
erouvier29 Posted January 20, 2016 Share Posted January 20, 2016 (edited) Bonjour, Dans /classes/Product.php, fonction getPricesDrop, ajoutez à la directive WHERE de la requête SQL: AND p.id_product NOT IN ( SELECT id_product FROM '._DB_PREFIX_.'category_product WHERE id_category IN('.implode(',', $excluded_categories).')) Et définissez la liste des catégories à exclure juste avant, par exemple: $excluded_categories = array(5,6,7); Mieux, vous pouvez récupérer cette liste en BDD si vous développez un moyen de l'éditer et de la stocker Cordialement NB: videz le cache, ou modifiez un produit pour que la modif soit effective. Edited January 20, 2016 by erouvier29 (see edit history) Link to comment Share on other sites More sharing options...
Pixel carré Posted January 21, 2016 Share Posted January 21, 2016 Bonjour, Merci pour cette réponse. Dans la partie "getPricesDrop" j'ai plusieurs fois un "WHERE" et je ne vois pas où et comment inclure votre fonction... J'ai : WHERE cp.`id_product` = p.`id_product`)'; WHERE product_shop.`active` = 1 AND product_shop.`show_price` = 1 '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' WHERE product_shop.`active` = 1 AND product_shop.`show_price` = 1 '.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').' Merci d'avance Link to comment Share on other sites More sharing options...
erouvier29 Posted January 21, 2016 Share Posted January 21, 2016 Ah oui, je n'avais pas vu l'option "décompte" uniquement... Vous pouvez donc modifier les 2 derniers blocs, de cette façon par exemple: WHERE product_shop.`active` = 1 AND p.id_product NOT IN ( SELECT DISTINCT id_product FROM '._DB_PREFIX_.'category_product WHERE id_category IN('.implode(',', $excluded_categories).')) AND product_shop.`show_price` = 1 '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' Et pensez bien à définir $excluded_categories avant, en début de fonction par exemple. Link to comment Share on other sites More sharing options...
Pixel carré Posted January 21, 2016 Share Posted January 21, 2016 Merci, malheureusement ça n'a pas l'air de fonctionner... enfin si je ne me suis pas trompé ! La catégorie que je souhaite exclure s'affiche toujours, en revanche sur la page "promotion" je n'ai pas de promo qui s'affiche... Link to comment Share on other sites More sharing options...
erouvier29 Posted January 21, 2016 Share Posted January 21, 2016 "La catégorie que je souhaite exclure s'affiche toujours": Avez-vous vidé le cache? "sur la page "promotion" je n'ai pas de promo qui s'affiche": Je n'ai pas moyen de tester pour l'instant, je pourrai vérifier ça plus tard. Désolé... Link to comment Share on other sites More sharing options...
Pixel carré Posted January 21, 2016 Share Posted January 21, 2016 J'ai désactivé le cache pour le moment, mais je l'ai vidé quand même Je vais continuer les essais de mon côté. Merci beaucoup. Link to comment Share on other sites More sharing options...
erouvier29 Posted January 22, 2016 Share Posted January 22, 2016 Quelques tests plus tard, je confirme que cela fonctionne sur une install 1.6.1.4 tout fraîche. Quelle version exacte de PS utilisez-vous? Pour info, ci-joint la surcharge de la méthode Product::getPricesDrop(): Product.php Link to comment Share on other sites More sharing options...
Pixel carré Posted January 22, 2016 Share Posted January 22, 2016 Bonjour et merci pour cette réponse bien matinale Je suis en 1.6.1.4 également et j'ai testé votre code, mais ma boutique ne s'affiche plus ! "Erreur serveur 500". J'ai copié votre code et j'ai remplacé la partie "Get prices drop" de mon fichier product.php. J'ai défini ma catégorie à exclure : $excluded_categories = 13; J'ai certainement oublié de modifier quelque chose... Link to comment Share on other sites More sharing options...
erouvier29 Posted January 22, 2016 Share Posted January 22, 2016 Il faut que ce soit un tableau: $excluded_categories = array(13); et ça devrait rentrer dans l'ordre! Link to comment Share on other sites More sharing options...
Pixel carré Posted January 22, 2016 Share Posted January 22, 2016 Pareil... toujours la même erreur... et je n'ai plus accès au catalogue dans le BO Link to comment Share on other sites More sharing options...
erouvier29 Posted January 22, 2016 Share Posted January 22, 2016 (edited) C'est peut-être le remplacement du code de getPricesDrop qui n'aurait pas été fait correctement. Passez en mode DEV et vérifiez l'erreur reportée. https://www.prestashop.com/forums/topic/232472-que-faire-en-cas-de-page-blanche-ou-partie-blanche-dans-le-shop/ Edited January 22, 2016 by erouvier29 (see edit history) Link to comment Share on other sites More sharing options...
Pixel carré Posted January 22, 2016 Share Posted January 22, 2016 Oui, je pense en effet qu'il y a un souci avec mon copier/coller, voilà ce que j'ai comme erreur : Parse error: syntax error, unexpected 'class' (T_CLASS), expecting function (T_FUNCTION) in C:\wamp\www\presta\classes\Product.php on line 2483 2483 étant la 1ère ligne du code ajouté. Link to comment Share on other sites More sharing options...
erouvier29 Posted January 22, 2016 Share Posted January 22, 2016 (edited) OK, compris: Si vous voulez modifier le fichier /classes/Product.php original, il ne faut pas insérer tout le contenu du fichier que j'ai posté, mais seulement la définition de la fonction, à partir de la ligne public static function getPricesDrop(..., et sans la toute dernière accolade fermante. Sinon, vous téléchargez le fichier sous /override/classes, vous supprimez le fichier /cache/class_index.php, (*) et vous rechargez vos pages FO/BO. (*) EDIT: vous videz le cache, Edited January 22, 2016 by erouvier29 (see edit history) Link to comment Share on other sites More sharing options...
Pixel carré Posted January 22, 2016 Share Posted January 22, 2016 Bon, en effet j'avais bien fait une erreur. Je n'ai plus l'erreur d'affichage, mais par contre j'ai toujours la catégorie que je souhaite exclure dans le bloc promo... J'ai testé plusieurs catégories, je vide le cache à chaque fois... mais rien ! Link to comment Share on other sites More sharing options...
erouvier29 Posted January 22, 2016 Share Posted January 22, 2016 Bouhou... 1/ A tout hasard, modifiez un produit (n'importe lequel) depuis le BO et rechargez la page d'accueil FO 2/ Je suppose que le site est en maintenance, ou bien qu'il s'agit d'un site de test: Ajoutez die($sql); juste avant $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); Rechargez FO et vérifiez que la requête affichée est correcte par rapport aux catégories que vous souhaitez exclure. Link to comment Share on other sites More sharing options...
Pixel carré Posted January 22, 2016 Share Posted January 22, 2016 J'avais déjà testé la mise à jour d'un produit, en promo ou non, mais ça ne fait rien... Pour info le site est en local, sur WAMP. J'ai ajouté "die($sql);" et en actualisant le FO j'ai ça : SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, IFNULL(product_attribute_shop.id_product_attribute, 0) id_product_attribute, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, image_shop.`id_image` id_image, il.`legend`, m.`name` AS manufacturer_name, DATEDIFF( p.`date_add`, DATE_SUB( "2016-01-22 00:00:00", INTERVAL 20 DAY ) ) > 0 AS new FROM `ps_product` p INNER JOIN ps_product_shop product_shop ON (product_shop.id_product = p.id_product AND product_shop.id_shop = 1) LEFT JOIN `ps_product_attribute_shop` product_attribute_shop ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop=1) LEFT JOIN ps_stock_available stock ON (stock.id_product = p.id_product AND stock.id_product_attribute = 0 AND stock.id_shop = 1 AND stock.id_shop_group = 0 ) LEFT JOIN `ps_product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = 1 AND pl.id_shop = 1 ) LEFT JOIN `ps_image_shop` image_shop ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop=1) LEFT JOIN `ps_image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = 1) LEFT JOIN `ps_manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) WHERE product_shop.`active` = 1 AND product_shop.`show_price` = 1 AND p.`visibility` IN ("both", "catalog") AND p.`id_product` IN (5, 7, 8, 10, 1) AND EXISTS(SELECT 1 FROM `ps_category_product` cp JOIN `ps_category_group` cg ON (cp.id_category = cg.id_category AND cg.`id_group` IN (3)) WHERE cp.`id_product` = p.`id_product`) ORDER BY product_shop.price DESC LIMIT 0, 5 Argh !!!! Link to comment Share on other sites More sharing options...
erouvier29 Posted January 22, 2016 Share Posted January 22, 2016 (edited) La/les catégorie(s) ne sont pas exclue(s)!!! Copié/collé de votre fonction getPricesDrop(), svp Edited January 22, 2016 by erouvier29 (see edit history) Link to comment Share on other sites More sharing options...
Pixel carré Posted January 22, 2016 Share Posted January 22, 2016 Et voilà : public static function getPricesDrop($id_lang, $page_number = 0, $nb_products = 10, $count = false, $order_by = null, $order_way = null, $beginning = false, $ending = false, Context $context = null) { $excluded_categories = array(12,13); //array(5,6,7); $exclude_condition = ''; if (is_array($excluded_categories)) { $exclude_condition = 'AND p.id_product NOT IN ( SELECT DISTINCT id_product FROM '._DB_PREFIX_.'category_product WHERE id_category IN('.implode(',', $excluded_categories).'))'; } if (!Validate::isBool($count)) { die(Tools::displayError()); } if (!$context) { $context = Context::getContext(); } if ($page_number < 0) { $page_number = 0; } if ($nb_products < 1) { $nb_products = 10; } if (empty($order_by) || $order_by == 'position') { $order_by = 'price'; } if (empty($order_way)) { $order_way = 'DESC'; } if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd') { $order_by_prefix = 'product_shop'; } elseif ($order_by == 'name') { $order_by_prefix = 'pl'; } if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) { die(Tools::displayError()); } $current_date = date('Y-m-d H:i:00'); $ids_product = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context); $tab_id_product = array(); foreach ($ids_product as $product) { if (is_array($product)) { $tab_id_product[] = (int)$product['id_product']; } else { $tab_id_product[] = (int)$product; } } $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) { $front = false; } $sql_groups = ''; if (Group::isFeatureActive()) { $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = ' AND EXISTS(SELECT 1 FROM `'._DB_PREFIX_.'category_product` cp JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.id_category = cg.id_category AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').') WHERE cp.`id_product` = p.`id_product`)'; } if ($count) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(DISTINCT p.`id_product`) FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' WHERE product_shop.`active` = 1 AND product_shop.`show_price` = 1 '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' '.((!$beginning && !$ending) ? 'AND p.`id_product` IN('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' '.$sql_groups); } if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; } $sql = ' SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, IFNULL(product_attribute_shop.id_product_attribute, 0) id_product_attribute, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, image_shop.`id_image` id_image, il.`legend`, m.`name` AS manufacturer_name, DATEDIFF( p.`date_add`, DATE_SUB( "'.date('Y-m-d').' 00:00:00", INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 AS new FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` product_attribute_shop ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop='.(int)$context->shop->id.') '.Product::sqlStock('p', 0, false, $context->shop).' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' ) LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) WHERE product_shop.`active` = 1 AND product_shop.`show_price` = 1 '.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').' '.((!$beginning && !$ending) ? ' AND p.`id_product` IN ('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' '.$sql_groups.' ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '.pSQL($order_way).' LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; die($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$result) { return false; } if ($order_by == 'price') { Tools::orderbyPrice($result, $order_way); } return Product::getProductsProperties($id_lang, $result); } Link to comment Share on other sites More sharing options...
erouvier29 Posted January 22, 2016 Share Posted January 22, 2016 Vous avez oublié d'insérer 2 lignes: public static function getPricesDrop($id_lang, $page_number = 0, $nb_products = 10, $count = false, $order_by = null, $order_way = null, $beginning = false, $ending = false, Context $context = null) { $excluded_categories = null; //array(5,6,7); $exclude_condition = ''; if (is_array($excluded_categories)) { $exclude_condition = 'AND p.id_product NOT IN ( SELECT DISTINCT id_product FROM '._DB_PREFIX_.'category_product WHERE id_category IN('.implode(',', $excluded_categories).'))'; } if (!Validate::isBool($count)) { die(Tools::displayError()); } if (!$context) { $context = Context::getContext(); } if ($page_number < 0) { $page_number = 0; } if ($nb_products < 1) { $nb_products = 10; } if (empty($order_by) || $order_by == 'position') { $order_by = 'price'; } if (empty($order_way)) { $order_way = 'DESC'; } if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd') { $order_by_prefix = 'product_shop'; } elseif ($order_by == 'name') { $order_by_prefix = 'pl'; } if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) { die(Tools::displayError()); } $current_date = date('Y-m-d H:i:00'); $ids_product = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context); $tab_id_product = array(); foreach ($ids_product as $product) { if (is_array($product)) { $tab_id_product[] = (int)$product['id_product']; } else { $tab_id_product[] = (int)$product; } } $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) { $front = false; } $sql_groups = ''; if (Group::isFeatureActive()) { $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = ' AND EXISTS(SELECT 1 FROM `'._DB_PREFIX_.'category_product` cp JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.id_category = cg.id_category AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').') WHERE cp.`id_product` = p.`id_product`)'; } if ($count) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(DISTINCT p.`id_product`) FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' WHERE product_shop.`active` = 1 ICI: '.$exclude_condition.' AND product_shop.`show_price` = 1 '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' '.((!$beginning && !$ending) ? 'AND p.`id_product` IN('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' '.$sql_groups); } if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; } $sql = ' SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, IFNULL(product_attribute_shop.id_product_attribute, 0) id_product_attribute, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, image_shop.`id_image` id_image, il.`legend`, m.`name` AS manufacturer_name, DATEDIFF( p.`date_add`, DATE_SUB( "'.date('Y-m-d').' 00:00:00", INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 AS new FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` product_attribute_shop ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop='.(int)$context->shop->id.') '.Product::sqlStock('p', 0, false, $context->shop).' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' ) LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) WHERE product_shop.`active` = 1 ET LA: '.$exclude_condition.' AND product_shop.`show_price` = 1 '.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').' '.((!$beginning && !$ending) ? ' AND p.`id_product` IN ('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' '.$sql_groups.' ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '.pSQL($order_way).' LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$result) { return false; } if ($order_by == 'price') { Tools::orderbyPrice($result, $order_way); } return Product::getProductsProperties($id_lang, $result); } Link to comment Share on other sites More sharing options...
erouvier29 Posted January 22, 2016 Share Posted January 22, 2016 Ouf !.. ;-) 1 Link to comment Share on other sites More sharing options...
Pixel carré Posted January 22, 2016 Share Posted January 22, 2016 Et ça fonctionne à merveille !!!!!!!! Un grand MERCI Je n'avais en fait copié que le début en effet... 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