diff --git a/vendor/magento/module-catalog-url-rewrite-graph-ql/Plugin/Model/Resolver/EntityUrlExcludeDisabledProductPlugin.php b/vendor/magento/module-catalog-url-rewrite-graph-ql/Plugin/Model/Resolver/EntityUrlExcludeDisabledProductPlugin.php new file mode 100644 index 0000000000000..4899f2b5b4717 --- /dev/null +++ b/vendor/magento/module-catalog-url-rewrite-graph-ql/Plugin/Model/Resolver/EntityUrlExcludeDisabledProductPlugin.php @@ -0,0 +1,85 @@ +productResource = $productResource; + } + + /** + * After plugin for EntityUrl resolver to exclude disabled products + * + * @param EntityUrl $subject + * @param array|null $result + * @param Field $field + * @param mixed $context + * @param ResolveInfo $info + * @param array|null $value + * @param array|null $args + * @return array|null + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterResolve( + EntityUrl $subject, + ?array $result, + Field $field, + $context, + ResolveInfo $info, + ?array $value = null, + ?array $args = null + ): ?array { + if ($result === null || strtolower($result['type'] ?? '') !== self::TYPE_PRODUCT || empty($result['id'])) { + return $result; + } + $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); + $cacheKey = $result['id'] . '_' . $storeId; + if (!array_key_exists($cacheKey, $this->statusCache)) { + $this->statusCache[$cacheKey] = $this->productResource->getAttributeRawValue( + (int)$result['id'], + 'status', + $storeId + ); + } + $status = $this->statusCache[$cacheKey]; + if ($status === false || (int)$status !== Status::STATUS_ENABLED) { + return null; + } + return $result; + } +} diff --git a/vendor/magento/module-catalog-url-rewrite-graph-ql/etc/di.xml b/vendor/magento/module-catalog-url-rewrite-graph-ql/etc/di.xml index cb7362717fff6..cdb55aa9582d3 100644 --- a/vendor/magento/module-catalog-url-rewrite-graph-ql/etc/di.xml +++ b/vendor/magento/module-catalog-url-rewrite-graph-ql/etc/di.xml @@ -39,4 +39,8 @@ + + +