本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute\AbstractAttribute::getIsRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractAttribute::getIsRequired方法的具体用法?PHP AbstractAttribute::getIsRequired怎么用?PHP AbstractAttribute::getIsRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Entity\Attribute\AbstractAttribute
的用法示例。
在下文中一共展示了AbstractAttribute::getIsRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _insertAttribute
/**
* 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);
}
示例2: _insertAttribute
/**
* 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);
}