@@ -195,6 +195,11 @@ class AfterImportDataObserver implements ObserverInterface
195
195
*/
196
196
private $ attributeValue ;
197
197
198
+ /**
199
+ * @var null|array
200
+ */
201
+ private $ cachedValues = null ;
202
+
198
203
/**
199
204
* @param ProductFactory $catalogProductFactory
200
205
* @param ObjectRegistryFactory $objectRegistryFactory
@@ -455,28 +460,29 @@ private function isGlobalScope($storeId)
455
460
private function canonicalUrlRewriteGenerate (array $ products )
456
461
{
457
462
$ urls = [];
458
- $ cachedValues = null ;
459
463
foreach ($ products as $ productId => $ productsByStores ) {
460
464
foreach ($ productsByStores as $ storeId => $ product ) {
461
465
if ($ this ->productUrlPathGenerator ->getUrlPath ($ product )) {
462
466
$ reqPath = $ this ->productUrlPathGenerator ->getUrlPathWithSuffix ($ product , $ storeId );
467
+ $ targetPath = $ this ->productUrlPathGenerator ->getCanonicalUrlPath ($ product );
463
468
if ((int ) $ storeId !== (int ) $ product ->getStoreId ()
464
469
&& $ this ->isGlobalScope ($ product ->getStoreId ())) {
465
- if ($ cachedValues === null ) {
466
- $ cachedValues = $ this ->getScopeBasedUrlKeyValues ($ products );
470
+ if ($ this -> cachedValues === null ) {
471
+ $ this -> cachedValues = $ this ->getScopeBasedUrlKeyValues ($ products );
467
472
}
468
- if (!empty ($ cachedValues ) && isset ($ cachedValues [$ productId ][$ storeId ])) {
473
+ if (!empty ($ this -> cachedValues ) && isset ($ this -> cachedValues [$ productId ][$ storeId ])) {
469
474
$ storeProduct = clone $ product ;
470
475
$ storeProduct ->setStoreId ($ storeId );
471
- $ storeProduct ->setUrlKey ($ cachedValues [$ productId ][$ storeId ]);
476
+ $ storeProduct ->setUrlKey ($ this -> cachedValues [$ productId ][$ storeId ]);
472
477
$ reqPath = $ this ->productUrlPathGenerator ->getUrlPathWithSuffix ($ storeProduct , $ storeId );
478
+ $ targetPath = $ this ->productUrlPathGenerator ->getCanonicalUrlPath ($ storeProduct );
473
479
}
474
480
}
475
481
$ urls [] = $ this ->urlRewriteFactory ->create ()
476
482
->setEntityType (ProductUrlRewriteGenerator::ENTITY_TYPE )
477
483
->setEntityId ($ productId )
478
484
->setRequestPath ($ reqPath )
479
- ->setTargetPath ($ this -> productUrlPathGenerator -> getCanonicalUrlPath ( $ product ) )
485
+ ->setTargetPath ($ targetPath )
480
486
->setStoreId ($ storeId );
481
487
}
482
488
}
@@ -637,6 +643,20 @@ private function generateForCustom(UrlRewrite $url, ?Category $category, array $
637
643
$ targetPath = $ url ->getRedirectType ()
638
644
? $ this ->productUrlPathGenerator ->getUrlPathWithSuffix ($ product , $ storeId , $ category )
639
645
: $ url ->getTargetPath ();
646
+ if ((int ) $ storeId !== (int ) $ product ->getStoreId ()
647
+ && $ this ->isGlobalScope ($ product ->getStoreId ())) {
648
+ if ($ this ->cachedValues === null ) {
649
+ $ this ->cachedValues = $ this ->getScopeBasedUrlKeyValues ($ products );
650
+ }
651
+ if (!empty ($ this ->cachedValues ) && isset ($ this ->cachedValues [$ productId ][$ storeId ])) {
652
+ $ storeProduct = clone $ product ;
653
+ $ storeProduct ->setStoreId ($ storeId );
654
+ $ storeProduct ->setUrlKey ($ this ->cachedValues [$ productId ][$ storeId ]);
655
+ $ targetPath = $ url ->getRedirectType ()
656
+ ? $ this ->productUrlPathGenerator ->getUrlPathWithSuffix ($ storeProduct , $ storeId , $ category )
657
+ : $ url ->getTargetPath ();
658
+ }
659
+ }
640
660
if ($ url ->getRequestPath () === $ targetPath ) {
641
661
return [];
642
662
}
0 commit comments