Skip to content

Commit 7bfbc23

Browse files
committed
MC-18450: Allow custom attributes to be filterable and also returned in the layered navigation the product filter section in GraphQL
- address review comments
1 parent 81a521b commit 7bfbc23

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

app/code/Magento/CatalogGraphQl/Model/Config/FilterAttributeReader.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,24 @@ class FilterAttributeReader implements ReaderInterface
4545
*/
4646
private $collectionFactory;
4747

48+
/**
49+
* @var array
50+
*/
51+
private $exactMatchAttributes = ['sku'];
52+
4853
/**
4954
* @param MapperInterface $mapper
5055
* @param CollectionFactory $collectionFactory
56+
* @param array $exactMatchAttributes
5157
*/
5258
public function __construct(
5359
MapperInterface $mapper,
54-
CollectionFactory $collectionFactory
60+
CollectionFactory $collectionFactory,
61+
array $exactMatchAttributes = []
5562
) {
5663
$this->mapper = $mapper;
5764
$this->collectionFactory = $collectionFactory;
65+
$this->exactMatchAttributes = array_merge($this->exactMatchAttributes, $exactMatchAttributes);
5866
}
5967

6068
/**
@@ -94,7 +102,7 @@ public function read($scope = null) : array
94102
*/
95103
private function getFilterType(Attribute $attribute): string
96104
{
97-
if ($attribute->getAttributeCode() === 'sku') {
105+
if (in_array($attribute->getAttributeCode(), $this->exactMatchAttributes)) {
98106
return self::FILTER_EQUAL_TYPE;
99107
}
100108

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ProductSearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getList(
9595
$searchResults = $this->searchResultsFactory->create();
9696
$searchResults->setSearchCriteria($searchCriteria);
9797
$searchResults->setItems($collection->getItems());
98-
$searchResults->setTotalCount($collection->getSize());
98+
$searchResults->setTotalCount($searchResult->getTotalCount());
9999
return $searchResults;
100100
}
101101

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ type ProductMediaGalleryEntriesVideoContent @doc(description: "ProductMediaGalle
338338
video_metadata: String @doc(description: "Optional data about the video.")
339339
}
340340

341-
input ProductSortInput @deprecated(reason: "The attributes used in this input are hard-coded, and some of them are not sortable. Use @ProductAttributeSortInput instead") @doc(description: "ProductSortInput specifies the attribute to use for sorting search results and indicates whether the results are sorted in ascending or descending order.") {
341+
input ProductSortInput @doc(description: "ProductSortInput is deprecated, use @ProductAttributeSortInput instead. ProductSortInput specifies the attribute to use for sorting search results and indicates whether the results are sorted in ascending or descending order.") {
342342
name: SortEnum @doc(description: "The product name. Customers use this name to identify the product.")
343343
sku: SortEnum @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer.")
344344
description: SortEnum @doc(description: "Detailed information about the product. The value can include simple HTML tags.")

0 commit comments

Comments
 (0)