diff --git a/vendor/magento/module-shared-catalog-graph-ql/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/ApplyCategoryPermissionsOnProductProcessor.php b/vendor/magento/module-shared-catalog-graph-ql/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/ApplyCategoryPermissionsOnProductProcessor.php new file mode 100644 index 00000000000..876de77311e --- /dev/null +++ b/vendor/magento/module-shared-catalog-graph-ql/Model/Resolver/Products/DataProvider/Product/CollectionProcessor/ApplyCategoryPermissionsOnProductProcessor.php @@ -0,0 +1,97 @@ +config = $config; + $this->customerGroupManagement = $customerGroupManagement; + $this->groupProcessor = $groupProcessor; + } + + /** + * Process collection to add additional joins, attributes, and clauses to a product collection. + * + * @param Collection $collection + * @param SearchCriteriaInterface $searchCriteria + * @param array $attributeNames + * @param ContextInterface|null $context + * @return Collection + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function process( + Collection $collection, + SearchCriteriaInterface $searchCriteria, + array $attributeNames, + ContextInterface $context = null + ): Collection { + if (!$context) { + return $collection; + } + /** @var StoreInterface $store */ + $store = $context->getExtensionAttributes()->getStore(); + $customerGroupId = $this->groupProcessor->getCustomerGroup($context); + $website = $store->getWebsite()->getId(); + if (!$collection->hasFlag(self::SHARED_CATALOG_FILTER) + && $this->config->isActive(ScopeInterface::SCOPE_WEBSITE, $website) + && !$this->customerGroupManagement->isPrimaryCatalogAvailable($customerGroupId) + ) { + $collection->joinTable( + ['shared_product' => $collection->getTable( + 'shared_catalog_product_item' + )], + 'sku = sku', + ['customer_group_id'], + '{{table}}.customer_group_id = \'' . $customerGroupId . '\'' + ); + + $collection->setFlag(self::SHARED_CATALOG_FILTER, true); + } + return $collection; + } +} diff --git a/vendor/magento/module-shared-catalog-graph-ql/etc/di.xml b/vendor/magento/module-shared-catalog-graph-ql/etc/di.xml new file mode 100644 index 00000000000..2a1ce3e7fe4 --- /dev/null +++ b/vendor/magento/module-shared-catalog-graph-ql/etc/di.xml @@ -0,0 +1,16 @@ + + + + + + + Magento\SharedCatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessor\ApplyCategoryPermissionsOnProductProcessor + + + + diff --git a/vendor/magento/module-shared-catalog-graph-ql/etc/module.xml b/vendor/magento/module-shared-catalog-graph-ql/etc/module.xml index 3ea2e083184..d3c025ed6a4 100755 --- a/vendor/magento/module-shared-catalog-graph-ql/etc/module.xml +++ b/vendor/magento/module-shared-catalog-graph-ql/etc/module.xml @@ -9,7 +9,7 @@ - +