Infinite scroll is loading once all products are loaded
-
15-04-2021 - |
Pregunta
I want to make infinite scroll to load even if not all products are loaded
templates for infinite scroll
here is the code :
<?php if($block->isEnabled()): ?>
<div class="infiniteScroll_wrap">
<div id="infinite_loadMoreAnchor"
data-pages="<?php echo $block->getPagesToShow(); ?>">
</div>
Block code for Infinite.php
protected function _getProductsCount()
{
$block = $this->getLayout()->getBlock('category.products.list');
if (!$block) {
$block = $this->getLayout()->getBlock('search_result_list');
}
if (!$block) {
return false;
}
$productCollection = $block->getLoadedProductCollection();
return $productCollection->getSize();
}
/**
* Get number of pagination pages
*
* @return mixed
*/
public function getPagesToShow()
{
return min($this->getPagesCount(), $this->_pagesToShowOption());
}
/**
* Get pagination pages from collection
*
* @return float
*/
public function getPagesCount()
{
$pages = ceil($this->_getProductsCount()/$this->_productsPerPage());
return $pages;
}
/**
* If is enabled
*
* @return mixed
*/
public function isEnabled()
{
return $this->_scopeConfig->getValue('ajaxcatalog/general/ajaxcatalog_infinite_scroll',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
/**
* Get pages to show option
*/
protected function _pagesToShowOption()
{
return $this->_scopeConfig->getValue('ajaxcatalog/general/ajaxcatalog_infinite_pages',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
/**
* Get number of products displayed in grid/list mode
*
* @return mixed
*/
protected function _productsPerPage()
{
if($this->_request->getParam('product_list_mode') == 'list'){
return $this->_scopeConfig->getValue('catalog/frontend/list_per_page',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
No hay solución correcta
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange