2012-02-20 14 views
0

私はこの「pricee」に名前Magentoのカスタム属性の "Default Store View"値を取得する際に問題がありますか?

 

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

$attribute->getFrontendLabel() 

 

属性を取得するには、以下のコードを使用していますが、属性コードです。しかし出力は希望のものではなく、代わりに "管理者"の下の値が検索されます。画面の下には私が間違って何をやっている

enter image description here

を表示する必要がある実際のフィールドを示しますか?提案してください。

+0

ええ、最初に 'Mage :: app() - > setCurrentStore();を追加してみてください。 – Zyava

答えて

0

が実際に以下のコードは、私の場合で働いていた、この

 

$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] => Price )

2

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

HTH、

ショーン・オライリー

関連する問題