2013-08-04 65 views
1

我需要獲取「color」屬性的所有含義列表。當我使用此代碼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 
      ) 
    ) 

這是顯示在網站的管理的一部分的所有含義的列表。我怎樣才能得到在店鋪中顯示的屬性的所有含義列表,而不是在管理部門的網站中?

謝謝。

回答

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);