は、Magentoのクラスを使用してそれを行う方法です。必要に応じて
// Get the model of the attribute in question
/* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'color');
// Load the option collection for that attribute adding the storeFilter()
/* @var $collection Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection */
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setPositionOrder('asc')
->setAttributeFilter($attribute->getId())
->setStoreFilter();
// Load the product so we can get the correct option from the collection
$product = Mage::getModel('catalog/product')->load(39);
$productOption = $collection->getItemById($product->getColor());
printf("Default: %s, Store: %s\n", $productOption->getDefaultValue(), $productOption->getValue());
を調整します。
ありがとうございました。エレガントでよく書かれています。私は製品に全面的な負荷をかけないようにしたいので、config.xmlのデフォルトのコレクション属性に属性を追加すると思います。また、属性オプションのコレクションはキャッシュされていますか? –
属性の 'used_in_product_listing'プロパティを設定するだけで十分なデータがある場合は、config.xmlに追加する必要はありません。 – Vinai
オプション収集データは、デフォルトではキャッシュされません。あなたはコレクションキャッシングを使って素早くそれを実装することができますhttp://tweetorials.tumblr.com/post/10203426431/magento-block-caching – Vinai