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); }
/** * 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; }