コード例 #1
0
ファイル: OrderTest.php プロジェクト: nja78/magento2
 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->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->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);
 }
コード例 #2
0
ファイル: AbstractEntity.php プロジェクト: opexsw/magento2
 /**
  * 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
ファイル: AbstractDb.php プロジェクト: niranjanssiet/magento2
 /**
  * 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;
 }
コード例 #4
0
ファイル: Product.php プロジェクト: nja78/magento2
 /**
  * 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;
 }