pdriss Posted May 30, 2012 Share Posted May 30, 2012 (edited) Bonjour, Après 2 jours de recherche, je n'est pas trouver de solution, je viens donc demander votre aide. Mon problème: Dans les 2 modules cité en titre je n'arrive pas a gérer l'affichage des produits selon le groupe. puisque $category = new Category(1, Configuration::get('PS_LANG_DEFAULT')); correspond à la catégorie accueil dans laquelle se trouve mes sous-catégorie. En effet comment faire prendre en compte l'ID du groupe selon les sous-catégories ? je précise que j'ai dupliquer chaque catégorie et chaque produits pour que celle-ci ne soit accessible qu'a un groupe donné (ID 1 groupe par défaut et ID 2 groupe "Pro") l'affichage fonctionne parfaitement pour tout le reste. Merci de votre aide, @+ pdriss Edited June 7, 2012 by pdriss (see edit history) Link to comment Share on other sites More sharing options...
pdriss Posted June 4, 2012 Author Share Posted June 4, 2012 un petit UP... Link to comment Share on other sites More sharing options...
pdriss Posted June 7, 2012 Author Share Posted June 7, 2012 (edited) re salut, bon, j'ai dupliquer la fonction getNewProducts dans classes/Products.php que j'ai renommer en gethomefeaturedProducts en supprimant aux passage toutes les limitation de temps ce qui donne: public static function gethomefeaturedProducts($id_lang, $pageNumber = 0, $nbProducts = 10, $count = false, $orderBy = NULL, $orderWay = NULL) { if ($pageNumber < 0) $pageNumber = 0; if ($nbProducts < 1) $nbProducts = 10; if (empty($orderBy) || $orderBy == 'position') $orderBy = 'date_add'; if (empty($orderWay)) $orderWay = 'DESC'; if ($orderBy == 'id_product' OR $orderBy == 'price' OR $orderBy == 'date_add') $orderByPrefix = 'p'; elseif ($orderBy == 'name') $orderByPrefix = 'pl'; if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)) die(Tools::displayError()); $groups = FrontController::getCurrentCustomerGroups(); $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); if ($count) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(`id_product`) AS nb FROM `'._DB_PREFIX_.'product` p WHERE `active` = 1 AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` '.$sqlGroups.' )'); return (int)($result['nb']); } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name,(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice, pa.id_product_attribute FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)($id_lang).') LEFT OUTER JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND `default_on` = 1) LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) WHERE p.`active` = 1 AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` '.$sqlGroups.' ) ORDER BY '.(isset($orderByPrefix) ? pSQL($orderByPrefix).'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).' LIMIT '.(int)($pageNumber * $nbProducts).', '.(int)($nbProducts)); if ($orderBy == 'price') Tools::orderbyPrice($result, $orderWay); if (!$result) return false; $productsIds = array(); foreach ($result as $row) $productsIds[] = $row['id_product']; // Thus you can avoid one query per product, because there will be only one query for all the products of the cart Product::cacheFrontFeatures($productsIds, $id_lang); return Product::getProductsProperties((int)$id_lang, $result); } Et dans homefeatured.php j'ai remplacer function hookHome($params) { global $smarty, $cookie; $id_group = $cookie->id_customer ? (int)(Customer::getDefaultGroupId((int)($cookie->id_customer))) : _PS_DEFAULT_CUSTOMER_GROUP_; $category = new Category(1, Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); $products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10)); $smarty->assign(array( 'products' => $products, 'group' => $id_group, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'))); return $this->display(__FILE__, 'homefeatured.tpl'); } Par function hookHome($params) { global $smarty, $cookie; $id_group = $cookie->id_customer ? (int)(Customer::getDefaultGroupId((int)($cookie->id_customer))) : _PS_DEFAULT_CUSTOMER_GROUP_; $products = Product::getHomeFeaturedProducts((int)($params['cookie']->id_lang), 0, (int)(Configuration::get('HOME_FEATURED_NBR'))); $smarty->assign(array( 'products' => $products, 'group' => $id_group, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'homeSize' => Image::getSize('home'))); return $this->display(__FILE__, 'homefeatured.tpl'); } Vous remarquerez que j'ai ajouter la variable $id_group pour voir quel groupe s'affiche dans mon fichier .tpl, et c'est la ou ca bug, Si je me connecte avec un client par defaut c'est ok seul le produit du groupe 1 (celui par defaut) s'affiche. Si je me connecte avec un client Pro (groupe 2) les deux produits celui du groupe 1 et celui du groupe 2 s'affiche, je precise que le client du groupe 2 fait uniquement parti de ce groupe. Quelqu'un à une idée ? je suis sous PrestaShop™ 1.4.8.2 C'est incroyable que les modules fournis par defaut ne prenne pas en compte les groupes, alors que c'est parfaitement gerer pour tout le reste. Merci de votre aide, @+ pdriss Edited June 7, 2012 by pdriss (see edit history) 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