Pagination and / or infinite scroll problem

  • Posts: 5
  • Thank you received: 0
1 year 2 months ago #355939

-- HikaShop version -- : 5.0.0
-- Joomla version -- : 3.10.12
-- PHP version -- : 7.3.3
-- Browser(s) name and version -- : Chrome

In my installation of Hikashop I sort the products by product_quantity in descending order so that the available items are shown first.
Many products have the same quantity (0 or 1).

In one category I have 29 products.
I fetch the products 25 at a time.

When the infinite scroll is triggered, after the 25th item, I get the same the last 4 items of the first batch of 25 items.

The problem is the same even when I turn the infinite scroll off.

After much testing, debugging and digging I think I found the root cause: in MySQL ordering by a non unique field and then applying a LIMIT with an OFFSET returns inconsistent results.
The solution is to (also) order by a unique field.

I made a tiny modification to components/com_hikashop/views/product/view.html.php, at line 749:
from:

$order = ' ORDER BY '.implode(', ', $order);
to:
$order = ' ORDER BY '.implode(', ', $order); $order .= ', b.product_id';

The problem is now fixed.

(I'm not sure if the fix will cause problem with the RAND() sorting, thou)

Last edit: 1 year 2 months ago by forghy. Reason: formatting

Please Log in or Create an account to join the conversation.

  • Posts: 83007
  • Thank you received: 13400
  • MODERATOR
1 year 2 months ago #355954

Hi,

Thanks for the feedback.
I do think that this change will be problematic with RAND()
I think it will be better to add :

$order[] = 'b.product_id ASC';
after the line:
$order[] = $pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
in the same file. That way, it won't affect the query when RAND() is being used.
Can you confirm that it also helps on your end ?

The following user(s) said Thank You: forghy

Please Log in or Create an account to join the conversation.

  • Posts: 5
  • Thank you received: 0
1 year 2 months ago #355955

Perfect!
I confirm that it solves the problem just as well.
Thanks so much.

May I ask you if you think this modification will be part of a future release?

Please Log in or Create an account to join the conversation.

  • Posts: 83007
  • Thank you received: 13400
  • MODERATOR
1 year 2 months ago #355956

Hi,

Yes, I'm planning on adding this to the next version of HikaShop. Thanks for your feedback.

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds
Powered by Kunena Forum