Skip to content

Commit 8f97c50

Browse files
authored
Merge pull request #153 from Nosto/hotfix/4.0.1
Hotfix/4.0.1 - Fix CM GraphQl pagination issue
2 parents 35a54ff + 6ea4e25 commit 8f97c50

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.
22

3+
### 4.0.1
4+
* Fix empty results issues on Magento's GraphQl pagination
5+
36
### 4.0.0
47
* Remove support for MySQL as search engine
58
* Move CategoryMerchandising util to php-sdk

Plugin/CatalogGraphQl/Products/DataProvider/ProductSearch.php

+17
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
namespace Nosto\Cmp\Plugin\CatalogGraphQl\Products\DataProvider;
3838

3939
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ProductSearch as MagentoProductSearch;
40+
use Magento\Framework\Api\SearchCriteriaInterface;
4041
use Magento\Framework\Api\SearchResultsInterface;
42+
use Nosto\Cmp\Helper\CategorySorting;
4143
use Nosto\Cmp\Model\Service\Merchandise\LastResult;
4244

4345
/**
@@ -57,6 +59,21 @@ public function __construct(
5759
$this->lastResult = $lastResult;
5860
}
5961

62+
/**
63+
* @param MagentoProductSearch $productSearch
64+
* @param SearchCriteriaInterface $searchCriteria
65+
*/
66+
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
67+
public function beforeGetList(MagentoProductSearch $productSearch, SearchCriteriaInterface $searchCriteria)
68+
{
69+
//Set currentPage to 1, this will make sure that OFFSET is not applied to the MySQL query
70+
foreach ($searchCriteria->getSortOrders() as $sortOrder) {
71+
if ($sortOrder->getField() === CategorySorting::NOSTO_PERSONALIZED_KEY) {
72+
$searchCriteria->setCurrentPage(1);
73+
}
74+
}
75+
}
76+
6077
/**
6178
* @param MagentoProductSearch $productSearch
6279
* @param SearchResultsInterface $result

Plugin/CatalogGraphQl/Products/Query/Search.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function afterGetResult(
115115
if (isset($args[self::SORT_KEY]) && isset($args[self::SORT_KEY][CategorySorting::NOSTO_PERSONALIZED_KEY])
116116
&& $this->getTotalPages() != 0) {
117117
return $this->searchResultFactory->create([
118-
'totalCount' => $searchResult->getTotalCount(),
118+
'totalCount' => $this->getTotalCount(),
119119
'productsSearchResult' => $searchResult->getProductsSearchResult(),
120120
'searchAggregation' => $searchResult->getSearchAggregation(),
121121
'pageSize' => $searchResult->getPageSize(),
@@ -138,4 +138,16 @@ private function getTotalPages()
138138
}
139139
return (int) ceil($batchModel->getTotalCount() / $batchModel->getLastUsedLimit());
140140
}
141+
142+
/**
143+
* @return int
144+
*/
145+
private function getTotalCount()
146+
{
147+
$batchModel = $this->sessionService->getBatchModel();
148+
if ($batchModel === null) {
149+
return 0;
150+
}
151+
return $batchModel->getTotalCount();
152+
}
141153
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nosto/module-nostocmp",
33
"description": "Nosto Category Merchandising extension for Magento 2",
44
"type": "magento2-module",
5-
"version": "4.0.0",
5+
"version": "4.0.1",
66
"require-dev": {
77
"magento-ecg/coding-standard": "3.*",
88
"magento/module-store": "101.1.2",

etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<!--suppress XmlUnboundNsPrefix -->
3838
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3939
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
40-
<module name="Nosto_Cmp" setup_version="4.0.0">
40+
<module name="Nosto_Cmp" setup_version="4.0.1">
4141
<sequence>
4242
<module name="Nosto_Tagging"/>
4343
</sequence>

0 commit comments

Comments
 (0)