@@ -467,15 +467,8 @@ private function canonicalUrlRewriteGenerate(array $products)
467
467
$ targetPath = $ this ->productUrlPathGenerator ->getCanonicalUrlPath ($ product );
468
468
if ((int ) $ storeId !== (int ) $ product ->getStoreId ()
469
469
&& $ this ->isGlobalScope ($ product ->getStoreId ())) {
470
- if ($ this ->cachedValues === null ) {
471
- $ this ->cachedValues = $ this ->getScopeBasedUrlKeyValues ($ products );
472
- }
473
- if (!empty ($ this ->cachedValues ) && isset ($ this ->cachedValues [$ productId ][$ storeId ])) {
474
- $ storeProduct = clone $ product ;
475
- $ storeProduct ->setStoreId ($ storeId );
476
- $ storeProduct ->setUrlKey ($ this ->cachedValues [$ productId ][$ storeId ]);
477
- $ reqPath = $ this ->productUrlPathGenerator ->getUrlPathWithSuffix ($ storeProduct , $ storeId );
478
- }
470
+ $ this ->initializeCacheForProducts ($ products );
471
+ $ reqPath = $ this ->getReqPath ((int )$ productId , (int )$ storeId , $ product );
479
472
}
480
473
$ urls [] = $ this ->urlRewriteFactory ->create ()
481
474
->setEntityType (ProductUrlRewriteGenerator::ENTITY_TYPE )
@@ -489,6 +482,40 @@ private function canonicalUrlRewriteGenerate(array $products)
489
482
return $ urls ;
490
483
}
491
484
485
+ /**
486
+ * Initialization for cache with scop based values
487
+ *
488
+ * @param array $products
489
+ * @return void
490
+ */
491
+ private function initializeCacheForProducts (array $ products ) : void
492
+ {
493
+ if ($ this ->cachedValues === null ) {
494
+ $ this ->cachedValues = $ this ->getScopeBasedUrlKeyValues ($ products );
495
+ }
496
+ }
497
+
498
+ /**
499
+ * Get request path for the selected scope
500
+ *
501
+ * @param int $productId
502
+ * @param int $storeId
503
+ * @param Product $product
504
+ * @pram Category|null $category
505
+ * @return string
506
+ */
507
+ private function getReqPath (int $ productId , int $ storeId , Product $ product , ?Category $ category = null ) : string
508
+ {
509
+ $ reqPath = $ this ->productUrlPathGenerator ->getUrlPathWithSuffix ($ product , $ storeId , $ category );
510
+ if (!empty ($ this ->cachedValues ) && isset ($ this ->cachedValues [$ productId ][$ storeId ])) {
511
+ $ storeProduct = clone $ product ;
512
+ $ storeProduct ->setStoreId ($ storeId );
513
+ $ storeProduct ->setUrlKey ($ this ->cachedValues [$ productId ][$ storeId ]);
514
+ $ reqPath = $ this ->productUrlPathGenerator ->getUrlPathWithSuffix ($ storeProduct , $ storeId , $ category );
515
+ }
516
+ return $ reqPath ;
517
+ }
518
+
492
519
/**
493
520
* Get url key attribute values for the specified scope
494
521
*
@@ -541,19 +568,8 @@ private function categoriesUrlRewriteGenerate(array $products): array
541
568
$ targetPath = $ this ->productUrlPathGenerator ->getCanonicalUrlPath ($ product , $ category );
542
569
if ((int ) $ storeId !== (int ) $ product ->getStoreId ()
543
570
&& $ this ->isGlobalScope ($ product ->getStoreId ())) {
544
- if ($ this ->cachedValues === null ) {
545
- $ this ->cachedValues = $ this ->getScopeBasedUrlKeyValues ($ products );
546
- }
547
- if (!empty ($ this ->cachedValues ) && isset ($ this ->cachedValues [$ productId ][$ storeId ])) {
548
- $ storeProduct = clone $ product ;
549
- $ storeProduct ->setStoreId ($ storeId );
550
- $ storeProduct ->setUrlKey ($ this ->cachedValues [$ productId ][$ storeId ]);
551
- $ requestPath = $ this ->productUrlPathGenerator ->getUrlPathWithSuffix (
552
- $ storeProduct ,
553
- $ storeId ,
554
- $ category
555
- );
556
- }
571
+ $ this ->initializeCacheForProducts ($ products );
572
+ $ requestPath = $ this ->getReqPath ($ productId , $ storeId , $ product , $ category );
557
573
}
558
574
$ urls [] = [
559
575
$ this ->urlRewriteFactory ->create ()
@@ -662,9 +678,7 @@ private function generateForCustom(UrlRewrite $url, ?Category $category, array $
662
678
: $ url ->getTargetPath ();
663
679
if ((int ) $ storeId !== (int ) $ product ->getStoreId ()
664
680
&& $ this ->isGlobalScope ($ product ->getStoreId ())) {
665
- if ($ this ->cachedValues === null ) {
666
- $ this ->cachedValues = $ this ->getScopeBasedUrlKeyValues ($ products );
667
- }
681
+ $ this ->initializeCacheForProducts ($ products );
668
682
if (!empty ($ this ->cachedValues ) && isset ($ this ->cachedValues [$ productId ][$ storeId ])) {
669
683
$ storeProduct = clone $ product ;
670
684
$ storeProduct ->setStoreId ($ storeId );
0 commit comments