Filtering isn't working correctly with Infinite scroll option

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 1 month ago #350091

Hi,

You can use our contact form:
www.hikashop.com/support/contact-us.html

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

  • Posts: 41
  • Thank you received: 4
1 year 1 month ago #350118

Perfect, I have done that right now.
Thank you very much for the help!

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 1 month ago #350155

Hi,

Thank you for the access. It is working. I made some progress.
However, with JCHOptimize activated I have a hard time debugging properly the javascript of the infinite scroll system.
Could you turn it off temporarily ?

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

  • Posts: 41
  • Thank you received: 4
1 year 1 month ago #350182

Hi, sorry!
I Was not around yesterday, I can do that for you now.
Very sorry for the delay.

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

  • Posts: 41
  • Thank you received: 4
1 year 4 weeks ago #350285

Hey Nicolas!

Thank you so much for sorting that for me, I really appreciate it and I'm glad that it's working now.
I was just wondering if I was able to re-enable caching and optimizations again, if you're done debugging?
(as well as closing the ftp access)
Also interested what the solution was, if you're able to share I would find it really interesting.

All the best

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 4 weeks ago #350294

Hi,

Sorry for not coming back to you since the end of last week.
The beginning of the week was quite intense for me and I didn't had the time to look into it.
I was actually going to look into the issue today, but indeed, as you're saying, it's working fine today, without me doing anything since last week.
So I'm feeling the issue being solved might mean that the issue is actually linked to caching.

The changes I made last week were to make sure the javascript for the infinite scroll mechanism properly takes into account the URL with the new value of the filters.
The changes are actually quite important in the product / listing_div view file.
I changed this code:

	if($infinite_scroll && empty($this->tmpl_ajax) && $this->pageInfo->elements->page > 1) {
		// @TODO
		// display of the block for the automatic update.
		// addition of the javascript

		global $Itemid;

		$filters_params = '';
		if(!empty($this->filters)){
			$reseted = hikaInput::get()->getVar('reseted');
			foreach($this->filters as $uniqueFitler){
				$name = 'filter_'.$uniqueFitler->filter_namekey;
				$value = hikaInput::get()->getVar($name);
				if(is_array($value))
					$value = implode('::', $value);
				if($reseted)
					$value = '';
				$filters_params .= '&'.$name . '=' . $value;

				$name .= '_values';
				$value = hikaInput::get()->getVar($name);
				if($reseted)
					continue;
				if(is_array($value))
					$value = implode('::', $value);
				if(empty($value))
					continue;

				$filters_params .= '&'.$name . '=' . $value;
			}
		}
		$cid = '';
		if($this->categoryFromURL)
			$cid = '&cid='.(int)(is_array($this->pageInfo->filter->cid) ? reset($this->pageInfo->filter->cid) : $this->pageInfo->filter->cid);

?>
		<div class="hikashop_infinite_scroll" id="<?php echo $mainDivName; ?>_infinite_scroll">
			<a href="#" onclick="return window.localPage.infiniteScroll('<?php echo $mainDivName; ?>');">
				<span><?php echo JText::_('HIKA_LOAD_MORE'); ?></span>
			</a>
		</div>
<script type="text/javascript">
if(!window.localPage) window.localPage = {};
window.localPage.infiniteScrollEvents = {};
window.localPage.infiniteScrollPage = 1;
window.localPage.infiniteScroll = function(container_name) {
	if(window.localPage.infiniteScrollPage <= 0)
		return false;

	var w = window, d = document, o = w.Oby,
		container = d.getElementById(container_name + '_infinite_scroll');

	if(!container)
		return false;
	if(container.loading)
		return false;

	container.loading = true;
	o.addClass(container, 'loading');

	var url = '<?php echo HIKASHOP_LIVE; ?>index.php?option=com_hikashop&ctrl=product&task=listing<?php echo $cid; ?>&limitstart=HIKAPAGE<?php echo $filters_params; ?>&Itemid=<?php echo (int)$Itemid; ?>&tmpl=<?php echo (HIKASHOP_J30 ? 'raw' : 'component'); ?>';
	url = url.replace(/HIKAPAGE/g, <?php echo (int)$this->pageInfo->limit->value; ?> * window.localPage.infiniteScrollPage);
to this:
	if($infinite_scroll && $this->pageInfo->elements->page > 1) {
		// @TODO
		// display of the block for the automatic update.
		// addition of the javascript

		global $Itemid;

		$filters_params = '';
		if(!empty($this->filters)){
			$reseted = hikaInput::get()->getVar('reseted');
			foreach($this->filters as $uniqueFitler){
				$name = 'filter_'.$uniqueFitler->filter_namekey;
				$value = hikaInput::get()->getVar($name, null);
				if(is_null($value) || (is_string($value) && !strlen($value))) {
					$cid = hikaInput::get()->getInt("cid",'itemid_'.hikaInput::get()->getInt("Itemid",0));
					$value = $app->getUserState('com_hikashop.'.$cid.'_filter_'.$uniqueFitler->filter_namekey, '');
				}
				if(is_array($value))
					$value = implode('::', $value);
				if($reseted)
					$value = '';
				$filters_params .= '&'.$name . '=' . $value;

				$name .= '_values';
				$value = hikaInput::get()->getVar($name, null);
				if(is_null($value) || (is_string($value) && !strlen($value))) {
					$cid = hikaInput::get()->getInt("cid",'itemid_'.hikaInput::get()->getInt("Itemid",0));
					$value = $app->getUserState('com_hikashop.'.$cid.'_filter_'.$uniqueFitler->filter_namekey.'_values', '');
				}
				if($reseted)
					continue;
				if(is_array($value))
					$value = implode('::', $value);
				if(empty($value))
					continue;

				$filters_params .= '&'.$name . '=' . $value;
			}
		}
		$cid = '';
		if($this->categoryFromURL)
			$cid = '&cid='.(int)(is_array($this->pageInfo->filter->cid) ? reset($this->pageInfo->filter->cid) : $this->pageInfo->filter->cid);
		if(!empty($this->tmpl_ajax)) {
?>
<script type="text/javascript">
window.localPage.infiniteScrollUrl = '<?php echo HIKASHOP_LIVE; ?>index.php?option=com_hikashop&ctrl=product&task=listing<?php echo $cid; ?>&limitstart=HIKAPAGE<?php echo $filters_params; ?>&Itemid=<?php echo (int)$Itemid; ?>&tmpl=<?php echo (HIKASHOP_J30 ? 'raw' : 'component'); ?>';
</script>
<?php
		}
	}
	if($infinite_scroll && empty($this->tmpl_ajax) && $this->pageInfo->elements->page > 1) {
?>
		<div class="hikashop_infinite_scroll" id="<?php echo $mainDivName; ?>_infinite_scroll">
			<a href="#" onclick="return window.localPage.infiniteScroll('<?php echo $mainDivName; ?>');">
				<span><?php echo JText::_('HIKA_LOAD_MORE'); ?></span>
			</a>
		</div>
<script type="text/javascript">
if(!window.localPage) window.localPage = {};
window.localPage.infiniteScrollEvents = {};
window.localPage.infiniteScrollPage = 1;
window.localPage.infiniteScrollUrl = '<?php echo HIKASHOP_LIVE; ?>index.php?option=com_hikashop&ctrl=product&task=listing<?php echo $cid; ?>&limitstart=HIKAPAGE<?php echo $filters_params; ?>&Itemid=<?php echo (int)$Itemid; ?>&tmpl=<?php echo (HIKASHOP_J30 ? 'raw' : 'component'); ?>';
window.localPage.infiniteScroll = function(container_name) {
	if(window.localPage.infiniteScrollPage <= 0)
		return false;

	var w = window, d = document, o = w.Oby,
		container = d.getElementById(container_name + '_infinite_scroll');

	if(!container)
		return false;
	if(container.loading)
		return false;

	container.loading = true;
	o.addClass(container, 'loading');
	var url = window.localPage.infiniteScrollUrl.replace(/HIKAPAGE/g, <?php echo (int)$this->pageInfo->limit->value; ?> * window.localPage.infiniteScrollPage);

So try to reactivate the caching and see if you have the problem or not after that. If you do, then it will mean it's definitely linked to the caching.

The following user(s) said Thank You: jasmine247

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

  • Posts: 41
  • Thank you received: 4
1 year 3 weeks ago #350343

Hi again Nicolas!

That's amazing, thank you so much!

I re-enabled caching and it appears to be working perfectly (I have checked a few pages and filters that I knew were an issue)!
So I'm guessing that your changes have worked for me, which is so great!

I really appreciate the time you've put in to helping fix this and hopefully It can be useful to someone else in the same spot.

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 3 weeks ago #350360

Hi,

Thanks for the feedback. We'll include the modifications for the next release of HikaShop in 2 months.

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 2 weeks ago #350509

Hi,

I have the same issue, but after replacing the code you provided I get an error:
0 Call to a member function GetUserState() on null

Call stack
# Function Location
1 () JROOT/templates/r_ivee/html/com_hikashop/product/listing_div.php:232
2 include() JROOT/libraries/src/MVC/View/HtmlView.php:410
3 Joomla\CMS\MVC\View\HtmlView->loadTemplate() JROOT/administrator/components/com_hikashop/helpers/helper.php:2785
4 hikashopView->loadTemplate() JROOT/components/com_hikashop/views/product/tmpl/listing.php:270
5 include() JROOT/libraries/src/MVC/View/HtmlView.php:410
6 Joomla\CMS\MVC\View\HtmlView->loadTemplate() JROOT/administrator/components/com_hikashop/helpers/helper.php:2785
7 hikashopView->loadTemplate() JROOT/libraries/src/MVC/View/HtmlView.php:203
8 Joomla\CMS\MVC\View\HtmlView->display() JROOT/administrator/components/com_hikashop/helpers/helper.php:2740
9 hikashopView->display() JROOT/components/com_hikashop/views/product/view.html.php:29
10 ProductViewProduct->display() JROOT/libraries/src/MVC/Controller/BaseController.php:639
11 Joomla\CMS\MVC\Controller\BaseController->display() JROOT/administrator/components/com_hikashop/helpers/helper.php:2459
12 hikashopController->display() JROOT/components/com_hikashop/controllers/product.php:46
13 productController->listing() JROOT/libraries/src/MVC/Controller/BaseController.php:672
14 Joomla\CMS\MVC\Controller\BaseController->execute() JROOT/administrator/components/com_hikashop/helpers/helper.php:2437
15 hikashopController->execute() JROOT/components/com_hikashop/hikashop.php:88
16 require_once() JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:71
17 Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher\{closure}() JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:73
18 Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch() JROOT/libraries/src/Component/ComponentHelper.php:355
19 Joomla\CMS\Component\ComponentHelper::renderComponent() JROOT/libraries/src/Application/SiteApplication.php:208
20 Joomla\CMS\Application\SiteApplication->dispatch() JROOT/libraries/src/Application/SiteApplication.php:249
21 Joomla\CMS\Application\SiteApplication->doExecute() JROOT/libraries/src/Application/CMSApplication.php:294
22 Joomla\CMS\Application\CMSApplication->execute() JROOT/includes/app.php:61
23 require_once() JROOT/index.php:32

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 2 weeks ago #350510

Hi,

Indeed, I had forgotten a line to initialize the $app variable at the beginning of the code.

You need to add:
$app = JFactory::getApplication();

Note that I've added the patch on our end. So you could delete your view override, download HikaShop on our website and install it on yours and you would get the patch automatically.

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 2 weeks ago #350533

Hi,
Thanks, I downloaded the latest version and installed it. But the problem is still the same. When I filter on f.e. "naambordjes plexiglas", the first rows are ok, but when scrolling down (infinite scroll) all the products are shown instead of just the filtered ones.

jouwnaambord.nl/alle-naambordjes

Last edit: 1 year 2 weeks ago by michelpouli. Reason: Updated the view to version 4.7.2. again, restored some layout changes for the template.

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 2 weeks ago #350544

Hi,

When I use the filters on your website and inspect the AJAX requests, I can see the main request returning a 500 HTTP status:
i.imgur.com/iOQgOX1.png
And if I look at the content of the response, it contains a fatal error message:
"Attempt to assign property 'currency_code' on null"
i.imgur.com/Xm1KxLR.png
However, since the "debug" is not activated in the Joomla configuration, I don't see the full error message.
Ideally, you should be able to find the full error message for that error in the PHP error log of your hosting. Or with the debug on, while looking at the HTTP requests with your browser's developer tools, like I did.

I'm thinking that this 500 error might prevent the filters from properly initializing the filters, leading to the infinite scroll not getting the filter selection registered.

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 2 weeks ago #350563

Hi,

I have activated the debug and found this Call Stack:


Call stack
# Function Location
1 () JROOT/plugins/system/hikashop_ga4/hikashop_ga4.php:417
2 plgSystemHikashop_ga4->getProductInfo() JROOT/plugins/system/hikashop_ga4/hikashop_ga4.php:268
3 plgSystemHikashop_ga4->getProductJS() JROOT/plugins/system/hikashop_ga4/hikashop_ga4.php:53
4 plgSystemHikashop_ga4->onBeforeCompileHead() JROOT/libraries/src/Plugin/CMSPlugin.php:279
5 Joomla\CMS\Plugin\CMSPlugin->Joomla\CMS\Plugin\{closure}() JROOT/libraries/vendor/joomla/event/src/Dispatcher.php:486
6 Joomla\Event\Dispatcher->dispatch() JROOT/libraries/src/Application/EventAware.php:107
7 Joomla\CMS\Application\WebApplication->triggerEvent() JROOT/libraries/src/Document/Renderer/Html/MetasRenderer.php:61
8 Joomla\CMS\Document\Renderer\Html\MetasRenderer->render() JROOT/libraries/src/Document/Renderer/Html/HeadRenderer.php:39
9 Joomla\CMS\Document\Renderer\Html\HeadRenderer->render() JROOT/libraries/src/Document/HtmlDocument.php:565
10 Joomla\CMS\Document\HtmlDocument->getBuffer() JROOT/libraries/src/Document/HtmlDocument.php:848
11 Joomla\CMS\Document\HtmlDocument->_renderTemplate() JROOT/libraries/src/Document/HtmlDocument.php:633
12 Joomla\CMS\Document\HtmlDocument->render() JROOT/libraries/src/Application/CMSApplication.php:1017
13 Joomla\CMS\Application\CMSApplication->render() JROOT/libraries/src/Application/SiteApplication.php:722
14 Joomla\CMS\Application\SiteApplication->render() JROOT/libraries/src/Application/CMSApplication.php:299
15 Joomla\CMS\Application\CMSApplication->execute() JROOT/includes/app.php:61
16 require_once() JROOT/index.php:32

So, I deactivated the Hikashop - Google Analytics 4 plugin to test.
Then the 500 error disapeared. When selecting the filter "naambordjes plexiglas" the page still show all the products. After a page refresh, the page shows the right products. But when selecting another filter f.e. "naambordjes aluminium" the page shows the products related to that, but also the productresults from the previous filter ("naambordjes plexiglas"). After a refresh again, it shows the proper results.

I tested further with the Hikashop - Google Analytics 4 plugin activated again and got the same results, but then the filter can't be removed anymore.

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 2 weeks ago #350564

Hi,

I think you're using an old version of the GA4 plugin. Download the latest version on our website and install it on yours and you should not have the error anymore.

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 2 weeks ago #350571

Ok, downloaded and installed it. The error indeed is gone and the filter can be removed again too.

But the shown products are still the same after filtering. Only after a page refresh (f5) the results are how it should be. See screenshots.

Attachments:

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 2 weeks ago #350576

Hi,

Do you have some kind of caching on your website or an override of the product / filter.php view file ?
If so, could you deactivate them and try again ?

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

  • Posts: 506
  • Thank you received: 21
  • Hikashop Business
1 year 2 weeks ago #350592

Hi,

Yes I do, JCH Optimize, but the pages with the filter are excluded from cache. But to be sure I disabled the plugin and tested again. It's not in the cache, but I think it has to do with some other option in the plugin. I will look into that. Thanks.

Last edit: 1 year 2 weeks ago by michelpouli.

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

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

Hi,
I contacted Samuel from JCH optimize and this is his reply:

Question: When selecting a filteroption the page loads the first 12 products ok, but when using the infinit scroll the page shows all products. After a page refresh the filter show the correct results. I first thought the page cache was responsible, but that was not the cause. When I disable JCH Optimize the filters work ok. I then tried to exclude all js files from hikashop, but that doesn't solve this too.

Answer from Samuel:
This seems to be a bug in the hikashop script. When a filter is selected, I see a JavaScript error on the page:

i.imgur.com/j3iDOsM.png

Even though the error occurs with the JCH Optimize script, it occurs in the hikashop script and the development tool can direct you to the line it is generated in:

i.imgur.com/aU5LxpQ.png

From what I can read here, the script is getting all the scripts in the HEAD section and re-inserting them into the page. That's why it's complaining that the identifier is already declared. This causes the rest of the script to fail. I'm not sure what the intended function here was, but I can't fix this because ultimately, the issue is about what this script is doing. If I understood it better, I probably could think of a workaround but your best bet would be to ask the developer of this script for more assistance. If there's any feedback I can act on, I'd be happy to do so.

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
1 year 1 week ago #350805

Hi,

The loading of the infinite scroll will ask for the main area of the page with a parameter tmpl=raw in the URL.
Then, it will get the HTML in the main div of the listing in the HTML returned to add it to the listing already displayed on the page, and then also add the JS/CSS elements returned if not already on the page. This is necessary as plugins might add things on the fly to the products being displayed.
For example, with the Tabs & Accordions plugin from Regular labs ( regularlabs.com/tabsaccordions ), you could add tabs tags in the description of (some of ?) your products and then configure your HikaShop listing to display the description. The plugin needs to add its javascript to the page and the javascript needs to be initialized so that the tabs can be functionnal. HikaShop doesn't know which plugin will add what where, so it has to take into account all the javascript.
I think that what we could do is to change the code:

						d.head.appendChild(script);
						d.head.removeChild(script);
in the function refreshOneArea of media/com_hikashop/js/hikashop.js to:
					try {
						d.head.appendChild(script);
						d.head.removeChild(script);
					} catch (e) {
						if (e instanceof SyntaxError) {
						}
					}
that way, it should prevent the system from properly refreshing the areas because of javascript errors, and it should hopefully work properly.
Could you try making the change and letting us know how it goes ?

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

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

Hi,

Thanks, I changed the code in the function refreshOneArea, but the error remains.

Attachments:

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

Time to create page: 0.109 seconds
Powered by Kunena Forum