Skip to content

Commit

Permalink
Merge pull request #5007 from magento-troll/MC-21962-3
Browse files Browse the repository at this point in the history
- fixed Catalog Pagination doesn't work on Elasticsearch 6.x (2.3.4)
  • Loading branch information
irenelagno authored Nov 11, 2019
2 parents 3efbe15 + bd6a973 commit 439d2ab
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<severity value="CRITICAL"/>
<group value="mtf_migrated"/>
<group value="Catalog"/>
<skip>
<issueId value="MC-21962"/>
</skip>
</annotations>
<before>
<magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 1 "/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Search\Model\EngineResolver;

/**
* Advanced search collection
Expand All @@ -40,6 +41,11 @@
*/
class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
{
/**
* Config search engine path.
*/
private const SEARCH_ENGINE_VALUE_PATH = 'catalog/search/engine';

/**
* List Of filters
* @var array
Expand Down Expand Up @@ -344,6 +350,63 @@ protected function _renderFiltersBefore()
parent::_renderFiltersBefore();
}

/**
* @inheritDoc
*/
public function clear()
{
$this->searchResult = null;
return parent::clear();
}

/**
* @inheritDoc
*/
protected function _reset()
{
$this->searchResult = null;
return parent::_reset();
}

/**
* @inheritdoc
*/
public function _loadEntities($printQuery = false, $logQuery = false)
{
$this->getEntity();

$currentSearchEngine = $this->_scopeConfig->getValue(self::SEARCH_ENGINE_VALUE_PATH);
if ($this->_pageSize && $currentSearchEngine === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE) {
$this->getSelect()->limitPage($this->getCurPage(), $this->_pageSize);
}

$this->printLogQuery($printQuery, $logQuery);

try {
/**
* Prepare select query
* @var string $query
*/
$query = $this->getSelect();
$rows = $this->_fetchAll($query);
} catch (\Exception $e) {
$this->printLogQuery(false, true, $query);
throw $e;
}

foreach ($rows as $value) {
$object = $this->getNewEmptyItem()->setData($value);
$this->addItem($object);
if (isset($this->_itemsById[$object->getId()])) {
$this->_itemsById[$object->getId()][] = $object;
} else {
$this->_itemsById[$object->getId()] = [$object];
}
}

return $this;
}

/**
* Get total records resolver.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
use Magento\Search\Model\EngineResolver;

/**
* Fulltext Collection
Expand All @@ -41,6 +42,11 @@
*/
class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
{
/**
* Config search engine path.
*/
private const SEARCH_ENGINE_VALUE_PATH = 'catalog/search/engine';

/**
* @var QueryResponse
* @deprecated 100.1.0
Expand Down Expand Up @@ -373,6 +379,63 @@ public function addFieldToFilter($field, $condition = null)
return $this;
}

/**
* @inheritDoc
*/
public function clear()
{
$this->searchResult = null;
return parent::clear();
}

/**
* @inheritDoc
*/
protected function _reset()
{
$this->searchResult = null;
return parent::_reset();
}

/**
* @inheritdoc
*/
public function _loadEntities($printQuery = false, $logQuery = false)
{
$this->getEntity();

$currentSearchEngine = $this->_scopeConfig->getValue(self::SEARCH_ENGINE_VALUE_PATH);
if ($this->_pageSize && $currentSearchEngine === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE) {
$this->getSelect()->limitPage($this->getCurPage(), $this->_pageSize);
}

$this->printLogQuery($printQuery, $logQuery);

try {
/**
* Prepare select query
* @var string $query
*/
$query = $this->getSelect();
$rows = $this->_fetchAll($query);
} catch (\Exception $e) {
$this->printLogQuery(false, true, $query);
throw $e;
}

foreach ($rows as $value) {
$object = $this->getNewEmptyItem()->setData($value);
$this->addItem($object);
if (isset($this->_itemsById[$object->getId()])) {
$this->_itemsById[$object->getId()][] = $object;
} else {
$this->_itemsById[$object->getId()] = [$object];
}
}

return $this;
}

/**
* Add search query filter
*
Expand Down

0 comments on commit 439d2ab

Please sign in to comment.