本文整理汇总了PHP中Mage_Eav_Model_Entity_Attribute_Abstract::getIsRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Eav_Model_Entity_Attribute_Abstract::getIsRequired方法的具体用法?PHP Mage_Eav_Model_Entity_Attribute_Abstract::getIsRequired怎么用?PHP Mage_Eav_Model_Entity_Attribute_Abstract::getIsRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Eav_Model_Entity_Attribute_Abstract
的用法示例。
在下文中一共展示了Mage_Eav_Model_Entity_Attribute_Abstract::getIsRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _insertAttribute
/**
* Insert entity attribute value
*
* @param Varien_Object $object
* @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
* @param mixed $value
* @return Mage_Catalog_Model_Resource_Abstract
*/
protected function _insertAttribute($object, $attribute, $value)
{
/**
* save required attributes in global scope every time if store id different from default
*/
$storeId = (int) Mage::app()->getStore($object->getStoreId())->getId();
if ($attribute->getIsRequired() && $this->getDefaultStoreId() != $storeId) {
$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 Varien_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 Varien_Object $object
* @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
* @param mixed $value
* @return Mage_Eav_Model_Entity_Abstract
*/
protected function _insertAttribute($object, $attribute, $value)
{
/**
* save required attributes in global scope every time if store id different from default
*/
$storeId = Mage::app()->getStore($object->getStoreId())->getId();
if ($attribute->getIsRequired() && $this->getDefaultStoreId() != $storeId) {
$bind = array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getAttributeId(), 'store_id' => $this->getDefaultStoreId(), 'entity_id' => $object->getEntityId(), 'value' => $this->_prepareValueForSave($value, $attribute));
$this->_getWriteAdapter()->insertOnDuplicate($attribute->getBackend()->getTable(), $bind, array('value'));
}
return $this->_saveAttributeValue($object, $attribute, $value);
// $entityIdField = $attribute->getBackend()->getEntityIdField();
// $row = array(
// $entityIdField => $object->getId(),
// 'entity_type_id'=> $object->getEntityTypeId(),
// 'attribute_id' => $attribute->getId(),
// 'value' => $this->_prepareValueForSave($value, $attribute),
// 'store_id' => $this->getDefaultStoreId()
// );
//
// $fields = array();
// $bind = array();
// foreach ($row as $k => $v) {
// $fields[] = $this->_getWriteAdapter()->quoteIdentifier($k);
// $bind[':' . $k] = $v;
// }
//
// $sql = sprintf('INSERT IGNORE INTO %s (%s) VALUES(%s)',
// $this->_getWriteAdapter()->quoteIdentifier($attribute->getBackend()->getTable()),
// implode(',', $fields),
// implode(',', array_keys($bind)));
//
// $this->_getWriteAdapter()->query($sql, $bind);
// if (!$lastId = $this->_getWriteAdapter()->lastInsertId()) {
// $select = $this->_getReadAdapter()->select()
// ->from($attribute->getBackend()->getTable(), 'value_id')
// ->where($entityIdField . '=?', $row[$entityIdField])
// ->where('entity_type_id=?', $row['entity_type_id'])
// ->where('attribute_id=?', $row['attribute_id'])
// ->where('store_id=?', $row['store_id']);
// $lastId = $select->query()->fetchColumn();
// }
// if ($object->getStoreId() != $this->getDefaultStoreId()) {
// $this->_updateAttribute($object, $attribute, $lastId, $value);
// }
// return $this;
}