@@ -79,53 +79,38 @@ public function __construct(
79
79
public function execute (array $ products , array $ storesToAdd ): void
80
80
{
81
81
foreach ($ products as $ product ) {
82
- $ urls = $ this ->getProductUrlRewrites ($ product , $ storesToAdd );
82
+ $ forceGenerateDefault = false ;
83
+ foreach ($ storesToAdd as $ storeId ) {
84
+ if ($ this ->needGenerateUrlForStore ($ product , (int )$ storeId )) {
85
+ $ urls [] = $ this ->generateUrls ($ product , (int )$ storeId );
86
+ } elseif ((int )$ product ->getStoreId () !== Store::DEFAULT_STORE_ID ) {
87
+ $ forceGenerateDefault = true ;
88
+ }
89
+ }
90
+ if ($ product ->getStoreId () === Store::DEFAULT_STORE_ID
91
+ || $ this ->isProductAssignedToStore ($ product )) {
92
+ $ product ->unsUrlPath ();
93
+ $ product ->setUrlPath ($ this ->productUrlPathGenerator ->getUrlPath ($ product ));
94
+ $ urls [] = $ this ->productUrlRewriteGenerator ->generate ($ product );
95
+ }
96
+ if ($ forceGenerateDefault && $ product ->getStoreId () !== Store::DEFAULT_STORE_ID ) {
97
+ $ urls [] = $ this ->generateUrls ($ product , Store::DEFAULT_STORE_ID );
98
+ }
83
99
$ this ->getDataByStore ->clearProductUrlRewriteDataCache ($ product );
84
100
}
85
101
if (!empty ($ urls )) {
86
102
$ this ->urlPersist ->replace (array_merge (...$ urls ));
87
103
}
88
104
}
89
105
90
- /**
91
- * Generate store product URLs
92
- *
93
- * @param ProductInterface $product
94
- * @param array $stores
95
- * @return array
96
- */
97
- public function getProductUrlRewrites (ProductInterface $ product , array $ stores ): array
98
- {
99
- $ urls = [];
100
- $ forceGenerateDefault = false ;
101
- foreach ($ stores as $ storeId ) {
102
- if ($ this ->needGenerateUrlForStore ($ product , (int )$ storeId )) {
103
- $ urls [] = $ this ->generateProductStoreUrls ($ product , (int )$ storeId );
104
- } elseif ((int )$ product ->getStoreId () !== Store::DEFAULT_STORE_ID ) {
105
- $ forceGenerateDefault = true ;
106
- }
107
- }
108
- if ($ product ->getStoreId () === Store::DEFAULT_STORE_ID
109
- || $ this ->isProductAssignedToStore ($ product )) {
110
- $ product ->unsUrlPath ();
111
- $ product ->setUrlPath ($ this ->productUrlPathGenerator ->getUrlPath ($ product ));
112
- $ urls [] = $ this ->productUrlRewriteGenerator ->generate ($ product );
113
- }
114
- if ($ forceGenerateDefault && $ product ->getStoreId () !== Store::DEFAULT_STORE_ID ) {
115
- $ urls [] = $ this ->generateProductStoreUrls ($ product , Store::DEFAULT_STORE_ID );
116
- }
117
-
118
- return $ urls ;
119
- }
120
-
121
106
/**
122
107
* Generate urls for specific store
123
108
*
124
109
* @param ProductInterface $product
125
110
* @param int $storeId
126
111
* @return array
127
112
*/
128
- private function generateProductStoreUrls (ProductInterface $ product , int $ storeId ): array
113
+ private function generateUrls (ProductInterface $ product , int $ storeId ): array
129
114
{
130
115
$ storeData = $ this ->getDataByStore ->execute ($ product , $ storeId );
131
116
$ origStoreId = $ product ->getStoreId ();
0 commit comments