Reputation: 11
It is necessary for me to get a list of all the meanings an attribute of “color”. when i use this code
$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);
In that case I get that kind of list:
(
[0] => Array
(
[value] => 6
[label] => blueAdmin
)
[1] => Array
(
[value] => 5
[label] => coralAdmin
)
[2] => Array
(
[value] => 3
[label] => redAdmin
)
[3] => Array
(
[value] => 4
[label] => limeAdmin
)
)
It is the list of all meanings which are displayed in administration's part of website. How can I get a list of all meanings of attributes which are displayed in the shop not in administration's part of website?
Thank you.
Upvotes: 1
Views: 6906
Reputation: 225
You can get the attribute option values for a particular store by setting the store ID on the attribute prior to calling getAllOptions(), e.g.,
$attributeOptions = $attribute->setStoreId(1)->getSource()->getAllOptions(false);
gets the option values for the store with ID 1. You can get the ID of the current store with
Mage::app()->getStore()->getId();
So something like this should get you what you want:
$storeId = Mage::app()->getStore()->getId();
$attributeOptions = $attribute->setStoreId($storeId)->getSource()->getAllOptions(false);
Upvotes: 2