2011-09-26 12 views

答えて

50

異なるエンティティに同じattribute_codeを割り当てることができるので、entity_typeを知る必要があります。だから、属性モデルを取得する:

$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode($entity_type, $attributeCode); 

$entity_typeパラメータがnumeric(直接ID)、string(例えば、'catalog_product'またはMage_Catalog_Model_Product::ENTITYの場合)であることも、モデルMage_Eav_Model_Entity_Type

+0

ありがとうございます。私はあなたに結果を確認しようとします。 – vietean

+0

上記のコードを使用して、short_descriptionが 'フロントエンドのプロダクトビューページに表示されているかどうか'を確認してください: $ attributeShortDescription = Mage :: getModel( 'eav/entity_attribute') - > loadByCode( 'catalog_product'、 'short_description '); $ attributeShortDescription-> getIsVisibleOnFront(); –

+6

定数を使用するバージョン: $ _attr = Mage :: getModel( 'eav/entity_attribute') - > loadByCode(Mage_Catalog_Model_Product :: ENTITY、$ attributeCode); –

0

$ attributeModel =メイジ:: getModelのインスタンスであることができます( 'eav/entity_attribute') - > loadByCode(1、 'is_approved'); echo $ attributeModel-> getAttributeId();

+0

これは、多くのシナリオのうちの1つにのみ固有のデータを持つばかりでなく、受け入れられた回答をエコーし​​ます。コードはフォーマットされておらず、説明もありません。 –

3

おそらく、あなたは私がコードによって製品から属性を必要とするので、私はこのようにそれを行うコレクション

Mage::getModel('eav/entity_attribute')->getCollection()->addFieldToFilter('attribute_code', array('in' => $codes)) 

フィルタによって属性を読み取ることができます。

$codes = (array) $codes; 
    $res = array_intersect_key($this->getAttributes(), array_flip($codes)); 

$コードがattribute_codeです-array 範囲:拡張Mage_Catalog_Model_Product

3
$attribute_code = "flat_printing_quantity"; 
$attribute_details = 
Mage::getSingleton("eav/config")->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attribute_code); 
$attribute = $attribute_details->getData(); 
echo $attribute['attribute_id']; 
関連する問題