Filtering isn't working correctly with Infinite scroll option

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 1 week ago #350849

Hi,

Can you provide a FTP and a backend access so that we can look into it ?
You an go through our contact form to provide the credentials privately:
www.hikashop.com/support/contact-us.html
Make sure you include a link to this thread in your message

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 1 week ago #350881

Juste sended you the credentials.

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 1 week ago #350910

Hi,

Well, I've spent my morning on this.
To remove the javascript error, I actually had to make the code a lot more complex.
Here is what I've come up with instead of what I had told you:

new Promise((resolve, reject)=>{
						var script = d.createElement('script');
						script.setAttribute('type', 'text/javascript');

						var windowErrorHandler = (event) =>{
							event.preventDefault();
							var error = event.error;
							error.stack = error.stack + '\n\n' + scripts;
							window.removeEventListener('error', windowErrorHandler);
							reject(error);
						};
						window.addEventListener('error', windowErrorHandler);

						var rejectHandler = (error) =>{
							window.removeEventListener('error', windowErrorHandler);
							reject(error);
						};
						script.addEventListener('error', rejectHandler);
						script.addEventListener('abort', rejectHandler);
						var loadedHandler = ()=>{
							window.removeEventListener('error', windowErrorHandler);
							resolve();
						};

						script.addEventListener('load', loadedHandler);
						script.text = scripts.replaceAll('let jch_', 'jch_').replaceAll('const jch', 'window.hikashop.jch');
						try {
							d.head.appendChild(script);
							d.head.removeChild(script);
						} catch (e) {
							if (e instanceof SyntaxError) {
							}
						}
					})
					.catch(error => {
						console.warn('Could not process JavaScript code:\n', error);
					})
					.then(()=>{
					});
This does two things:
- it catches errors generated by scripts loaded in AJAX and cancel them so that the infinite scroll system can continue its job
- it prevents the errors in the JCH Optimize script

However, it's still not working with the "enable combine files" setting of JCH Optimize activated.
While the error didn't help, it's not the main issue I think. The issue I think is that JCH is using cached JS in the AJAX request instead of using the new JS inlined by the infinite scroll mechanism to give to the JS already loaded the new URL to use which includes the values of the filters. So the mechanism calls on the following pages of the infinite scroll as if no filter was set.
Ideally, if JCH Optimize would have some mechanism we could use to tell it to not cache some piece of inlined JS, it would be great.
For example, in the file components/com_hikashop/views/product/tmpl/listing_div.php there are 3 times the line:
<script type="text/javascript">
If we could change them to:
<script type="text/javascript" data-nocache>
and JCH Optimize would skip these, it should solve the problem.

Could you please convey all this to the JCH Optimize support person you were talking to and see what they propose ?

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 1 week ago #350911

Thank you Nicolas for all your effort to solve this. I've sended your suggestion to Samuel from JCH. I will let you know his answer/solution.

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 6 days ago #350942

Hi Nicolas, this is the answer I got from Samuel:

I'm glad to know he's looking at resolving this issue. I don't fully understand how his script works, nor do I understand what he means by "JCH is using cached JS in the AJAX request." From what I remember about the issue, JCH adds some scripts to the page, and it seems his script is re-adding them via AJAX when you use the filters. That's why you get the error "Identifier has already been declared." So that's an error the browser triggers when the script is added again. Also, in the browser's development tool, I could see where these scripts were being duplicated. So it's not JCH that is triggering the error, it's the browser when it detects an illegal use of JavaScript and prevents the rest of the script from running.

These scripts are added whenever you enable the Combine Files feature and any of the Advanced Features, such as Reduce Unused CSS, etc. So invariably, it's not an issue with the JCH script, as any inline script on the page that declares an identifier in this way, I think, will cause the same issue if you try to re-add it to the page.

If there are scripts on the page that you want to exclude from JCH Optimize combining, you can do that with the exclude options:

www.jch-optimize.net/documentation/minif...s-and-inline-scripts

I doubt that would work, though, as I already tried excluding all the hikashop scripts and got the same error. If he has scripts he wants to add to the page, then it may be safer to mark his scripts like <script type="text/javascript" data-hika-script> and then only target these with the AJAX script. Again, I don't fully understand what he's trying to do, so I don't even know if that makes sense, but this seems to be the problem based on how I analyzed it.

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 6 days ago #350943

Hi,

It seems Samuel missed some of what I wrote in my previous message.

From what I remember about the issue, JCH adds some scripts to the page, and it seems his script is re-adding them via AJAX when you use the filters. That's why you get the error "Identifier has already been declared." So that's an error the browser triggers when the script is added again. Also, in the browser's development tool, I could see where these scripts were being duplicated. So it's not JCH that is triggering the error, it's the browser when it detects an illegal use of JavaScript and prevents the rest of the script from running.

That was the error he found before. However, as I said in my previous message, I've worked on a solution for these javascript errors.
If he had checked your website again, he would have seen that these errors did not happen anymore. However, the infinite scroll still didn't take into account the filters if JCH's combining was activated.

If there are scripts on the page that you want to exclude from JCH Optimize combining, you can do that with the exclude options:

The inline scripts of HikaShop are not available in that setting, so I'm not sure how to do that.

Anyways, I've looked into it more today, and I think I've found the solution. I've modified the infinite scroll system so that it will now pass the URL with the filters set in a data attribute of the HTML instead of JS code. That way, it's not compressed by JCH and it works fine even with the "enable combining" setting is activated in JCH.
I've made the modifications on your website and it's working fine now as far as I can see. So I guess the case can be closed.
We'll of course include the changes in the next version of HikaShop.

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 5 days ago #350965

Hi Nicolas,

That is great news, thanks a lot. I will inform Samuel. It is awesome that you took all this effort to solve this issue. Your support belongs without any doubt to the best there is.

Samuel asked me to give you a huge compliment for the way you solved this issue.

Last edit: 11 months 4 weeks ago by michelpouli. Reason: reply from Samuel (JCH optimize)
The following user(s) said Thank You: nicolas

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

  • Posts: 30
  • Thank you received: 5
10 months 3 weeks ago #351983

nicolas wrote: When you use the sorting by price, HikaShop uses the product_sort_price value of the products to sort the products. This value in the hikashop_product table in the database is automatically refreshed when you save a product in the backend.
What's likely is that some of the products on your website have a wrong value in that product_sort_price column for some reason ( for example, due to the way the prices are being inserted or have being added in the past).
So what you'll need to do, is to update the sort prices of your products with the current price of the products.
For example, you could go in each product, one by one and save them once. That should fix the problem.
Another solution would be to use a mass action with an action "update the values" on the product_sort_price column in the "operation" mode with the value price.price_value
This will automatically fill the product_sort_price with the price of the product.


Sorry to dig up this thread, but I have the same issue with inconsistencies between price.price_value and product.product_sort_price.

Should I be worried about future problems and set all of our prices to the correct value? Or is this value really only ever used for sorting and nothing else?

EDIT: Maybe the "Check Database" function in Hika's configuration menu could check if these values aren't correct and fix them accordingly?

Last edit: 10 months 3 weeks ago by NTV.

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
10 months 3 weeks ago #351984

Hi,

It's only used for sorting and that won't change so no worries there.

The check database does already a lot of things. Updating the sorting price of a product requires loading all its prices in memory to process them. And if it has variants it has to load the variants too. If there are more than a few thousands variants/products on the website, it will easily take several seconds which could translate into crashes on small servers, or on websites with tens of thousands of websites.
The massaction to update the sort price has the benefit that you can use the "limitation" area to process the products little by little, or with filters, to target the categories one by one for example.

The following user(s) said Thank You: NTV

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

  • Posts: 30
  • Thank you received: 5
10 months 2 weeks ago #352048

Thanks nicolas,

there's something weird about updating a value and then displaying the results via a mass action. In the result display, it looks like the updated value contains the equation for the new value instead.



This only happens for displaying results immediately after changing the value. If I run another mass action to display it again, the value is correct.

EDIT: It's very simple, but here's the mass action that corrects the inconsistencies:

Attachments:
Last edit: 10 months 2 weeks ago by NTV.
The following user(s) said Thank You: nicolas

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

Time to create page: 0.080 seconds
Powered by Kunena Forum