Пример #1
0
 /**
  * Delete the object
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Exception
  */
 public function delete(\Magento\Framework\Model\AbstractModel $object)
 {
     $connection = $this->transactionManager->start($this->_getWriteAdapter());
     try {
         $object->beforeDelete();
         $this->_beforeDelete($object);
         $this->objectRelationProcessor->delete(
             $this->transactionManager,
             $connection,
             $this->getMainTable(),
             $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId()),
             $object->getData()
         );
         $this->_afterDelete($object);
         $object->isDeleted(true);
         $object->afterDelete();
         $this->transactionManager->commit();
         $object->afterDeleteCommit();
     } catch (\Exception $e) {
         $this->transactionManager->rollBack();
         throw $e;
     }
     return $this;
 }
Пример #2
0
 /**
  * Delete entity using current object's data
  *
  * @param \Magento\Framework\Object|int|string $object
  * @return $this
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function delete($object)
 {
     try {
         $connection = $this->transactionManager->start($this->_getWriteAdapter());
         if (is_numeric($object)) {
             $id = (int) $object;
         } elseif ($object instanceof \Magento\Framework\Object) {
             $object->beforeDelete();
             $id = (int) $object->getId();
         }
         $this->_beforeDelete($object);
         try {
             $where = [$this->getEntityIdField() . '=?' => $id];
             $this->objectRelationProcessor->delete($this->transactionManager, $connection, $this->getEntityTable(), $this->_getWriteAdapter()->quoteInto($this->getEntityIdField() . '=?', $id), [$this->getEntityIdField() => $id]);
             $this->loadAllAttributes($object);
             foreach ($this->getAttributesByTable() as $table => $attributes) {
                 $this->_getWriteAdapter()->delete($table, $where);
             }
         } catch (\Exception $e) {
             throw $e;
         }
         $this->_afterDelete($object);
         if ($object instanceof \Magento\Framework\Object) {
             $object->isDeleted(true);
             $object->afterDelete();
         }
         $this->transactionManager->commit();
         if ($object instanceof \Magento\Framework\Object) {
             $object->afterDeleteCommit();
         }
     } catch (\Exception $e) {
         $this->transactionManager->rollBack();
         throw $e;
     }
     return $this;
 }
Пример #3
0
 /**
  * Delete products.
  *
  * @return $this
  * @throws \Exception
  */
 protected function _deleteProducts()
 {
     $productEntityTable = $this->_resourceFactory->create()->getEntityTable();
     while ($bunch = $this->_dataSourceModel->getNextBunch()) {
         $idToDelete = [];
         foreach ($bunch as $rowNum => $rowData) {
             if ($this->validateRow($rowData, $rowNum) && self::SCOPE_DEFAULT == $this->getRowScope($rowData)) {
                 $idToDelete[] = $this->_oldSku[$rowData[self::COL_SKU]]['entity_id'];
             }
         }
         if ($idToDelete) {
             $this->countItemsDeleted += count($idToDelete);
             $this->transactionManager->start($this->_connection);
             try {
                 $this->objectRelationProcessor->delete($this->transactionManager, $this->_connection, $productEntityTable, $this->_connection->quoteInto('entity_id IN (?)', $idToDelete), ['entity_id' => $idToDelete]);
                 $this->transactionManager->commit();
             } catch (\Exception $e) {
                 $this->transactionManager->rollBack();
                 throw $e;
             }
             $this->_eventManager->dispatch('catalog_product_import_bunch_delete_after', ['adapter' => $this, 'bunch' => $bunch]);
         }
     }
     return $this;
 }