/** * Insert entity attribute value * * @param \Magento\Framework\Object $object * @param AbstractAttribute $attribute * @param mixed $value * @return $this */ protected function _insertAttribute($object, $attribute, $value) { /** * save required attributes in global scope every time if store id different from default */ $storeId = (int) $this->_storeManager->getStore($object->getStoreId())->getId(); if ($this->getDefaultStoreId() != $storeId) { if ($attribute->getIsRequired() || $attribute->getIsRequiredInAdminStore()) { $table = $attribute->getBackend()->getTable(); $select = $this->_getReadAdapter()->select()->from($table)->where('entity_type_id = ?', $attribute->getEntityTypeId())->where('attribute_id = ?', $attribute->getAttributeId())->where('store_id = ?', $this->getDefaultStoreId())->where('entity_id = ?', $object->getEntityId()); $row = $this->_getReadAdapter()->fetchOne($select); if (!$row) { $data = new \Magento\Framework\Object(array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getAttributeId(), 'store_id' => $this->getDefaultStoreId(), 'entity_id' => $object->getEntityId(), 'value' => $this->_prepareValueForSave($value, $attribute))); $bind = $this->_prepareDataForTable($data, $table); $this->_getWriteAdapter()->insertOnDuplicate($table, $bind, array('value')); } } } return $this->_saveAttributeValue($object, $attribute, $value); }
/** * Insert entity attribute value * * @param \Magento\Framework\DataObject $object * @param AbstractAttribute $attribute * @param mixed $value * @return $this */ protected function _insertAttribute($object, $attribute, $value) { /** * save required attributes in global scope every time if store id different from default */ $storeId = (int) $this->_storeManager->getStore($object->getStoreId())->getId(); if ($this->getDefaultStoreId() != $storeId) { if ($attribute->getIsRequired() || $attribute->getIsRequiredInAdminStore()) { $table = $attribute->getBackend()->getTable(); $select = $this->getConnection()->select()->from($table)->where('attribute_id = ?', $attribute->getAttributeId())->where('store_id = ?', $this->getDefaultStoreId())->where($this->getLinkField() . ' = ?', $object->getData($this->getLinkField())); $row = $this->getConnection()->fetchOne($select); if (!$row) { $data = new \Magento\Framework\DataObject(['attribute_id' => $attribute->getAttributeId(), 'store_id' => $this->getDefaultStoreId(), $this->getLinkField() => $object->getData($this->getLinkField()), 'value' => $this->_prepareValueForSave($value, $attribute)]); $bind = $this->_prepareDataForTable($data, $table); $this->getConnection()->insertOnDuplicate($table, $bind, ['value']); } } } return $this->_saveAttributeValue($object, $attribute, $value); }