From 20c9b2e47ee5aa411a73034c9b6fe1ef7f7d21b4 Mon Sep 17 00:00:00 2001 From: Misha Date: Thu, 23 Jun 2022 19:38:05 +0700 Subject: [PATCH] fix missing score custom option when use smile elasticsuite --- .../Products/DataProvider/ProductSearch.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Model/Resolver/Products/DataProvider/ProductSearch.php b/Model/Resolver/Products/DataProvider/ProductSearch.php index 75bf875..f732820 100755 --- a/Model/Resolver/Products/DataProvider/ProductSearch.php +++ b/Model/Resolver/Products/DataProvider/ProductSearch.php @@ -36,6 +36,7 @@ use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Framework\Api\SearchResultsInterface; use Magento\GraphQl\Model\Query\ContextInterface; +use Magento\Customer\Api\Data\OptionInterfaceFactory; /** * Product field data provider for product search, used for GraphQL resolver processing. @@ -72,6 +73,11 @@ class ProductSearch */ private $searchCriteriaBuilder; + /** + * @var OptionInterfaceFactory + */ + private $optionFactory; + /** * @param CollectionFactory $collectionFactory * @param ProductSearchResultsInterfaceFactory $searchResultsFactory @@ -79,6 +85,7 @@ class ProductSearch * @param CollectionPostProcessor $collectionPostProcessor * @param SearchResultApplierFactory $searchResultsApplierFactory * @param ProductCollectionSearchCriteriaBuilder $searchCriteriaBuilder + * @param OptionInterfaceFactory $optionFactory */ public function __construct( CollectionFactory $collectionFactory, @@ -86,7 +93,8 @@ public function __construct( CollectionProcessorInterface $collectionPreProcessor, CollectionPostProcessor $collectionPostProcessor, SearchResultApplierFactory $searchResultsApplierFactory, - ProductCollectionSearchCriteriaBuilder $searchCriteriaBuilder + ProductCollectionSearchCriteriaBuilder $searchCriteriaBuilder, + OptionInterfaceFactory $optionFactory ) { $this->collectionFactory = $collectionFactory; $this->searchResultsFactory = $searchResultsFactory; @@ -94,6 +102,7 @@ public function __construct( $this->collectionPostProcessor = $collectionPostProcessor; $this->searchResultApplierFactory = $searchResultsApplierFactory; $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->optionFactory = $optionFactory; } /** @@ -129,7 +138,10 @@ public function getList( if (get_class($_item) == "Smile\\ElasticsuiteCore\\Search\\Adapter\\Elasticsuite\\Response\\Document") { $score = $_item->getCustomAttribute('score'); if (!$score) { - $_item->setCustomAttribute('score', ''); + $scoreOption = $this->optionFactory->create(); + $scoreOption->setLabel("score"); + $scoreOption->setValue(1); + $_item->setCustomAttribute('score', $scoreOption); } $items[] = $_item; }