本文整理汇总了PHP中Mage_Eav_Model_Entity_Attribute类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Eav_Model_Entity_Attribute类的具体用法?PHP Mage_Eav_Model_Entity_Attribute怎么用?PHP Mage_Eav_Model_Entity_Attribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Eav_Model_Entity_Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getAttributeRecords
/**
* Changed to support price attribute type multi-scope
* (non-PHPdoc)
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @see Mage_Test_Model_Mysql4_Fixture_Eav_Catalog_Abstract::_getAttributeRecords()
*/
protected function _getAttributeRecords($row, $attribute, $tableColumns)
{
if ($attribute->getFrontendInput() == 'price') {
$attribute->setIsGlobal(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE);
}
return parent::_getAttributeRecords($row, $attribute, $tableColumns);
}
示例2: addOptionValueToCollection
/**
* Add Join with option value for collection select
*
* @param Mage_Eav_Model_Entity_Collection_Abstract $collection
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param Zend_Db_Expr $valueExpr
*
* @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option
*/
public function addOptionValueToCollection($collection, $attribute, $valueExpr)
{
$attributeCode = $attribute->getAttributeCode();
$optionTable1 = $attributeCode . '_option_value_t1';
$optionTable2 = $attributeCode . '_option_value_t2';
$collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), "`{$optionTable1}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='0'", array())->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), "`{$optionTable2}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", array($attributeCode => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)"));
return $this;
}
示例3: getAttributeFieldName
/**
* Retrieve attribute field name
*
*
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @return string
*/
public function getAttributeFieldName($attribute)
{
$name = $attribute->getAttributeCode();
if ($suffix = $this->getForm()->getFieldNameSuffix()) {
$name = $this->getForm()->addSuffixToName($name, $suffix);
}
return $name;
}
示例4: getOptions
/**
* Gets attribute options from database
*
* @param \Mage_Eav_Model_Entity_Attribute $attribute
*
* @return array
*/
protected function getOptions($attribute)
{
$select = $this->readConnection->select()->from(array('o' => \Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')))->join(array('ov' => \Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')), 'o.option_id = ov.option_id')->where('o.attribute_id = ?', $attribute->getId())->where('ov.store_id = 0')->order('ov.option_id');
$query = $select->query();
$values = array();
foreach ($query->fetchAll() as $row) {
$values[] = $row['value'];
}
return array('values' => $values);
}
示例5: addOptionValueToCollection
/**
* Add Join with option value for collection select
*
* @param Mage_Eav_Model_Entity_Collection_Abstract $collection
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param Zend_Db_Expr $valueExpr
* @return Mage_Eav_Model_Resource_Entity_Attribute_Option
*/
public function addOptionValueToCollection($collection, $attribute, $valueExpr)
{
$adapter = $this->_getReadAdapter();
$attributeCode = $attribute->getAttributeCode();
$optionTable1 = $attributeCode . '_option_value_t1';
$optionTable2 = $attributeCode . '_option_value_t2';
$tableJoinCond1 = "{$optionTable1}.option_id={$valueExpr} AND {$optionTable1}.store_id=0";
$tableJoinCond2 = $adapter->quoteInto("{$optionTable2}.option_id={$valueExpr} AND {$optionTable2}.store_id=?", $collection->getStoreId());
$valueExpr = $adapter->getCheckSql("{$optionTable2}.value_id IS NULL", "{$optionTable1}.value", "{$optionTable2}.value");
$collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), $tableJoinCond1, array())->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), $tableJoinCond2, array($attributeCode => $valueExpr));
return $this;
}
示例6: addOptionValueToCollection
/**
* Add Join with option value for collection select
*
* @param Mage_Eav_Model_Entity_Collection_Abstract $collection
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param Zend_Db_Expr $valueExpr
*
* @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option
*/
public function addOptionValueToCollection($collection, $attribute, $valueExpr)
{
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$attributeCode = $attribute->getAttributeCode();
$optionTable1 = $attributeCode . '_option_value_t1';
$optionTable2 = $attributeCode . '_option_value_t2';
$collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), "`{$optionTable1}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$adminStore}'", $collection->getStoreId() != $adminStore ? array() : array($attributeCode . '_value' => "{$optionTable1}.value"));
if ($collection->getStoreId() != $adminStore) {
$collection->getSelect()->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), "`{$optionTable2}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", array($attributeCode . '_value' => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)"));
}
return $this;
}
示例7: deleteProductData
/**
* Delete product data
*
* @param Mage_Catalog_Model_Product $product
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @return Enterprise_GiftCard_Model_Resource_Attribute_Backend_Giftcard_Amount
*/
public function deleteProductData($product, $attribute)
{
$condition = array();
if (!$attribute->isScopeGlobal()) {
if ($storeId = $product->getStoreId()) {
$condition['website_id IN (?)'] = array(0, Mage::app()->getStore($storeId)->getWebsiteId());
}
}
$condition['entity_id=?'] = $product->getId();
$condition['attribute_id=?'] = $attribute->getId();
$this->_getWriteAdapter()->delete($this->getMainTable(), $condition);
return $this;
}
示例8: copyAttributeValues
/**
* Copy all eav attribute values for a specified attribute from one table to another eav attribute table,
* updating the attribute id. The old records remain in the old value table.
*
* @param Mage_Eav_Model_Entity_Attribute $oldAttribute
* @param Mage_Eav_Model_Entity_Attribute $newAttribute
* @return array Affected entity ids
*/
public function copyAttributeValues(Mage_Eav_Model_Entity_Attribute $oldAttribute, Mage_Eav_Model_Entity_Attribute $newAttribute)
{
$select = $this->_getReadAdapter()->select()->reset()->distinct(true)->from($oldAttribute->getBackendTable(), 'entity_id')->where('attribute_id=:attribute_id');
$entityIds = $this->_getReadAdapter()->fetchCol($select, array('attribute_id' => $oldAttribute->getId()));
// Remove new attribute value records for entities that are being migrated
$this->_getWriteAdapter()->delete($newAttribute->getBackendTable(), array('attribute_id=?' => $newAttribute->getId(), 'entity_id IN(?)' => $entityIds));
// Copy old attribute values to the new attribute
$selectFields = array('entity_type_id', new Zend_Db_Expr($newAttribute->getId()), 'store_id', 'entity_id', 'value');
$insertFields = array('entity_type_id', 'attribute_id', 'store_id', 'entity_id', 'value');
$select->reset()->from($oldAttribute->getBackendTable(), $selectFields)->where('attribute_id=?', $oldAttribute->getId());
$update = $this->_getWriteAdapter()->insertFromSelect($select, $newAttribute->getBackendTable(), $insertFields, Varien_Db_Adapter_Interface::INSERT_IGNORE);
$this->_getWriteAdapter()->query($update);
return $entityIds;
}
示例9: setAttributeModel
/**
* Set attribute model to filter
*
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @return Mage_Catalog_Model_Layer_Filter_Abstract
*/
public function setAttributeModel($attribute)
{
$this->setRequestVar($attribute->getAttributeCode());
$this->setData('attribute_model', $attribute);
return $this;
}
示例10: getAttributeType
/**
* Get attribute type for upcoming validation.
*
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @return string
*/
public static function getAttributeType(Mage_Eav_Model_Entity_Attribute $attribute)
{
if ($attribute->usesSource()) {
return $attribute->getFrontendInput() == 'multiselect' ? 'multiselect' : 'select';
} elseif ($attribute->isStatic()) {
return $attribute->getFrontendInput() == 'date' ? 'datetime' : 'varchar';
} else {
return $attribute->getBackendType();
}
}
示例11: getAttributeFilterType
/**
* Determine filter type for specified attribute.
*
* @static
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @throws Exception
* @return string
*/
public static function getAttributeFilterType(Mage_Eav_Model_Entity_Attribute $attribute)
{
if ($attribute->usesSource() || $attribute->getFilterOptions()) {
return self::FILTER_TYPE_SELECT;
} elseif ('datetime' == $attribute->getBackendType()) {
return self::FILTER_TYPE_DATE;
} elseif ('decimal' == $attribute->getBackendType() || 'int' == $attribute->getBackendType()) {
return self::FILTER_TYPE_NUMBER;
} elseif ($attribute->isStatic() || 'varchar' == $attribute->getBackendType() || 'text' == $attribute->getBackendType()) {
return self::FILTER_TYPE_INPUT;
} else {
Mage::throwException(Mage::helper('importexport')->__('Can not determine attribute filter type'));
}
}
示例12: _updateDefaultValue
/**
* Update attribute default value
*
* @param Mage_Eav_Model_Entity_Attribute|Mage_Core_Model_Abstract $object
* @param int|string $optionId
* @param int $intOptionId
* @param array $defaultValue
*/
protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)
{
if (in_array($optionId, $object->getDefault())) {
$frontendInput = $object->getFrontendInput();
if ($frontendInput === 'multiselect') {
$defaultValue[] = $intOptionId;
} elseif ($frontendInput === 'select') {
$defaultValue = array($intOptionId);
}
}
}
示例13: testValidate
/**
* @dataProvider attributeValueDataProvider
*/
public function testValidate($data)
{
$this->_attribute->expects($this->atLeastOnce())->method('getAttributeCode')->will($this->returnValue('code'));
$product = new Varien_Object(array('code' => $data));
$this->_model->validate($product);
$this->assertEquals('1,2,3', $product->getCode());
}
示例14: saveAttribute
private function saveAttribute()
{
if ($this->attributeObj->getId()) {
return array('result' => true, 'obj' => $this->attributeObj);
}
if (!$this->validate()) {
return array('result' => false, 'error' => 'Attribute builder. Validation failed.');
}
$this->attributeObj = Mage::getModel('catalog/resource_eav_attribute');
$data = $this->params;
$data['attribute_code'] = $this->code;
$data['frontend_label'] = array(Mage_Core_Model_App::ADMIN_STORE_ID => $this->primaryLabel);
$data['frontend_input'] = $this->inputType;
$data['entity_type_id'] = $this->entityTypeId;
$data['is_user_defined'] = 1;
$data['source_model'] = Mage::helper('catalog/product')->getAttributeSourceModelByInputType($this->inputType);
$data['backend_model'] = Mage::helper('catalog/product')->getAttributeBackendModelByInputType($this->inputType);
$data['backend_type'] = $this->attributeObj->getBackendTypeByInput($this->inputType);
!isset($data['is_global']) && ($data['is_global'] = self::SCOPE_STORE);
!isset($data['is_configurable']) && ($data['is_configurable'] = 0);
!isset($data['is_filterable']) && ($data['is_filterable'] = 0);
!isset($data['is_filterable_in_search']) && ($data['is_filterable_in_search'] = 0);
!isset($data['apply_to']) && ($data['apply_to'] = array());
$this->prepareOptions($data);
$this->prepareDefault($data);
$this->attributeObj->addData($data);
try {
$this->attributeObj->save();
} catch (Exception $e) {
return array('result' => false, 'error' => $e->getMessage());
}
return array('result' => true, 'obj' => $this->attributeObj);
}
示例15: _beforeSave
protected function _beforeSave()
{
if ($this->getFrontendInput() == "image") {
$this->setBackendModel('catalog/category_attribute_backend_image');
$this->setBackendType('varchar');
}
if ($this->getFrontendInput() == "date") {
$this->setBackendModel('eav/entity_attribute_backend_datetime');
$this->setBackendType('datetime');
}
if ($this->getFrontendInput() == "textarea") {
$this->setBackendType('text');
}
if ($this->getFrontendInput() == "text") {
$this->setBackendType('varchar');
}
if ($this->getFrontendInput() == "multiselect" || $this->getFrontendInput() == "select") {
$this->setData('source_model', 'eav/entity_attribute_source_table');
$this->setBackendType('varchar');
}
if ($this->getFrontendInput() == "boolean") {
$this->setFrontendInput("select");
$this->setBackendType('int');
$this->setData('source_model', 'eav/entity_attribute_source_boolean');
}
return parent::_beforeSave();
}