Skip to content

Commit 9f063c6

Browse files
author
Olexii Korshenko
committed
MAGETWO-34269: quote_items are not deleted after delete product using import/export functionality
1 parent c876c62 commit 9f063c6

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use Magento\Framework\App\Filesystem\DirectoryList;
1212
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;
1315

1416
/**
1517
* Import entity product model
@@ -373,6 +375,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
373375
*/
374376
protected $masterAttributeCode = 'sku';
375377

378+
/**
379+
* @var ObjectRelationProcessor
380+
*/
381+
protected $objectRelationProcessor;
382+
383+
/**
384+
* @var TransactionManagerInterface
385+
*/
386+
protected $transactionManager;
387+
376388
/**
377389
* @param \Magento\Core\Helper\Data $coreData
378390
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -439,6 +451,8 @@ public function __construct(
439451
Product\SkuProcessor $skuProcessor,
440452
Product\CategoryProcessor $categoryProcessor,
441453
Product\Validator $validator,
454+
ObjectRelationProcessor $objectRelationProcessor,
455+
TransactionManagerInterface $transactionManager,
442456
array $data = []
443457
) {
444458
$this->_eventManager = $eventManager;
@@ -463,6 +477,8 @@ public function __construct(
463477
$this->skuProcessor = $skuProcessor;
464478
$this->categoryProcessor = $categoryProcessor;
465479
$this->validator = $validator;
480+
$this->objectRelationProcessor = $objectRelationProcessor;
481+
$this->transactionManager = $transactionManager;
466482
parent::__construct($coreData, $importExportData, $importData, $config, $resource, $resourceHelper, $string);
467483
$this->_optionEntity = isset(
468484
$data['option_entity']
@@ -504,6 +520,7 @@ public function setParameters(array $params)
504520
* Delete products.
505521
*
506522
* @return $this
523+
* @throws \Exception
507524
*/
508525
protected function _deleteProducts()
509526
{
@@ -518,12 +535,20 @@ protected function _deleteProducts()
518535
}
519536
}
520537
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+
}
527552
}
528553
}
529554
return $this;

lib/internal/Magento/Framework/Model/Resource/Db/ObjectRelationProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function delete(
3636
*
3737
* @param string $table
3838
* @param array $involvedData
39+
* @return void
3940
*/
4041
public function validateDataIntegrity($table, array $involvedData)
4142
{

0 commit comments

Comments
 (0)