Skip to content

Commit

Permalink
Merge pull request #15 from landofcoder/fix-graphql-issue
Browse files Browse the repository at this point in the history
fix missing score custom option when use smile elasticsuite
  • Loading branch information
landofcoder authored Jun 23, 2022
2 parents 30c0da3 + 20c9b2e commit e911bd9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Model/Resolver/Products/DataProvider/ProductSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -72,28 +73,36 @@ class ProductSearch
*/
private $searchCriteriaBuilder;

/**
* @var OptionInterfaceFactory
*/
private $optionFactory;

/**
* @param CollectionFactory $collectionFactory
* @param ProductSearchResultsInterfaceFactory $searchResultsFactory
* @param CollectionProcessorInterface $collectionPreProcessor
* @param CollectionPostProcessor $collectionPostProcessor
* @param SearchResultApplierFactory $searchResultsApplierFactory
* @param ProductCollectionSearchCriteriaBuilder $searchCriteriaBuilder
* @param OptionInterfaceFactory $optionFactory
*/
public function __construct(
CollectionFactory $collectionFactory,
ProductSearchResultsInterfaceFactory $searchResultsFactory,
CollectionProcessorInterface $collectionPreProcessor,
CollectionPostProcessor $collectionPostProcessor,
SearchResultApplierFactory $searchResultsApplierFactory,
ProductCollectionSearchCriteriaBuilder $searchCriteriaBuilder
ProductCollectionSearchCriteriaBuilder $searchCriteriaBuilder,
OptionInterfaceFactory $optionFactory
) {
$this->collectionFactory = $collectionFactory;
$this->searchResultsFactory = $searchResultsFactory;
$this->collectionPreProcessor = $collectionPreProcessor;
$this->collectionPostProcessor = $collectionPostProcessor;
$this->searchResultApplierFactory = $searchResultsApplierFactory;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->optionFactory = $optionFactory;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e911bd9

Please sign in to comment.