@@ -119,6 +119,18 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
119
119
*/
120
120
protected $ _permanentAttributes = [self ::COL_SKU ];
121
121
122
+ /**
123
+ * Catalog product entity
124
+ *
125
+ * @var string
126
+ */
127
+ protected $ _catalogProductEntity ;
128
+
129
+ /**
130
+ * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
131
+ */
132
+ protected $ _localeDate ;
133
+
122
134
/**
123
135
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
124
136
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
@@ -136,6 +148,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
136
148
* @param AdvancedPricing\Validator\GroupPrice $groupPriceValidator
137
149
*/
138
150
public function __construct (
151
+ \Magento \Framework \Stdlib \DateTime \TimezoneInterface $ localeDate ,
139
152
\Magento \Framework \Json \Helper \Data $ jsonHelper ,
140
153
\Magento \ImportExport \Helper \Data $ importExportData ,
141
154
\Magento \ImportExport \Model \Resource \Helper $ resourceHelper ,
@@ -150,6 +163,7 @@ public function __construct(
150
163
AdvancedPricing \Validator \Website $ websiteValidator ,
151
164
AdvancedPricing \Validator \GroupPrice $ groupPriceValidator
152
165
) {
166
+ $ this ->_localeDate = $ localeDate ;
153
167
$ this ->jsonHelper = $ jsonHelper ;
154
168
$ this ->_importExportData = $ importExportData ;
155
169
$ this ->_resourceHelper = $ resourceHelper ;
@@ -164,6 +178,7 @@ public function __construct(
164
178
$ this ->_oldSkus = $ this ->retrieveOldSkus ();
165
179
$ this ->websiteValidator = $ websiteValidator ;
166
180
$ this ->groupPriceValidator = $ groupPriceValidator ;
181
+ $ this ->_catalogProductEntity = $ this ->_resourceFactory ->create ()->getTable ('catalog_product_entity ' );
167
182
}
168
183
169
184
/**
@@ -262,6 +277,7 @@ public function deleteAdvancedPricing()
262
277
if ($ listSku ) {
263
278
$ this ->deleteProductTierAndGroupPrices (array_unique ($ listSku ), self ::TABLE_GROUPED_PRICE );
264
279
$ this ->deleteProductTierAndGroupPrices (array_unique ($ listSku ), self ::TABLE_TIER_PRICE );
280
+ $ this ->setUpdatedAt ($ listSku );
265
281
}
266
282
return $ this ;
267
283
}
@@ -287,8 +303,8 @@ protected function saveAndReplaceAdvancedPrices()
287
303
$ behavior = $ this ->getBehavior ();
288
304
if (\Magento \ImportExport \Model \Import::BEHAVIOR_REPLACE == $ behavior ) {
289
305
$ this ->_cachedSkuToDelete = null ;
290
- $ listSku = [];
291
306
}
307
+ $ listSku = [];
292
308
while ($ bunch = $ this ->_dataSourceModel ->getNextBunch ()) {
293
309
$ tierPrices = [];
294
310
$ groupPrices = [];
@@ -298,9 +314,7 @@ protected function saveAndReplaceAdvancedPrices()
298
314
continue ;
299
315
}
300
316
$ rowSku = $ rowData [self ::COL_SKU ];
301
- if (\Magento \ImportExport \Model \Import::BEHAVIOR_REPLACE == $ behavior ) {
302
- $ listSku [] = $ rowSku ;
303
- }
317
+ $ listSku [] = $ rowSku ;
304
318
if (!empty ($ rowData [self ::COL_TIER_PRICE_WEBSITE ])) {
305
319
$ tierPrices [$ rowSku ][] = [
306
320
'all_groups ' => $ rowData [self ::COL_TIER_PRICE_CUSTOMER_GROUP ] == self ::VALUE_ALL_GROUPS ,
@@ -330,6 +344,7 @@ protected function saveAndReplaceAdvancedPrices()
330
344
&& $ this ->deleteProductTierAndGroupPrices (array_unique ($ listSku ), self ::TABLE_TIER_PRICE )) {
331
345
$ this ->saveProductPrices ($ tierPrices , self ::TABLE_TIER_PRICE )
332
346
->saveProductPrices ($ groupPrices , self ::TABLE_GROUPED_PRICE );
347
+ $ this ->setUpdatedAt ($ listSku );
333
348
}
334
349
}
335
350
} elseif (\Magento \ImportExport \Model \Import::BEHAVIOR_APPEND == $ behavior ) {
@@ -338,6 +353,9 @@ protected function saveAndReplaceAdvancedPrices()
338
353
->processCountNewPrices ($ tierPrices , $ groupPrices );
339
354
$ this ->saveProductPrices ($ tierPrices , self ::TABLE_TIER_PRICE )
340
355
->saveProductPrices ($ groupPrices , self ::TABLE_GROUPED_PRICE );
356
+ if ($ listSku ) {
357
+ $ this ->setUpdatedAt ($ listSku );
358
+ }
341
359
}
342
360
}
343
361
return $ this ;
@@ -355,12 +373,14 @@ protected function saveProductPrices(array $priceData, $table)
355
373
if ($ priceData ) {
356
374
$ tableName = $ this ->_resourceFactory ->create ()->getTable ($ table );
357
375
$ priceIn = [];
376
+ $ entityIds = [];
358
377
foreach ($ priceData as $ sku => $ priceRows ) {
359
378
if (isset ($ this ->_oldSkus [$ sku ])) {
360
379
$ productId = $ this ->_oldSkus [$ sku ];
361
380
foreach ($ priceRows as $ row ) {
362
381
$ row ['entity_id ' ] = $ productId ;
363
382
$ priceIn [] = $ row ;
383
+ $ entityIds [] = $ productId ;
364
384
}
365
385
}
366
386
}
@@ -384,8 +404,8 @@ protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
384
404
if (!$ this ->_cachedSkuToDelete ) {
385
405
$ this ->_cachedSkuToDelete = $ this ->_connection ->fetchCol (
386
406
$ this ->_connection ->select ()
387
- ->from ($ this ->_connection -> getTableName ( ' catalog_product_entity ' ) , 'entity_id ' )
388
- ->where ('sku IN (?) ' , $ listSku )
407
+ ->from ($ this ->_catalogProductEntity , 'entity_id ' )
408
+ ->where ('sku IN (?) ' , $ listSku )
389
409
);
390
410
}
391
411
if ($ this ->_cachedSkuToDelete ) {
@@ -407,6 +427,23 @@ protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
407
427
}
408
428
}
409
429
430
+ /**
431
+ * Set updated_at for product
432
+ *
433
+ * @param array $listSku
434
+ * @return $this
435
+ */
436
+ protected function setUpdatedAt (array $ listSku )
437
+ {
438
+ $ updatedAt = $ this ->_localeDate ->date (null , null , false )->format ('Y-m-d H:i:s ' );
439
+ $ this ->_connection ->update (
440
+ $ this ->_catalogProductEntity ,
441
+ [\Magento \Catalog \Model \Category::KEY_UPDATED_AT => $ updatedAt ],
442
+ $ this ->_connection ->quoteInto ('sku IN (?) ' , $ listSku )
443
+ );
444
+ return $ this ;
445
+ }
446
+
410
447
/**
411
448
* Get website id by code
412
449
*
0 commit comments