Esempio n. 1
0
 /**
  * Validate unique configuration data before save
  * Set id to object if exists configuration instead of throw exception
  *
  * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  *
  * @param \Magento\Framework\Model\AbstractModel $object The current configuration value being saved
  *
  * @return $this
  */
 protected function _checkUnique(\Magento\Framework\Model\AbstractModel $object)
 {
     $select = $this->getConnection()->select()->from($this->getMainTable(), [$this->getIdFieldName()])->where('scope = :scope')->where('scope_code = :scope_code')->where('path = :path');
     $bind = ['scope' => $object->getScope(), 'scope_code' => $object->getScopeCode(), 'path' => $object->getPath()];
     $configId = $this->getConnection()->fetchOne($select, $bind);
     if ($configId) {
         $object->setId($configId);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Validate unique configuration data before save
  * Set id to object if exists configuration instead of throw exception
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _checkUnique(\Magento\Framework\Model\AbstractModel $object)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), array($this->getIdFieldName()))->where('scope = :scope')->where('scope_id = :scope_id')->where('path = :path');
     $bind = array('scope' => $object->getScope(), 'scope_id' => $object->getScopeId(), 'path' => $object->getPath());
     $configId = $this->_getReadAdapter()->fetchOne($select, $bind);
     if ($configId) {
         $object->setId($configId);
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Before save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $adapter = $this->_getWriteAdapter();
     $select = $adapter->select()->from($this->getMainTable(), 'key_id')->where('string = :string')->where('store_id = :store_id');
     $bind = array('string' => $object->getString(), 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $object->setId($adapter->fetchOne($select, $bind));
     return parent::_beforeSave($object);
 }
 /**
  * Identifier setter
  *
  * @param mixed $value
  * @return $this
  */
 public function setId($value)
 {
     parent::setId($value);
     return $this->setData('id', $value);
 }
Esempio n. 5
0
 /**
  * Tests \Magento\Framework\Object->getId()
  */
 public function testSetGetId()
 {
     $this->model->setId('test');
     $this->assertEquals('test', $this->model->getId());
 }
Esempio n. 6
0
 /**
  * Callback for delete method in mocked model
  */
 public function deleteModelSuccessfully()
 {
     $this->_model->setId(null);
 }