public function testUnsetData() { $data = ['key1' => 'value1', 'key2' => 'value2']; $this->_model->setData($data); // unset one locked $this->_model->lockAttribute('key1')->unsetData('key1'); $this->assertEquals($data, $this->_model->getData()); // unset all with read only $this->_model->setIsReadonly(true)->unsetData(); $this->assertEquals($data, $this->_model->getData()); // unset all $this->_model->unlockAttributes()->setIsReadonly(false)->unsetData(); $this->assertEquals([], $this->_model->getData()); }
/** * Initialize attribute value for object * * @param \Magento\Catalog\Model\AbstractModel $object * @param array $valueRow * @return $this */ protected function _setAttributeValue($object, $valueRow) { $attribute = $this->getAttribute($valueRow['attribute_id']); if ($attribute) { $attributeCode = $attribute->getAttributeCode(); $isDefaultStore = $valueRow['store_id'] == $this->getDefaultStoreId(); if (isset($this->_attributes[$valueRow['attribute_id']])) { if ($isDefaultStore) { $object->setAttributeDefaultValue($attributeCode, $valueRow['value']); } else { $object->setAttributeDefaultValue($attributeCode, $this->_attributes[$valueRow['attribute_id']]['value']); } } else { $this->_attributes[$valueRow['attribute_id']] = $valueRow; } $value = $valueRow['value']; $valueId = $valueRow['value_id']; $object->setData($attributeCode, $value); if (!$isDefaultStore) { $object->setExistsStoreValueFlag($attributeCode); } $attribute->getBackend()->setEntityValueId($object, $valueId); } return $this; }