Skip to content

Commit

Permalink
Merge pull request #169 from Nosto/release/5.3.0
Browse files Browse the repository at this point in the history
Release 5.3.0
  • Loading branch information
supercid authored Apr 11, 2023
2 parents 35d2609 + bda8277 commit 8c964dc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

### 5.3.0
* Improve compatibility with Magento 2.4.6

### 5.2.2
* Restore totalPrimaryCount result from GraphQL query as product count in order to fix an issue with pagination.

Expand Down
90 changes: 90 additions & 0 deletions Plugin/Api/Search/SearchResultApplier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Copyright (c) 2020, Nosto Solutions Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Nosto Solutions Ltd <contact@nosto.com>
* @copyright 2020 Nosto Solutions Ltd
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
*
*/

namespace Nosto\Cmp\Plugin\Api\Search;

use Magento\Framework\DB\Select;
use Nosto\Cmp\Model\Service\Merchandise\LastResult;
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
use Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier as ESearchResultApplier;
use Zend_Db_Expr;

class SearchResultApplier
{

/** @var Collection */
private Collection $collection;

/** @var LastResult */
private LastResult $lastResult;

/**
* @param LastResult $lastResult
* @param Collection $collection
*/
public function __construct(
LastResult $lastResult,
Collection $collection
) {
$this->lastResult = $lastResult;
$this->collection = $collection;
}

/**
* @param ESearchResultApplier $subject
* @param $result
* @return mixed
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @noinspection PhpUnused
* @noinspection PhpUnusedParameterInspection
*/
public function afterApply(// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
ESearchResultApplier $subject,
$result
) {
$cmResult = $this->lastResult->getLastResult();
if ($cmResult !== null) {
$productIds = $cmResult->parseProductIds();
$orderList = implode(',', $productIds);
$this->collection->getSelect()
->where('e.entity_id IN (?)', $productIds)
->reset(Select::ORDER)
->order(new Zend_Db_Expr("FIELD(e.entity_id,$orderList)"));

}
return $result;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nosto/module-nostocmp",
"description": "Nosto Category Merchandising extension for Magento 2",
"type": "magento2-module",
"version": "5.2.2",
"version": "5.3.0",
"require-dev": {
"magento-ecg/coding-standard": "3.*",
"magento/module-store": "101.1.2",
Expand Down
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<type name="Magento\Framework\Api\Search\SearchResult">
<plugin name="nosto_search_result_sort" type="Nosto\Cmp\Plugin\Api\Search\SearchResultSorter"/>
</type>
<type name="Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier">
<plugin name="nosto_search_result_applier" type="Nosto\Cmp\Plugin\Api\Search\SearchResultApplier" sortOrder="1" disabled="false" />
</type>

<type name="Magento\Catalog\Block\Product\ListProduct">
<plugin name="nosto_search_result_sort" type="Nosto\Cmp\Plugin\Catalog\Block\ListProduct"/>
</type>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<!--suppress XmlUnboundNsPrefix -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Nosto_Cmp" setup_version="5.2.2">
<module name="Nosto_Cmp" setup_version="5.3.0">
<sequence>
<module name="Nosto_Tagging"/>
</sequence>
Expand Down

0 comments on commit 8c964dc

Please sign in to comment.