Magento - 获取所有属性值

时间:2013-08-04 13:55:11

标签: magento

我需要获得“颜色”属性的所有含义列表。当我使用这段代码时

$name='color';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
$attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions(false); 

在这种情况下,我会得到那种清单:

 (
        [0] => Array
            (
                [value] => 6
                [label] => blueAdmin
            )
        [1] => Array
            (
                [value] => 5
                [label] => coralAdmin
            )
        [2] => Array
            (
                [value] => 3
                [label] => redAdmin
            )
        [3] => Array
            (
                [value] => 4
                [label] => limeAdmin
            )
    ) 

这是在网站管理部分显示的所有含义的列表。如何获得商店中显示的属性的所有含义列表,而不是在管理部门的网站中?

谢谢。

1 个答案:

答案 0 :(得分:2)

您可以通过在调用getAllOptions()之前在属性上设置商店ID来获取特定商店的属性选项值,例如,

$attributeOptions = $attribute->setStoreId(1)->getSource()->getAllOptions(false);

获取ID为1的商店的选项值。您可以使用

获取当前商店的ID
Mage::app()->getStore()->getId();

所以这样的事情可以让你得到你想要的东西:

$storeId = Mage::app()->getStore()->getId();
$attributeOptions = $attribute->setStoreId($storeId)->getSource()->getAllOptions(false);