From 78c5bd08b42d2027941b50c6f61288e2aa0b33dd Mon Sep 17 00:00:00 2001 From: Richard BAYET Date: Wed, 30 Oct 2019 17:13:40 +0100 Subject: [PATCH] Fixes #1591 #1581 Explicit collection page size when only fetching aggregations. Keeps the "Show all" working by distinguishing between NO page size set ("Show all") and a page size of 0. Also covers someone setting a page size of null for the fun. --- .../Controller/Navigation/Filter/Ajax.php | 2 ++ .../Product/Fulltext/Collection.php | 17 ++++++++++++++++- .../Ui/Category/Form/DataProviderPlugin.php | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/module-elasticsuite-catalog/Controller/Navigation/Filter/Ajax.php b/src/module-elasticsuite-catalog/Controller/Navigation/Filter/Ajax.php index e277caa99..d0b130618 100644 --- a/src/module-elasticsuite-catalog/Controller/Navigation/Filter/Ajax.php +++ b/src/module-elasticsuite-catalog/Controller/Navigation/Filter/Ajax.php @@ -116,6 +116,8 @@ private function initLayer() $this->applyFilters(); + $this->layerResolver->get()->getProductCollection()->setPageSize(0); + return $this; } diff --git a/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php b/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php index 5b12d3209..4c4213f98 100644 --- a/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php +++ b/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php @@ -219,6 +219,21 @@ public function resetOrder() return $this; } + /** + * {@inheritDoc} + */ + public function setPageSize($size) + { + /* + * Explicitely setting the page size to false or null is to be treated as having not set any page size. + * That is: no pagination, all items are expected. + */ + $size = ($size === null) ? false : $size; + $this->_pageSize = $size; + + return $this; + } + /** * {@inheritDoc} */ @@ -532,7 +547,7 @@ private function prepareRequest() $searchRequestName = $this->searchRequestName; // Pagination params. - $size = $this->_pageSize ? $this->_pageSize : $this->getSize(); + $size = ($this->_pageSize !== false) ? $this->_pageSize : $this->getSize(); $from = $size * (max(1, $this->_curPage) - 1); // Setup sort orders. diff --git a/src/module-elasticsuite-catalog/Plugin/Ui/Category/Form/DataProviderPlugin.php b/src/module-elasticsuite-catalog/Plugin/Ui/Category/Form/DataProviderPlugin.php index 04ce00262..0f83836ba 100644 --- a/src/module-elasticsuite-catalog/Plugin/Ui/Category/Form/DataProviderPlugin.php +++ b/src/module-elasticsuite-catalog/Plugin/Ui/Category/Form/DataProviderPlugin.php @@ -237,7 +237,7 @@ private function getAttributes($category) /** @var \Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection $fulltextCollection */ $fulltextCollection = $this->fulltextCollectionFactory->create(); $fulltextCollection->setStoreId($storeId) - ->setPageSize(1) + ->setPageSize(0) ->addFieldToFilter('category_ids', $this->getCategoryFilterParam($category)); $attributeSetIds = array_keys($fulltextCollection->getFacetedData('attribute_set_id'));