Jump to content

[SOLVED] pagination error


Recommended Posts

Does anyone have this problem?

My pagination works bad for prices-drop page.

By bad i mean that even if i have only 3 products on prices-drop, the pagination on that page shows the same number of pages like the new products page.

Why is that happenening and if you can think of a sollution please do tell me. Thank you.

Link to comment
Share on other sites

  • 1 month later...

Thank you, Rocky.

I did find that through searching, but "Fixed on SVN." ... doesn't help me ;)
Is there a file I can download or something? There's one posted on the forum for a previous PS version, didn't work on 1.2.5.

Link to comment
Share on other sites

Did you read the last comment on that bug report? Someone said that they fixed it by changing line 996 of classes/Product.php from:

if ($count) 
{ 
  $result = Db::getInstance()->getRow(' 
     SELECT COUNT(`id_product`) AS nb 
     FROM `'._DB_PREFIX_.'product` 
     WHERE `reduction_price` > 0 
     OR `reduction_percent` > 0 
     AND `active` = 1'); 
  return intval($result['nb']); 
} 
$currentDate = date('Y-m-d'); 



to this:

if ($count) 
{ 
  $result = Db::getInstance()->getRow(' 
     SELECT COUNT(`id_product`) AS nb 
     FROM `'._DB_PREFIX_.'product` 
     WHERE (`reduction_price` > 0 OR `reduction_percent` > 0) 
     '.((!$beginning AND !$ending) ? 
     'AND (`reduction_from` = `reduction_to` OR (`reduction_from` <= \''.$currentDate.'\' AND `reduction_to` >= \''.$currentDate.'\'))' 
     : 
     ($beginning ? 'AND `reduction_from` <= \''.$beginning.'\'' : '').($ending ? 'AND `reduction_to` >= \''.$ending.'\'' : '')).' 
     AND `active` = 1 
  '); 
  return intval($result['nb']); 
} 
$currentDate = date('Y-m-d'); 

Link to comment
Share on other sites

Yes, saw that too, thats why I wrote "There’s one posted on the forum for a previous PS version, didn’t work on 1.2.5" ;)

He said "If you have an old version", which made me doubt a bit. The edit he suggests is the same as in the file I downloaded, which didn't help much since product.php went into 'fatal error' after replacing it. Went back to the old bugged version.

I'll try editing manually, hope that'll do the trick.

Link to comment
Share on other sites

I've checked my classes/product.php and the solution is not for PS 2.5. That exact piece of code isn't in this version, which explains why I got an 'fatal error' after this fix.

Anybody know a fix that works on PS 2.5?

It's great a bug is fixed, buit please, get the fix out there to the users :)

Link to comment
Share on other sites

I just compared prices-drop.php and classes/Product.php in Prestashop v1.2.5 and SVN. There are changes to the getPricesDrop function in classes/Product.php, but no changes to prices-drop.php. Here's the getPricesDrop function on SVN at the moment:

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());
   $currentDate = date('Y-m-d H:m:i');
   if ($count)
   {
       $sql = '
       SELECT COUNT(DISTINCT p.`id_product`) AS nb
       FROM `'._DB_PREFIX_.'product` p
       WHERE p.`active` = 1
       AND (`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.`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']);
   }
   $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);
}



Try copying it over your getPricesDrop function and see whether that works.

Link to comment
Share on other sites

Thank you so much, Rocky! I'll see if it works in a few minutes, will let you know.

/Edit:

YES! It seems to work like a charm. I had just short of 1 page in specials and now the pagination links have finally gone.

Thanks again, Rocky, for taking the time to look this up and sorting it out for us!

Link to comment
Share on other sites

  • 4 months later...
  • 3 months later...
  • 6 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...