10
10
11
11
use Magento \Framework \App \Filesystem \DirectoryList ;
12
12
use Magento \CatalogImportExport \Model \Import \Product \RowValidatorInterface as ValidatorInterface ;
13
+ use Magento \Framework \Model \Resource \Db \TransactionManagerInterface ;
14
+ use Magento \Framework \Model \Resource \Db \ObjectRelationProcessor ;
13
15
14
16
/**
15
17
* Import entity product model
@@ -373,6 +375,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
373
375
*/
374
376
protected $ masterAttributeCode = 'sku ' ;
375
377
378
+ /**
379
+ * @var ObjectRelationProcessor
380
+ */
381
+ protected $ objectRelationProcessor ;
382
+
383
+ /**
384
+ * @var TransactionManagerInterface
385
+ */
386
+ protected $ transactionManager ;
387
+
376
388
/**
377
389
* @param \Magento\Core\Helper\Data $coreData
378
390
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -439,6 +451,8 @@ public function __construct(
439
451
Product \SkuProcessor $ skuProcessor ,
440
452
Product \CategoryProcessor $ categoryProcessor ,
441
453
Product \Validator $ validator ,
454
+ ObjectRelationProcessor $ objectRelationProcessor ,
455
+ TransactionManagerInterface $ transactionManager ,
442
456
array $ data = []
443
457
) {
444
458
$ this ->_eventManager = $ eventManager ;
@@ -463,6 +477,8 @@ public function __construct(
463
477
$ this ->skuProcessor = $ skuProcessor ;
464
478
$ this ->categoryProcessor = $ categoryProcessor ;
465
479
$ this ->validator = $ validator ;
480
+ $ this ->objectRelationProcessor = $ objectRelationProcessor ;
481
+ $ this ->transactionManager = $ transactionManager ;
466
482
parent ::__construct ($ coreData , $ importExportData , $ importData , $ config , $ resource , $ resourceHelper , $ string );
467
483
$ this ->_optionEntity = isset (
468
484
$ data ['option_entity ' ]
@@ -504,6 +520,7 @@ public function setParameters(array $params)
504
520
* Delete products.
505
521
*
506
522
* @return $this
523
+ * @throws \Exception
507
524
*/
508
525
protected function _deleteProducts ()
509
526
{
@@ -518,12 +535,20 @@ protected function _deleteProducts()
518
535
}
519
536
}
520
537
if ($ idToDelete ) {
521
- $ this ->_connection ->query (
522
- $ this ->_connection ->quoteInto (
523
- "DELETE FROM ` {$ productEntityTable }` WHERE `entity_id` IN (?) " ,
524
- $ idToDelete
525
- )
526
- );
538
+ $ this ->transactionManager ->start ($ this ->_connection );
539
+ try {
540
+ $ this ->objectRelationProcessor ->delete (
541
+ $ this ->transactionManager ,
542
+ $ this ->_connection ,
543
+ $ productEntityTable ,
544
+ $ this ->_connection ->quoteInto ('entity_id IN (?) ' , $ idToDelete ),
545
+ ['entity_id ' => $ idToDelete ]
546
+ );
547
+ $ this ->transactionManager ->commit ();
548
+ } catch (\Exception $ e ) {
549
+ $ this ->transactionManager ->rollBack ();
550
+ throw $ e ;
551
+ }
527
552
}
528
553
}
529
554
return $ this ;
0 commit comments