- Posts: 5
- Thank you received: 0
Pagination and / or infinite scroll problem
3 years 3 weeks ago - 3 years 3 weeks ago #355939
by forghy
Pagination and / or infinite scroll problem was created by forghy
-- 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:
to:
The problem is now fixed.
(I'm not sure if the fix will cause problem with the RAND() sorting, thou)
-- 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:
Code:
$order = ' ORDER BY '.implode(', ', $order);
Code:
$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: 3 years 3 weeks ago by forghy. Reason: formatting
Please Log in or Create an account to join the conversation.
3 years 2 weeks ago #355954
by nicolas
Replied by nicolas on topic Pagination and / or infinite scroll problem
Hi,
Thanks for the feedback.
I do think that this change will be problematic with RAND()
I think it will be better to add :
after the line:
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 ?
Thanks for the feedback.
I do think that this change will be problematic with RAND()
I think it will be better to add :
Code:
$order[] = 'b.product_id ASC';
Code:
$order[] = $pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
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.
3 years 2 weeks ago #355955
by forghy
Replied by forghy on topic Pagination and / or infinite scroll problem
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?
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.
3 years 2 weeks ago #355956
by nicolas
Replied by nicolas on topic Pagination and / or infinite scroll problem
Hi,
Yes, I'm planning on adding this to the next version of HikaShop. Thanks for your feedback.
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.056 seconds