diff --git a/vendor/magento/module-catalog-url-rewrite/Model/ProductScopeRewriteGenerator.php b/vendor/magento/module-catalog-url-rewrite/Model/ProductScopeRewriteGenerator.php index 7bf1da2b814..e68b38b046a 100644 --- a/vendor/magento/module-catalog-url-rewrite/Model/ProductScopeRewriteGenerator.php +++ b/vendor/magento/module-catalog-url-rewrite/Model/ProductScopeRewriteGenerator.php @@ -7,6 +7,7 @@ namespace Magento\CatalogUrlRewrite\Model; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Api\Data\CategoryInterface; +use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Model\Category; use Magento\Catalog\Model\Product; use Magento\CatalogUrlRewrite\Model\Product\AnchorUrlRewriteGenerator; @@ -78,6 +79,11 @@ class ProductScopeRewriteGenerator */ private $categoryRepository; + /** + * @var ProductRepositoryInterface + */ + private $productRepository; + /** * @param StoreViewService $storeViewService * @param StoreManagerInterface $storeManager @@ -89,6 +95,7 @@ class ProductScopeRewriteGenerator * @param \Magento\UrlRewrite\Model\MergeDataProviderFactory|null $mergeDataProviderFactory * @param CategoryRepositoryInterface|null $categoryRepository * @param ScopeConfigInterface|null $config + * @param ProductRepositoryInterface|null $productRepository * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -101,7 +108,8 @@ class ProductScopeRewriteGenerator AnchorUrlRewriteGenerator $anchorUrlRewriteGenerator, MergeDataProviderFactory $mergeDataProviderFactory = null, CategoryRepositoryInterface $categoryRepository = null, - ScopeConfigInterface $config = null + ScopeConfigInterface $config = null, + ProductRepositoryInterface $productRepository = null ) { $this->storeViewService = $storeViewService; $this->storeManager = $storeManager; @@ -117,6 +125,8 @@ class ProductScopeRewriteGenerator $this->categoryRepository = $categoryRepository ?: ObjectManager::getInstance()->get(CategoryRepositoryInterface::class); $this->config = $config ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); + $this->productRepository = $productRepository ?: + ObjectManager::getInstance()->get(ProductRepositoryInterface::class); } /** @@ -144,15 +154,21 @@ class ProductScopeRewriteGenerator $mergeDataProvider = clone $this->mergeDataProviderPrototype; foreach ($product->getStoreIds() as $id) { - if (!$this->isGlobalScope($id) && - !$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore( + if (!$this->isGlobalScope($id)) { + if (!$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore( $id, $productId, Product::ENTITY )) { - $mergeDataProvider->merge( - $this->generateForSpecificStoreView($id, $productCategories, $product, $rootCategoryId) - ); + $mergeDataProvider->merge( + $this->generateForSpecificStoreView($id, $productCategories, $product, $rootCategoryId) + ); + } else { + $scopedProduct = $this->productRepository->getById($productId, false, $id); + $mergeDataProvider->merge( + $this->generateForSpecificStoreView($id, $productCategories, $scopedProduct, $rootCategoryId) + ); + } } }