diff --git a/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/Identity.php b/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/Identity.php index 7aec66ccb69..aff8fa8a6fc 100644 --- a/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/Identity.php +++ b/vendor/magento/module-catalog-graph-ql/Model/Resolver/Product/Identity.php @@ -8,6 +8,8 @@ declare(strict_types=1); namespace Magento\CatalogGraphQl\Model\Resolver\Product; use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface; +use Magento\Catalog\Model\Category; +use Magento\Catalog\Model\Product; /** * Identity for resolved products @@ -15,7 +17,8 @@ use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface; class Identity implements IdentityInterface { /** @var string */ - private $cacheTag = \Magento\Catalog\Model\Product::CACHE_TAG; + private $cacheTagProduct = Product::CACHE_TAG; + private $cacheTagCategory = Category::CACHE_TAG; /** * Get product ids for cache tag @@ -26,12 +29,19 @@ class Identity implements IdentityInterface public function getIdentities(array $resolvedData): array { $ids = []; + $categories = $resolvedData['categories'] ?? []; $items = $resolvedData['items'] ?? []; + foreach ($categories as $category) { + $ids[] = sprintf('%s_%s', $this->cacheTagCategory, $category); + } + if (!empty($categories)) { + array_unshift($ids, $this->cacheTagCategory); + } foreach ($items as $item) { - $ids[] = sprintf('%s_%s', $this->cacheTag, $item['entity_id']); + $ids[] = sprintf('%s_%s', $this->cacheTagProduct, $item['entity_id']); } if (!empty($ids)) { - array_unshift($ids, $this->cacheTag); + array_unshift($ids, $this->cacheTagProduct); } return $ids; diff --git a/vendor/magento/module-catalog-graph-ql/Model/Resolver/Products.php b/vendor/magento/module-catalog-graph-ql/Model/Resolver/Products.php index 2ba20b56df1..04a8d84ddfe 100644 --- a/vendor/magento/module-catalog-graph-ql/Model/Resolver/Products.php +++ b/vendor/magento/module-catalog-graph-ql/Model/Resolver/Products.php @@ -122,6 +122,11 @@ class Products implements ResolverInterface 'layer_type' => isset($args['search']) ? Resolver::CATALOG_LAYER_SEARCH : Resolver::CATALOG_LAYER_CATEGORY, ]; + if (isset($args['filter']['category_id'])) { + $data['categories'] = $args['filter']['category_id']['eq'] ?? $args['filter']['category_id']['in']; + $data['categories'] = is_array($data['categories']) ? $data['categories'] : [$data['categories']]; + } + return $data; } }