public function testProcessRelations()
 {
     $this->relationProcessorMock->expects($this->once())->method('processRelation')->with($this->salesModelMock);
     $this->salesModelMock->expects($this->once())->method('getEventPrefix')->willReturn('sales_event_prefix');
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('sales_event_prefix_process_relation', ['object' => $this->salesModelMock]);
     $this->entityRelationComposite->processRelations($this->salesModelMock);
 }
Beispiel #2
0
 public function testSave()
 {
     $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->once())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->once())->method('getGroup')->willReturn($this->storeGroupMock);
     $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);
 }
Beispiel #3
0
 /**
  * Save entity
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Exception
  */
 public function save(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->isDeleted()) {
         return $this->delete($object);
     }
     if (!$this->entitySnapshot->isModified($object)) {
         $this->entityRelationComposite->processRelations($object);
         return $this;
     }
     $this->beginTransaction();
     try {
         $object->validateBeforeSave();
         $object->beforeSave();
         if ($object->isSaveAllowed()) {
             $this->_serializeFields($object);
             $this->_beforeSave($object);
             $this->_checkUnique($object);
             $this->objectRelationProcessor->validateDataIntegrity($this->getMainTable(), $object->getData());
             if ($object->getId() !== null && (!$this->_useIsObjectNew || !$object->isObjectNew())) {
                 $condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId());
                 $data = $this->_prepareDataForSave($object);
                 unset($data[$this->getIdFieldName()]);
                 $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
             } else {
                 $bind = $this->_prepareDataForSave($object);
                 unset($bind[$this->getIdFieldName()]);
                 $this->_getWriteAdapter()->insert($this->getMainTable(), $bind);
                 $object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable()));
                 if ($this->_useIsObjectNew) {
                     $object->isObjectNew(false);
                 }
             }
             $this->unserializeFields($object);
             $this->_afterSave($object);
             $this->entitySnapshot->registerSnapshot($object);
             $object->afterSave();
             $this->entityRelationComposite->processRelations($object);
         }
         $this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
         $object->setHasDataChanges(false);
     } catch (\Exception $e) {
         $this->rollBack();
         $object->setHasDataChanges(true);
         throw $e;
     }
     return $this;
 }