LarsHolmgaard Posted November 5, 2013 Share Posted November 5, 2013 (edited) Hi, We're running an old 1.2.5.0 version of PrestaShop and I am trying to show more than only 9 products on the prices-drop.php page but I am having trouble with it. I have looked in to the classes/Product.php and prices-drop.php which contains this: <?php include(dirname(__FILE__).'/config/config.inc.php'); include(dirname(__FILE__).'/header.php'); include(dirname(__FILE__).'/product-sort.php'); $nbProducts = Product::getPricesDrop(intval($cookie->id_lang), NULL, NULL, true); //include(dirname(__FILE__).'/pagination.php'); $category = new Category(9999); $smarty->assign(array( 'products' => Product::getPricesDrop(intval($cookie->id_lang), intval($p) - 1, intval($n), false, $orderBy, $orderWay), 'nbProducts' => $nbProducts, 'category' => $category )); $smarty->display(_PS_THEME_DIR_.'prices-drop.tpl'); include(dirname(__FILE__).'/footer.php'); ?> If I echo $nbProducts out it writes 144 which then puzzles me why only 9 shows on the page. And the pagination line is deactivated as you can see. It makes no difference if I turn on the line which includes pagination.php - no page buttons appear. And no more than 9 products on sale are shown. On the rest of the site, all products show in the categories on one page and no pagination is used. Any clues on how I show all products on sale and not just 9? Any feedback would be highly appreciated. Edited November 25, 2013 by LarsHolmgaard (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted November 5, 2013 Share Posted November 5, 2013 Try to change products' => Product::getPricesDrop(intval($cookie->id_lang), intval($p) - 1, intval($n), false, $orderBy, $orderWay), into products' => Product::getPricesDrop(intval($cookie->id_lang), intval($p) - 1, intval($nbProducts), false, $orderBy, $orderWay), to show them all, or: products' => Product::getPricesDrop(intval($cookie->id_lang), intval($p) - 1, 20, false, $orderBy, $orderWay), to show 20 of them Hope this helps, pascal 1 Link to comment Share on other sites More sharing options...
LarsHolmgaard Posted November 6, 2013 Author Share Posted November 6, 2013 Oh, I am sorry - I didn't notice it was two different variables, thanks for the heads up, Pascal! :-) This is the result of having too many tasks to be done in no time. But, unfortunately the problem persists. So, now I can control the amount shown from 1-9 which I haven't tried before - I always tried with numbers larger than 9. But according to $nbProducts there are 144 and it still only shows 9, which bugs me. Any suggestions? Link to comment Share on other sites More sharing options...
PascalVG Posted November 6, 2013 Share Posted November 6, 2013 Hi Lars, Can you copy the total function getPricesDrop(...) in classes/Product.php of your version? Maybe they limit the amount or so... (Please copy the code using the <> icon, to keep it formatted) pascal 1 Link to comment Share on other sites More sharing options...
LarsHolmgaard Posted November 7, 2013 Author Share Posted November 7, 2013 Yes of course, here you go, Pascal: /** * 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 */ static public function getPricesDrop($id_lang, $pageNumber = 0, $nbProducts = 10, $count = false, $orderBy = NULL, $orderWay = NULL, $beginning = false, $ending = false) { global $link, $cookie; if (!Validate::isBool($count)) die(Tools::displayError()); if ($pageNumber < 0) $pageNumber = 0; if ($nbProducts < 1) $nbProducts = 10; if (empty($orderBy) || $orderBy == 'position') $orderBy = 'myprice'; 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()); if ($count) { $sql = ' SELECT COUNT(DISTINCT p.`id_product`) AS nb FROM `'._DB_PREFIX_.'product` p 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` '.(!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').' )'; $result = Db::getInstance()->getRow($sql); return intval($result['nb']); } $currentDate = date('Y-m-d'); $sql = ' SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, i.`id_image`, il.`legend`, t.`rate`, (p.`reduction_price` + (p.`reduction_percent` * p.`price`)) AS myprice, m.`name` AS manufacturer_name FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') 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` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = p.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) WHERE (`reduction_price` > 0 OR `reduction_percent` > 0) '.((!$beginning AND !$ending) ? 'AND (`reduction_from` = `reduction_to` OR (`reduction_from` <= \''.pSQL($currentDate).'\' AND `reduction_to` >= \''.pSQL($currentDate).'\'))' : ($beginning ? 'AND `reduction_from` <= \''.pSQL($beginning).'\'' : '').($ending ? 'AND `reduction_to` >= \''.pSQL($ending).'\'' : '')).' AND 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` '.(!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').' ) ORDER BY '.(isset($orderByPrefix) ? pSQL($orderByPrefix).'.' : '').'`'.pSQL($orderBy).'`'.' '.pSQL($orderWay).' LIMIT '.intval($pageNumber * $nbProducts).', '.intval($nbProducts); $result = Db::getInstance()->ExecuteS($sql); if($orderBy == 'price') { Tools::orderbyPrice($result,$orderWay); } if (!$result) return false; return Product::getProductsProperties($id_lang, $result); } Link to comment Share on other sites More sharing options...
PascalVG Posted November 9, 2013 Share Posted November 9, 2013 Hmmm, don't see anything that limits the amount here. Maybe try this one more time (changed the start value of the 'limit' to always 0, so no pagination here: products' => Product::getPricesDrop(intval($cookie->id_lang), 0, intval($nbProducts), false, $orderBy, $orderWay), Hope this does something... pascal 1 Link to comment Share on other sites More sharing options...
LarsHolmgaard Posted November 11, 2013 Author Share Posted November 11, 2013 Hi Pascal, Thanks for your effort. I can't find anything limiting in the function neither. I have already tried your suggestion to hardcode the beginning value but it still only shows 9. It really puzzles me: If I write out $nbProducts it says 144... but still only 9 products are showing? I'm baffled. Link to comment Share on other sites More sharing options...
PascalVG Posted November 11, 2013 Share Posted November 11, 2013 Lars, the counting f the discounted product uses a different SQL query than getting the products really. Do you think you really have more than 9 discounted products? Do you think there indeed should be 148, according to your discount rules etc? one more try: just take out the LIMIT code: ORDER BY '.(isset($orderByPrefix) ? pSQL($orderByPrefix).'.' : '').'`'.pSQL($orderBy).'`'.' '.pSQL($orderWay) .' <- remove .' as well! LIMIT '.intval($pageNumber * $nbProducts).', '.intval($nbProducts); <- don't remove the ; so change to: ORDER BY '.(isset($orderByPrefix) ? pSQL($orderByPrefix).'.' : '').'`'.pSQL($orderBy).'`'.' '.pSQL($orderWay); <- finish with a ; pascal 1 Link to comment Share on other sites More sharing options...
LarsHolmgaard Posted November 18, 2013 Author Share Posted November 18, 2013 Hi Pascal, I am so glad for your help! And good idea removing the limit from the query - but ... it still only shows 9. There SHOULD be more products on sale than 9, but I can't tell for sure. My boss is handling all the products, pricing and so on and asked me to find out why it only shows 9 products. It has been this way for a while and I have never seen more than 9 on the prices-drop.php page. The most logical explanation would be that there really only is 9 products on sale, but I doubt it. Is there any way I can make sure how many products are on sale in the back end? Lars, the counting f the discounted product uses a different SQL query than getting the products really. Do you think you really have more than 9 discounted products? Do you think there indeed should be 148, according to your discount rules etc? one more try: just take out the LIMIT code: Link to comment Share on other sites More sharing options...
PascalVG Posted November 19, 2013 Share Posted November 19, 2013 Lars, I get the feeling your PrestaShop uses another function than this one. (Not sure if 1.2.5 already knew overriding of functions...) Can you check something for me? Can you rename the function temporarily to some non-existing name, like add 123 to its name: static public function GetPricesDrop123(...) If this IS the function it uses, it should get problems loading the page/module-info now and stop showing the page or any of the price drop products. If it loads as normal though, another getPricesDrop must be hiding somewhere... Can you search your files? Maybe search for function getPricesDrop( through all your files and see if there's another function that is used instead. (If you can't search on the server, zip all your files and download to your local computer. Then unzip and use the Windows search/Mac search functions... ) pascal. 1 Link to comment Share on other sites More sharing options...
LarsHolmgaard Posted November 21, 2013 Author Share Posted November 21, 2013 Hi Pascal, Good idea. It IS the function used. I just renamed the function and everything else than the prices-drop page is working properly. So... it is the right function and there is no code caching or anything else blocking my updates. I really don't get it. Now I am trying to find out how many products on sale there really is to make sure there IS more than 9. Can you check something for me? Can you rename the function temporarily to some non-existing name, like add 123 to its name: static public function GetPricesDrop123(...) Link to comment Share on other sites More sharing options...
LarsHolmgaard Posted November 25, 2013 Author Share Posted November 25, 2013 Pascal, you're the man. I think the problem was solved already in your first reply. I just asked my boss to lower the price on some more products and it works brilliant now. It shows 11 products on sale which is correct. Thank you so much for your effort and I apologize for the confusion. I was puzzled too. I really appreciate your help. Link to comment Share on other sites More sharing options...
PascalVG Posted November 25, 2013 Share Posted November 25, 2013 Glad it works now! I think we got confused by the $nbProducts, which is the total number of products (discounted or not), and your 9 being the DISCOUNTED products only. Happy selling! pascal 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