与获取有关的问题";“默认商店视图”;Magento中自定义属性的值?

与获取有关的问题";“默认商店视图”;Magento中自定义属性的值?,magento,Magento,我使用下面的代码来获取属性名 $attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','pricee'); echo $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId); $attribute->getFrontendLabel() 在这个“pric

我使用下面的代码来获取属性名


$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','pricee');
echo $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);

$attribute->getFrontendLabel()

在这个“price”中是属性代码。但输出不是所需的,而是检索“Admin”下的值。下面的屏幕显示了我需要显示的实际字段

我做错了什么?请建议。

Mage::app()->setCurrentStore('default')

这将选择您要查找的默认存储

您还可以尝试使用getStoreLabel($storeId)函数来获取更具体的内容

此函数位于:/app/code/core/Mage/Eav/Model/Entity/Attribute.php,如下所示:

/**
 * Return store label of attribute
 *
 * @return string
 */
public function getStoreLabel($storeId = null)
{
    if ($this->hasData('store_label')) {
        return $this->getData('store_label');
    }
    $store = Mage::app()->getStore($storeId);
    $label = false;
    if (!$store->isAdmin()) {
        $labels = $this->getStoreLabels();
        if (isset($labels[$store->getId()])) {
            return $labels[$store->getId()];
        }
    }
    return $this->getFrontendLabel();
}
嗯,


Shaun O'Reilly

事实上,以下代码在我的案例中起了作用


$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','ATTRIBUTE_CODE_HERE');
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions();

echo $attribute->getStoreLabels();

 
这个函数的输出是:
Array
(
[1] =>价格
)

Hmm,尝试添加
Mage::app()->setCurrentStore()在开头。