Example #1
0
 public function testSave()
 {
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null);
     $this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]);
     $this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order');
     $this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock);
     $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock);
     $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001');
     $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']);
     $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']);
     $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock);
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
     $this->connectionMock->expects($this->any())->method('quoteInto');
     $this->connectionMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->connectionMock->expects($this->any())->method('update');
     $this->connectionMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
Example #2
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;
 }
Example #3
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->getConnection());
     try {
         $object->beforeDelete();
         $this->_beforeDelete($object);
         $this->objectRelationProcessor->delete(
             $this->transactionManager,
             $connection,
             $this->getMainTable(),
             $this->getConnection()->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;
 }
Example #4
0
 /**
  * Evaluate Delete operations
  *
  * @param \Magento\Framework\DataObject|int|string $object
  * @param string|int $id
  * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
  * @return void
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function evaluateDelete($object, $id, $connection)
 {
     $where = [$this->getEntityIdField() . '=?' => $id];
     $this->objectRelationProcessor->delete($this->transactionManager, $connection, $this->getEntityTable(), $this->getConnection()->quoteInto($this->getEntityIdField() . '=?', $id), [$this->getEntityIdField() => $id]);
     $this->loadAllAttributes($object);
     foreach ($this->getAttributesByTable() as $table => $attributes) {
         $this->getConnection()->delete($table, $where);
     }
 }
Example #5
0
 /**
  * Delete entity using current object's data
  *
  * @param \Magento\Framework\DataObject|int|string $object
  * @return $this
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function delete($object)
 {
     try {
         $connection = $this->transactionManager->start($this->getConnection());
         if (is_numeric($object)) {
             $id = (int) $object;
         } elseif ($object instanceof \Magento\Framework\Model\AbstractModel) {
             $object->beforeDelete();
             $id = (int) $object->getId();
         }
         $this->_beforeDelete($object);
         try {
             $where = [$this->getEntityIdField() . '=?' => $id];
             $this->objectRelationProcessor->delete($this->transactionManager, $connection, $this->getEntityTable(), $this->getConnection()->quoteInto($this->getEntityIdField() . '=?', $id), [$this->getEntityIdField() => $id]);
             $this->loadAllAttributes($object);
             foreach ($this->getAttributesByTable() as $table => $attributes) {
                 $this->getConnection()->delete($table, $where);
             }
         } catch (\Exception $e) {
             throw $e;
         }
         $this->_afterDelete($object);
         if ($object instanceof \Magento\Framework\Model\AbstractModel) {
             $object->isDeleted(true);
             $object->afterDelete();
         }
         $this->transactionManager->commit();
         if ($object instanceof \Magento\Framework\Model\AbstractModel) {
             $object->afterDeleteCommit();
         }
     } catch (\Exception $e) {
         $this->transactionManager->rollBack();
         throw $e;
     }
     return $this;
 }
 /**
  * @param string $entityType
  * @param object $entity
  * @throws \Exception
  * @return void
  */
 public function execute($entityType, $entity)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $hydrator = $this->hydratorPool->getHydrator($entityType);
     $this->objectRelationProcessor->validateDataIntegrity($metadata->getEntityTable(), $hydrator->extract($entity));
 }