当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractAttribute::getIsRequired方法代码示例

本文整理汇总了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);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:28,代码来源:AbstractResource.php

示例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);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:28,代码来源:AbstractResource.php


注:本文中的Magento\Eav\Model\Entity\Attribute\AbstractAttribute::getIsRequired方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。