本文整理汇总了PHP中Mage_Eav_Model_Entity_Attribute::getAttributeCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Eav_Model_Entity_Attribute::getAttributeCode方法的具体用法?PHP Mage_Eav_Model_Entity_Attribute::getAttributeCode怎么用?PHP Mage_Eav_Model_Entity_Attribute::getAttributeCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Eav_Model_Entity_Attribute
的用法示例。
在下文中一共展示了Mage_Eav_Model_Entity_Attribute::getAttributeCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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: saveAttribute
private function saveAttribute()
{
if ($this->attributeObj->getId()) {
return array('result' => true, 'obj' => $this->attributeObj, 'code' => $this->attributeObj->getAttributeCode());
}
if (!$this->validate()) {
return array('result' => false, 'error' => 'Attribute builder. Validation failed.');
}
$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['source_model'] = Mage::helper('catalog/product')->getAttributeSourceModelByInputType($this->inputType);
$data['backend_model'] = Mage::helper('catalog/product')->getAttributeBackendModelByInputType($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);
$this->attributeObj = Mage::getModel('catalog/resource_eav_attribute');
if (is_null($this->attributeObj->getIsUserDefined()) || $this->attributeObj->getIsUserDefined() != 0) {
$data['backend_type'] = $this->attributeObj->getBackendTypeByInput($this->inputType);
}
// default value
if (empty($data['default_value'])) {
unset($data['default_value']);
}
// ---------------------------------------
!isset($data['apply_to']) && ($data['apply_to'] = array());
// prepare options
foreach ($this->options as $optionValue) {
$code = 'option_' . substr(sha1($optionValue), 0, 6);
$data['option']['value'][$code] = array(Mage_Core_Model_App::ADMIN_STORE_ID => $optionValue);
}
// ---------------------------------------
$this->attributeObj->addData($data);
$this->attributeObj->setEntityTypeId($this->entityTypeId);
$this->attributeObj->setIsUserDefined(1);
try {
$this->attributeObj->save();
} catch (Exception $e) {
return array('result' => false, 'error' => $e->getMessage());
}
return array('result' => true, 'obj' => $this->attributeObj, 'code' => $this->attributeObj->getAttributeCode());
}
示例4: 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;
}
示例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: updateAttribute
/**
* Update attribute flat data
*
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param int $store
* @param int|array $productIds update only product(s)
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer
*/
public function updateAttribute($attribute, $store, $productIds = null)
{
if ($attribute->getBackend()->getType() == 'static') {
$select = $this->_getWriteAdapter()->select()->join(array('main_table' => $this->getTable('catalog/product')), 'main_table.entity_id=e.entity_id ', array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()));
if ($this->getFlatHelper()->isAddChildData()) {
$select->where("e.is_child=?", 0);
}
if (!is_null($productIds)) {
$select->where('main_table.entity_id IN(?)', $productIds);
}
$sql = $select->crossUpdateFromSelect(array('e' => $this->getFlatTableName($store)));
$this->_getWriteAdapter()->query($sql);
} else {
$select = $attribute->getFlatUpdateSelect($store);
if ($select instanceof Varien_Db_Select) {
if (!is_null($productIds)) {
$select->where('e.entity_id IN(?)', $productIds);
}
$sql = $select->crossUpdateFromSelect(array('e' => $this->getFlatTableName($store)));
$this->_getWriteAdapter()->query($sql);
}
}
return $this;
}
示例7: updateAttribute
/**
* Update attribute flat data
*
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param int $storeId
* @param int|array $productIds update only product(s)
* @return Mage_Catalog_Model_Resource_Product_Flat_Indexer
*/
public function updateAttribute($attribute, $storeId, $productIds = null)
{
if (!$this->_isFlatTableExists($storeId)) {
return $this;
}
$adapter = $this->_getWriteAdapter();
$flatTableName = $this->getFlatTableName($storeId);
$describe = $adapter->describeTable($flatTableName);
if ($attribute->getBackend()->getType() == 'static') {
if (!isset($describe[$attribute->getAttributeCode()])) {
return $this;
}
$select = $adapter->select()->join(array('main_table' => $this->getTable('catalog/product')), 'main_table.entity_id = e.entity_id', array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()));
if ($this->getFlatHelper()->isAddChildData()) {
$select->where('e.is_child = ?', 0);
}
if ($productIds !== null) {
$select->where('main_table.entity_id IN(?)', $productIds);
}
$sql = $select->crossUpdateFromSelect(array('e' => $flatTableName));
$adapter->query($sql);
} else {
$columns = $attribute->getFlatColumns();
if (!$columns) {
return $this;
}
foreach (array_keys($columns) as $columnName) {
if (!isset($describe[$columnName])) {
return $this;
}
}
$select = $attribute->getFlatUpdateSelect($storeId);
if ($select instanceof Varien_Db_Select) {
if ($productIds !== null) {
$select->where('e.entity_id IN(?)', $productIds);
}
$sql = $select->crossUpdateFromSelect(array('e' => $flatTableName));
$adapter->query($sql);
}
}
return $this;
}
示例8: _createField
/**
* Create Field and Return it
*
* @param Varien_Data_Form_Element_Abstract $fieldset
* @param Varien_Object $e
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param string $fieldStep
*
* @return Varien_Data_Form_Element_Abstract
*/
protected function _createField(Varien_Data_Form_Element_Abstract $fieldset, Varien_Object $e, Mage_Eav_Model_Entity_Attribute $attribute, $fieldStep = 'standard')
{
// Get Config Data
$configData = $this->getConfigData();
if ('' == $attribute->getFrontendLabel()) {
return false;
}
// Define Attribute Code
$attributeCode = $attribute->getAttributeCode();
$attributeCode = $fieldStep == 'newfield' ? "{$attributeCode}_dynamic_new" : $attributeCode;
// Get Attribute Data and Inheritance
$path = $this->_configPath . $attributeCode;
if (isset($configData[$path])) {
$data = $configData[$path];
$inherit = false;
} else {
$data = (string) Mage::getConfig()->getNode(null, $this->getForm()->getScope(), $this->getForm()->getScopeCode())->descend($path);
$inherit = true;
}
// Get field Renderer
if ($e->frontend_model) {
$fieldRenderer = Mage::getBlockSingleton((string) $e->frontend_model);
} else {
$fieldRenderer = $this->_getFieldRenderer();
}
// Define Type, Name, and Label
$fieldType = (string) $e->frontend_type ? (string) $e->frontend_type : 'text';
$name = str_replace('_attrCode_', $attributeCode, $this->_fieldNameTemplate);
$label = $fieldStep == 'newfield' ? "" : $attribute->getFrontendLabel();
// Pass through backend model in case it needs to modify value
if ($e->backend_model) {
$model = Mage::getModel((string) $e->backend_model);
if (!$model instanceof Mage_Core_Model_Config_Data) {
Mage::throwException('Invalid config field backend model: ' . (string) $e->backend_model);
}
$model->setPath($path)->setValue($data)->afterLoad();
$data = $model->getValue();
}
// Pre-populate New field with label text
if ('newfield' == $fieldStep && '' == $data) {
$data = $attribute->getFrontendLabel();
}
// Select Field for Existing attributes.
$field = $fieldset->addField($attributeCode, $fieldType, array('name' => $name, 'label' => $label, 'value' => $data === 0 ? '' : $data, 'inherit' => $fieldStep == 'newfield' ? false : $inherit, 'field_config' => $e, 'scope' => $this->getForm()->getScope(), 'scopeId' => $this->getForm()->getScopeId(), 'scope_label' => '[STORE VIEW]', 'can_use_default_value' => $this->getForm()->canUseDefaultValue((int) $e->show_in_default), 'can_use_website_value' => $this->getForm()->canUseWebsiteValue((int) $e->show_in_website), 'can_use_store_value' => $this->getForm()->canUseWebsiteValue((int) $e->show_in_store)));
// Add Validation
if ($e->validate) {
$field->addClass($e->validate);
}
// Determine if value can be empty
if (isset($e->frontend_type) && 'multiselect' === (string) $e->frontend_type && isset($e->can_be_empty)) {
$field->setCanBeEmpty(true);
}
// Set Field Renderer
$field->setRenderer($fieldRenderer);
// Use Source Model to define available options
if ($e->source_model) {
$sourceModel = Mage::getSingleton((string) $e->source_model);
if ($sourceModel instanceof Varien_Object) {
$sourceModel->setPath($path);
}
$field->setValues($sourceModel->toOptionArray());
}
return $field;
}
示例9: _getSelectHtml
/**
* Select field filter HTML.
*
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @return string
*/
protected function _getSelectHtml(Mage_Eav_Model_Entity_Attribute $attribute)
{
if ($attribute->getFilterOptions()) {
$options = array();
foreach ($attribute->getFilterOptions() as $value => $label) {
$options[] = array('value' => $value, 'label' => $label);
}
} else {
$options = $attribute->getSource()->getAllOptions(false);
}
if ($size = count($options)) {
// add empty vaue option
$firstOption = reset($options);
if ('' === $firstOption['value']) {
$options[key($options)]['label'] = '';
} else {
array_unshift($options, array('value' => '', 'label' => ''));
}
$selectBlock = new Mage_Core_Block_Html_Select(array('name' => $this->getFilterElementName($attribute->getAttributeCode()), 'id' => $this->getFilterElementId($attribute->getAttributeCode()), 'class' => 'select', 'extra_params' => 'style="width:280px"'));
return $selectBlock->setOptions($options)->getHtml();
} else {
return $this->_helper->__('Attribute does not has options, so filtering is impossible');
}
}
示例10: _getGwsValue
/**
* Retrieves scope dependent value from fixture value, i.e,
* store view or
* website attribute value
*
*
* @param array $row
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param string $scopeCode
* @param string $scopeType
* @return mixed|null
*/
protected function _getGwsValue($row, $attribute, $scopeCode, $scopeType = self::SCOPE_TYPE_STORE)
{
if (!isset($row['/' . $scopeType][$scopeCode]) || !is_array($row['/' . $scopeType][$scopeCode]) || !isset($row['/' . $scopeType][$scopeCode][$attribute->getAttributeCode()])) {
return null;
}
return $this->_getAttributeValue($row['/' . $scopeType][$scopeCode], $attribute);
}
示例11: _updateAttribute
/**
* add product eav Attribute to document
*
* @param int $storeId
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param array $documents
* @return array
*/
public function _updateAttribute($storeId, $attribute, $documents = null)
{
$fields = $this->getMappings($storeId);
$adapter = $this->_getReadAdapter();
if ($attribute->getBackend()->getType() == 'static') {
var_dump('not implemented yet');
return $this;
if (false === isset($describe[$attribute->getAttributeCode()])) {
return $this;
}
$select = $adapter->select()->join(array('main_table' => $this->getTable('catalog/product')), 'main_table.entity_id = e.entity_id', array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()));
$select->where('main_table.entity_id IN(?)', array_map('intval', array_keys($documents)));
$sql = $select->crossUpdateFromSelect(array('e' => $flatTableName));
var_dump($sql);
die;
$adapter->query($sql);
} else {
//non static attributes
$columns = $attribute->getFlatColumns();
if (!$columns) {
return $this;
}
foreach (array_keys($columns) as $columnName) {
if (false === isset($fields[$columnName])) {
return $this;
}
}
$select = $attribute->getFlatUpdateSelect($storeId);
$select->from(array('e' => $this->getTable('catalog/product')), 'entity_id');
if ($select instanceof Varien_Db_Select) {
$select->where('e.entity_id IN(?)', array_map('intval', array_keys($documents)));
foreach ($adapter->query($select)->fetchAll() as $data) {
$documentId = $data['entity_id'];
//remove entity id Field
unset($data['entity_id']);
if (true === isset($documents[$documentId])) {
if (true === is_array($data) && count($data) > 0) {
foreach ($data as $field => $value) {
$documents[$documentId]->set($field, $value);
}
}
}
}
}
}
return $documents;
}
示例12: 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;
}
示例13: decorateFilter
/**
* Create filter fields for 'Filter' column.
*
* @param mixed $value
* @param Mage_Eav_Model_Entity_Attribute $row
* @param Varien_Object $column
* @param boolean $isExport
* @return string
*/
public function decorateFilter($value, Mage_Eav_Model_Entity_Attribute $row, Varien_Object $column, $isExport)
{
$value = null;
$values = $column->getValues();
if (is_array($values) && isset($values[$row->getAttributeCode()])) {
$value = $values[$row->getAttributeCode()];
}
switch (Mage_ImportExport_Model_Export::getAttributeFilterType($row)) {
case Mage_ImportExport_Model_Export::FILTER_TYPE_SELECT:
$cell = $this->_getSelectHtmlWithValue($row, $value);
break;
case Mage_ImportExport_Model_Export::FILTER_TYPE_INPUT:
$cell = $this->_getInputHtmlWithValue($row, $value);
break;
case Mage_ImportExport_Model_Export::FILTER_TYPE_DATE:
$cell = $this->_getDateFromToHtmlWithValue($row, $value);
break;
case Mage_ImportExport_Model_Export::FILTER_TYPE_NUMBER:
$cell = $this->_getNumberFromToHtmlWithValue($row, $value);
break;
default:
$cell = $this->_helper->__('Unknown attribute filter type');
}
return $cell;
}
示例14: _createAttributeOption
/**
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param string $optionLabel
*/
protected function _createAttributeOption($attribute, $optionLabel)
{
$option = array('value' => array(array('0' => $optionLabel)), 'order' => array(0), 'delete' => array(''));
$attribute->setOption($option);
$attribute->save();
$this->_attributeOptions[$attribute->getAttributeCode()][] = $optionLabel;
$this->_initTypeModels();
}
示例15: _lockAttribute
/**
* Lock a specific category or product attribute so that it can not be editted through the interface.
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param Mage_Catalog_Model_Abstract $model
* @param $profile
*/
protected function _lockAttribute(Mage_Eav_Model_Entity_Attribute $attribute, Mage_Catalog_Model_Abstract $model, $profile)
{
$note = $attribute->getNote() ? $attribute->getNote() : '';
if ($attribute->getAttributeCode() == 'ho_import_profile') {
return;
}
if ($note) {
$note .= "<br />\n";
}
$note .= Mage::helper('ho_import')->__("Locked by import: <i>%s</i>", $profile);
$model->lockAttribute($attribute->getAttributeCode());
$attribute->setNote($note);
}