Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Framework\Model\AbstractModel $object)
 {
     $hasDataChanges = $object->hasDataChanges();
     $object->setIsOptionsSaved(false);
     $result = parent::save($object);
     if ($hasDataChanges && !$object->isOptionsSaved()) {
         $object->saveItemOptions();
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Successful if $value is \Magento\Framework\Model\AbstractModel an all condition are fulfilled.
  *
  * If read-only properties are set than $value mustn't have changes in them.
  *
  * @param AbstractModel $value
  * @return bool
  * @throws \InvalidArgumentException when $value is not instanceof \Magento\Framework\DataObject
  * @api
  */
 public function isValid($value)
 {
     $this->_clearMessages();
     if (!$value instanceof AbstractModel) {
         throw new \InvalidArgumentException('Instance of \\Magento\\Framework\\Model\\AbstractModel is expected.');
     }
     if ($this->_readOnlyProperties) {
         if (!$value->hasDataChanges()) {
             return true;
         }
         foreach ($this->_readOnlyProperties as $property) {
             if ($this->_hasChanges($value->getData($property), $value->getOrigData($property))) {
                 $this->_messages[__CLASS__] = [(string) new \Magento\Framework\Phrase("Read-only property cannot be changed.")];
                 break;
             }
         }
     }
     return !count($this->_messages);
 }
Exemplo n.º 3
0
 /**
  * Check if object was modified
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return bool
  */
 protected function isModified(\Magento\Framework\Model\AbstractModel $object)
 {
     return $object->hasDataChanges();
 }
Exemplo n.º 4
0
 /**
  * Tests \Magento\Framework\Object->setDataChanges()
  */
 public function testSetDataChanges()
 {
     $this->assertFalse($this->model->hasDataChanges());
     $this->model->setDataChanges(true);
     $this->assertTrue($this->model->hasDataChanges());
 }