Filtering isn't working correctly with Infinite scroll option

  • Posts: 78286
  • Thank you received: 12365
  • MODERATOR
2 weeks 2 days 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: 36
  • Thank you received: 4
  • Hikashop Business
2 weeks 1 day 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: 78286
  • Thank you received: 12365
  • MODERATOR
2 weeks 6 hours 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: 36
  • Thank you received: 4
  • Hikashop Business
1 week 6 days 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: 36
  • Thank you received: 4
  • Hikashop Business
1 week 1 day 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: 78286
  • Thank you received: 12365
  • MODERATOR
1 week 1 day 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: 36
  • Thank you received: 4
  • Hikashop Business
6 days 11 hours 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: 78286
  • Thank you received: 12365
  • MODERATOR
6 days 5 hours 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: 425
  • Thank you received: 12
  • Hikashop Business
9 hours 25 minutes 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: 78286
  • Thank you received: 12365
  • MODERATOR
5 hours 46 minutes 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.

Time to create page: 0.089 seconds
Powered by Kunena Forum