@@ -84,33 +84,13 @@ public function execute($entity, $arguments = [])
84
84
$ websiteId = $ this ->storeManager ->getStore ($ entity ->getStoreId ())->getWebsiteId ();
85
85
$ isGlobal = $ attribute ->isScopeGlobal () || $ websiteId === 0 ;
86
86
$ identifierField = $ this ->metadataPoll ->getMetadata (ProductInterface::class)->getLinkField ();
87
- $ priceRows = array_filter ($ priceRows );
88
87
$ productId = $ entity ->getData ($ identifierField );
89
- $ old = [];
90
- $ new = [];
91
88
92
- // prepare original data for compare
89
+ // prepare original data to compare
93
90
$ origPrices = $ entity ->getOrigData ($ attribute ->getName ());
94
- if (is_array ($ origPrices )) {
95
- foreach ($ origPrices as $ data ) {
96
- if ($ isGlobal === $ this ->isWebsiteGlobal ((int )$ data ['website_id ' ])) {
97
- $ key = $ this ->getPriceKey ($ data );
98
- $ old [$ key ] = $ data ;
99
- }
100
- }
101
- }
102
-
91
+ $ old = $ this ->prepareOriginalDataToCompare ($ origPrices , $ isGlobal );
103
92
// prepare data for save
104
- foreach ($ priceRows as $ data ) {
105
- if (empty ($ data ['delete ' ])
106
- && (!empty ($ data ['price_qty ' ])
107
- || isset ($ data ['cust_group ' ])
108
- || $ isGlobal === $ this ->isWebsiteGlobal ((int )$ data ['website_id ' ]))
109
- ) {
110
- $ key = $ this ->getPriceKey ($ data );
111
- $ new [$ key ] = $ this ->prepareTierPrice ($ data );
112
- }
113
- }
93
+ $ new = $ this ->prepareNewDataForSave ($ priceRows , $ isGlobal );
114
94
115
95
$ delete = array_diff_key ($ old , $ new );
116
96
$ insert = array_diff_key ($ new , $ old );
@@ -279,4 +259,48 @@ private function isWebsiteGlobal(int $websiteId): bool
279
259
{
280
260
return $ websiteId === 0 ;
281
261
}
262
+
263
+ /**
264
+ * @param $origPrices
265
+ * @param bool $isGlobal
266
+ * @return array
267
+ */
268
+ private function prepareOriginalDataToCompare ($ origPrices , $ isGlobal = true ): array
269
+ {
270
+ $ old = [];
271
+ if (is_array ($ origPrices )) {
272
+ foreach ($ origPrices as $ data ) {
273
+ if ($ isGlobal === $ this ->isWebsiteGlobal ((int )$ data ['website_id ' ])) {
274
+ $ key = $ this ->getPriceKey ($ data );
275
+ $ old [$ key ] = $ data ;
276
+ }
277
+ }
278
+ }
279
+
280
+ return $ old ;
281
+ }
282
+
283
+ /**
284
+ * @param $priceRows
285
+ * @param bool $isGlobal
286
+ * @return array
287
+ * @throws \Magento\Framework\Exception\LocalizedException
288
+ */
289
+ private function prepareNewDataForSave ($ priceRows , $ isGlobal = true ): array
290
+ {
291
+ $ new = [];
292
+ $ priceRows = array_filter ($ priceRows );
293
+ foreach ($ priceRows as $ data ) {
294
+ if (empty ($ data ['delete ' ])
295
+ && (!empty ($ data ['price_qty ' ])
296
+ || isset ($ data ['cust_group ' ])
297
+ || $ isGlobal === $ this ->isWebsiteGlobal ((int )$ data ['website_id ' ]))
298
+ ) {
299
+ $ key = $ this ->getPriceKey ($ data );
300
+ $ new [$ key ] = $ this ->prepareTierPrice ($ data );
301
+ }
302
+ }
303
+
304
+ return $ new ;
305
+ }
282
306
}
0 commit comments