7
7
8
8
use Magento \Catalog \Api \CategoryRepositoryInterface ;
9
9
use Magento \Catalog \Api \Data \CategoryInterface ;
10
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
10
11
use Magento \Catalog \Model \Category ;
11
12
use Magento \Catalog \Model \Product ;
12
13
use Magento \CatalogUrlRewrite \Model \Product \AnchorUrlRewriteGenerator ;
@@ -78,6 +79,11 @@ class ProductScopeRewriteGenerator
78
79
*/
79
80
private $ categoryRepository ;
80
81
82
+ /**
83
+ * @var ProductRepositoryInterface
84
+ */
85
+ private $ productRepository ;
86
+
81
87
/**
82
88
* @param StoreViewService $storeViewService
83
89
* @param StoreManagerInterface $storeManager
@@ -89,6 +95,7 @@ class ProductScopeRewriteGenerator
89
95
* @param \Magento\UrlRewrite\Model\MergeDataProviderFactory|null $mergeDataProviderFactory
90
96
* @param CategoryRepositoryInterface|null $categoryRepository
91
97
* @param ScopeConfigInterface|null $config
98
+ * @param ProductRepositoryInterface|null $productRepository
92
99
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
93
100
*/
94
101
public function __construct (
@@ -101,7 +108,8 @@ public function __construct(
101
108
AnchorUrlRewriteGenerator $ anchorUrlRewriteGenerator ,
102
109
MergeDataProviderFactory $ mergeDataProviderFactory = null ,
103
110
CategoryRepositoryInterface $ categoryRepository = null ,
104
- ScopeConfigInterface $ config = null
111
+ ScopeConfigInterface $ config = null ,
112
+ ProductRepositoryInterface $ productRepository = null
105
113
) {
106
114
$ this ->storeViewService = $ storeViewService ;
107
115
$ this ->storeManager = $ storeManager ;
@@ -117,6 +125,8 @@ public function __construct(
117
125
$ this ->categoryRepository = $ categoryRepository ?:
118
126
ObjectManager::getInstance ()->get (CategoryRepositoryInterface::class);
119
127
$ this ->config = $ config ?: ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
128
+ $ this ->productRepository = $ productRepository ?:
129
+ ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
120
130
}
121
131
122
132
/**
@@ -144,15 +154,21 @@ public function generateForGlobalScope($productCategories, Product $product, $ro
144
154
$ mergeDataProvider = clone $ this ->mergeDataProviderPrototype ;
145
155
146
156
foreach ($ product ->getStoreIds () as $ id ) {
147
- if (!$ this ->isGlobalScope ($ id ) &&
148
- !$ this ->storeViewService ->doesEntityHaveOverriddenUrlKeyForStore (
157
+ if (!$ this ->isGlobalScope ($ id )) {
158
+ if ( !$ this ->storeViewService ->doesEntityHaveOverriddenUrlKeyForStore (
149
159
$ id ,
150
160
$ productId ,
151
161
Product::ENTITY
152
162
)) {
153
- $ mergeDataProvider ->merge (
154
- $ this ->generateForSpecificStoreView ($ id , $ productCategories , $ product , $ rootCategoryId )
155
- );
163
+ $ mergeDataProvider ->merge (
164
+ $ this ->generateForSpecificStoreView ($ id , $ productCategories , $ product , $ rootCategoryId )
165
+ );
166
+ } else {
167
+ $ scopedProduct = $ this ->productRepository ->getById ($ productId , false , $ id );
168
+ $ mergeDataProvider ->merge (
169
+ $ this ->generateForSpecificStoreView ($ id , $ productCategories , $ scopedProduct , $ rootCategoryId )
170
+ );
171
+ }
156
172
}
157
173
}
158
174
0 commit comments