Pagination not correct after changing limit

  • Posts: 200
  • Thank you received: 75
4 years 2 months ago #315490

-- HikaShop version -- : 4.2.2
-- Joomla version -- : 3.9.15

Hi,

we noticed when changing the number of products displayed in a listing, the pagination buttons do not seem to be correct when you are on a different page than the first page.

You can also see this on the Hikashop Demo website by following these steps:
1. In the backend, we created some more products to have a few more pages of products.
2. On the frontend go to Products Listing -> Display in List
3. Eight products are displayed. Go to a next page, e.g. page 2.
4. Now change the number of products displayed from 8 to e.g. 16
5. The webpage will display 16 products and move back to page nr. 1
However, all links to the other pages are now incorrect.

If you check the links, they are all limitstart=8 while it should be limitstart=16, limitstart=32, limitstart=48, etc.
This goes wrong every time a user is on any page > 1 and changes the limit.
We hope this can be fixed asap.
Thanks.

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
4 years 2 months ago #315516

Hi,

Download the install package on our website and install it on yours and it will add a patch for that.

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

  • Posts: 200
  • Thank you received: 75
4 years 2 months ago #315530

Hi,

hmm, we updated to the latest install package 4.2.2 [2002031612] and got rid of any overrides, but still doesn't appear to be working, we don't see any change.

Did you test by following our steps in the first post?
If you go to any page other than the first page and change the nr. of products displayed, then all the pagination buttons are wrong and they're all identical with the same "limitstart".

Thanks for looking into it.

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

  • Posts: 12953
  • Thank you received: 1778
4 years 2 months ago #315559

Hello,

I wasn't able to reproduce it on my end. Can you send us a temporary back-end access to your website so that we can directly test it ?
You can send it using our contact form, by specifying a link to that thread in your message :
www.hikashop.com/support/contact-us.html

Kind regards,
Mohamed Thelji.

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

  • Posts: 200
  • Thank you received: 75
4 years 2 months ago #315575

Hi,

our live website is not exactly suitable for testing, we'll see if we can set up a separate test-website when we have time.
However, I think you can test on your own Hikashop Demo website because you can also see the exact same thing happening there.

Just follow the steps in our first post on the Demo website and you will see the pagination buttons are not correct after changing the number of products displayed in a listing. That is precisely also what happens on our website.

Attachments:

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

  • Posts: 12953
  • Thank you received: 1778
4 years 2 months ago #315605

Hello,

We succeed to reproduce it on our end thanks to your instructions. to fix it you'll just have to edit the file "administrator\components\com_hikashop\helpers\pagination.php" and change that line :

$current_url = str_replace(array('limitstart'.$this->hikaSuffix.'='.$old_start, 'limitstart'.$this->hikaSuffix.'-='.$old_start), array('limitstart'.$this->hikaSuffix.'='.$start, 'limitstart'.$this->hikaSuffix.'-'.$start), $current_url);

By:

$current_url = preg_replace('#limitstart'.$this->hikaSuffix.'(=|-)[0-9]+#','limitstart'.$this->hikaSuffix.'${1}'.$start, $current_url);


Thank you for your feedback !
Kind regards,
Mohamed.

The following user(s) said Thank You: GW

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

  • Posts: 200
  • Thank you received: 75
4 years 2 months ago #315690

Hi,

the above edit has fixed the initial error, however we now notice changing the nr. of products per page and pagination goes wrong when in combination with filters.

Unfortunately the Hikashop Demo website doesn't have filters, but I think it is fairly easy to reproduce:

1. Apply a filter on a product listing, e.g. a color, size, whatever
2. Change the number of products displayed per page, e.g. from 8 to 16
It will display 16 products, but all pagination buttons are now wrong.

We can see this is because as soon as a filter is applied, there is never any "limit" parameter added to the pagination URL's and the browser therefore won't remember the nr. of products displayed. So the "limitstart" is ok, but the "limit" is missing and therefore it will always revert back to displaying 8 products.

Hopefully this can also be fixed, thanks.


EDIT: As an additional note, this only happens with "Redirect POST mode" set to "Yes", but for us it is quite important to keep this set to Yes.
Also, we found this actually doesn't have anything to do with filters, it is just because as soon as the "limitstart=0" is already present in the URL then things go wrong and the "limit" parameter never gets added.

Last edit: 4 years 2 months ago by GW.

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

  • Posts: 12953
  • Thank you received: 1778
4 years 2 months ago #315711

Hello,

EDIT: As an additional note, this only happens with "Redirect POST mode" set to "Yes", but for us it is quite important to keep this set to Yes.
Also, we found this actually doesn't have anything to do with filters, it is just because as soon as the "limitstart=0" is already present in the URL then things go wrong and the "limit" parameter never gets added.

Thank you for these information, we'll try to reproduce and fix it on our end and get back to you as soon as possible.

Kind regards,
Mohamed.

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

  • Posts: 12953
  • Thank you received: 1778
4 years 2 months ago #315773

Hello,

After a lot of testing I wasn't able to reproduce it on my end with or without the "redirect POST mode" set to yes.
Can you give us a temporary access to your website back-end and FTP so that we can directly test and debug it on your website ? Thank you.
You can send it using our contact form and by specifying a link to that thread in your message :
www.hikashop.com/support/contact-us.html

Kind regards,
Mohamed.

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

  • Posts: 200
  • Thank you received: 75
4 years 1 month ago #316337

Hi,

for some reason we didn't receive a notification of your reply and were too busy to check the forum for a while, apologies.
We'd prefer not to have anyone meddling on our live website if that's alright, but we've tried with a clean install of Joomla and Hikashop, and the problem we experience is also there. To see the issue is easy, what we did:

1. Clean install of Joomla
2. Clean install of Hikashop (4.2.3) with example products
3. Go to Configuration -> Advanced and change "Redirect POST mode" to Yes

4. On frontend go to products listing and manually add &limitstart=0 to the URL (to simulate using a filter, since this is also added when using filters)
5. Scroll to bottom of page and change the number of products displayed from e.g. 21 to 42
6. Now try going to the second page

It doesn't work. It will always reset the nr. of products displayed back to 21 and stay on the first page.

This is also what we tried to explain in our previous message. For things to go wrong, you have to have these 3 conditions:
- "Redirect POST mode" set to Yes
- limitstart must be present in url but NOT limit (which happens when applying filters)
- you must change the number of products displayed

Then pagination is all messed up and doesn't work, which for us is quite a big deal since almost all of our visitors make use of filters.
Hopefully this will help to reproduce and fix the issue, thanks.

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

  • Posts: 12953
  • Thank you received: 1778
4 years 1 month ago #316365

Hello,

I just tested it with :
- The "Redirect POST mode" option set to Yes
- the "limitstart" parameter present in the url but NOT the "limit" one
- a different number of product displayed

and it worked fine, can you send us information about how you configured the filter you used ?

We'd prefer not to have anyone meddling on our live website if that's alright, but we've tried with a clean install of Joomla and Hikashop, and the problem we experience is also there.


Sure no problem, can we eventually get just an access to the page where you are having your issue to directly test it ? Thank you.

Kind regards,
Mohamed.

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

  • Posts: 200
  • Thank you received: 75
4 years 1 month ago #316410

You can check on our website for example here:

This message contains confidential information


Just change the number of products displayed from e.g. 12 to 24 and try going to another page, it doesn't work.
(I've already added &limitstart=0 to the link, but you can apply a filter on the right of the page if you want. As mentioned before however, this has nothing to do with filters, it also happens when disabling all filters or with a completely clean hikashop install without ever setting up any filters. The issue is just because of limitstart)

Not sure if more explanation will help, but:
- normally the pagination buttons should have both limitstart and limit in them.
Please remove ?limitstart=0 from our link above and check the pagination buttons, you will see they look like ?limitstart=12&limit=12 , ?limitstart=24&limit=12 etc., as they should.
Now compare this with the pagination buttons when limitstart is present in our link above, they look like ?limitstart=12 , ?limitstart=24 etc..

Something goes wrong somewhere and limit is never added to the pagination buttons. This is ok if the nr. of products displayed is the default lowest number, in our case 12, and the pagination buttons will still work, but if the nr. of products is other than the default, for example 24, then the pagination buttons no longer work.


We know we have several modifications and overrides, but we are quite certain this has no influence on the issue since we tried after removing them all, and besides we also clearly see it happening on a completely fresh install of hikashop with your sample products.

I would ask you once more to literally just follow the few simple steps we described in our previous post, create a new database on your localhost or wherever, install Joomla, install Hikashop with sample products, set Redirect Post mode to Yes, and you can already see the issue.


We'd gladly give any additional info or explanation if that will help, hope you can finally see what we mean.
Thanks!

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

  • Posts: 12953
  • Thank you received: 1778
4 years 1 month ago #316431

Hello,

Thank you for these information, we succeed to reproduce an issue using both filters and the pagination. We'll debug it and fix it as soon as possible and get back to you !

Kind regards,
Mohamed.

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

  • Posts: 12953
  • Thank you received: 1778
4 years 1 month ago #316481

Hello,

Can you edit the file "administrator\components\com_hikashop\helpers\pagination.php" and change these lines :

if(isset($_POST['limit'.$this->hikaSuffix]) && isset($_GET['limit'.$this->hikaSuffix])){
	$ret = true;
	$old_limit = (int)$_GET['limit'.$this->hikaSuffix];
	$current_url = preg_replace('#limit'.$this->hikaSuffix.'(=|-)[0-9]+#','limit'.$this->hikaSuffix.'${1}'.$this->limit, $current_url);
}
By:
if(isset($_POST['limit'.$this->hikaSuffix]) && isset($_GET['limit'.$this->hikaSuffix])){
	$ret = true;
	$old_limit = hikaInput::get()->getInt('limit'.$this->hikaSuffix);
	$current_url = preg_replace('#limit'.$this->hikaSuffix.'(=|-)[0-9]+#','limit'.$this->hikaSuffix.'${1}'.$this->limit, $current_url);
}

Thank you for your feedback !
Kind regards,
Mohamed.

Last edit: 4 years 1 month ago by Mohamed Thelji.

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

  • Posts: 200
  • Thank you received: 75
4 years 1 month ago #316554

Hm, that doesn't seem to change anything.

We've added your above patch on our website and you can check it, but your only change is to $old_limit, which isn't used anywhere at all in the pagination.php file and therefore doesn't affect anything, correct? (Just like $old_start a few lines above, they seem to be leftovers from older hikashop versions where they were still used)
Thanks.

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

  • Posts: 12953
  • Thank you received: 1778
4 years 1 month ago #316596

Hello,

You're right my bad, I sent you the wrong fix. Can you download the last Hikashop version through our website, install it and test it again ? Thank you.

Kind regards,
Mohamed.

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

  • Posts: 200
  • Thank you received: 75
4 years 1 month ago #316621

Hi,

thank you, that is an improvement, but still not working in all cases.
If you apply a filter directly after landing on a product listing page, neither $_POST nor $_GET is set, so limit will now be correctly added to the pagination buttons urls. Good!

However, if you apply a filter and then immediately change the nr. of products displayed, the pagination buttons will still be incorrect and limit will not be added. That is because in this case in pagination.php $_GET is not set, but $_POST is, so that $ret_limit = true and the limit parameter will still not be appended to the urls by your added check on line 166, if($ret_start && $ret_limit).

The problem is, if limit is only set in POST, it should still be added to the url for pagination to work correctly. I think this can be solved by changing line 161 from

$ret_limit = true;
to
if(isset($_GET['limit'.$this->hikaSuffix])) $ret_limit = true;

Only if limit is already present in $_GET, then it doesn't need to be added to the urls. But in all other cases, it needs to be added.
As far as we've tested with that fix everything is working correctly, hope you can confirm as well.
Thanks.

Last edit: 4 years 1 month ago by GW.
The following user(s) said Thank You: Mohamed Thelji

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

  • Posts: 12953
  • Thank you received: 1778
4 years 1 month ago #316637

Hello,

I think it's already what we have in our code and it's working fine :

		if(isset($_POST['limit'.$this->hikaSuffix]) || isset($_GET['limit'.$this->hikaSuffix])){
			$ret_limit = true;

Thank you so much for your feedback, we'll do more investigation and comeback to you if we find something else !
Kind regards,
Mohamed.

Last edit: 4 years 1 month ago by Mohamed Thelji.

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

  • Posts: 200
  • Thank you received: 75
4 years 1 month ago #316650

Nono, you're not correct, that is not the same at all and your code is not working fine...

Compare your code

if(isset($_POST['limit'.$this->hikaSuffix]) || isset($_GET['limit'.$this->hikaSuffix])){
	$ret_limit = true;
	......
}
if($ret_start && $ret_limit)
	return $current_url;
elseif($ret_start && !$ret_limit)
	return $current_url . '&limit='.$this->limit;
with this
if(isset($_POST['limit'.$this->hikaSuffix]) || isset($_GET['limit'.$this->hikaSuffix])){
	if(isset($_GET['limit'.$this->hikaSuffix])) $ret_limit = true;
	......
}
if($ret_start && $ret_limit)
	return $current_url;
elseif($ret_start && !$ret_limit)
	return $current_url . '&limit='.$this->limit;

and try to spot the difference, what happens if only $_POST[ 'limit' ] is set.
In your code, limit will then not be appended to $current_url, but it needs to be added for pagination to work. In our code it will.

On the product listing try applying a filter and then directly changing the nr. of products displayed and you will see which one is working, and which one isn't. Hope you can see what we mean...
Thanks.

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

  • Posts: 12953
  • Thank you received: 1778
4 years 1 month ago #316701

Hello,

and try to spot the difference, what happens if only $_POST[ 'limit' ] is set.
In your code, limit will then not be appended to $current_url, but it needs to be added for pagination to work. In our code it will.


You're right, the fact that it wasn't appended to the $current_url didn't created any issue on my end that's why I didn't added it.

I just tested it with your fix and everything is still working on my end, so we'll add it to the next version.

Thanks for your feedback.
Kind regards,
Mohamed.

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

Time to create page: 0.112 seconds
Powered by Kunena Forum