如何从不同的范围访问Magento Model数据

Jon*_*Day 3 attributes scope magento

我要求访问多网站/多商店网站上另一个范围中指定的属性的值.特别是,当设置了Store的标签时,我们需要在前端显示属性的Admin(默认)标签.

在此输入图像描述

因此,代码应该在页面的一部分中从Admin列呈现Hex值,在页面的另一部分上呈现来自英语(US)的文本描述.我怎么做?

相反,我已经看到了在Store View上设置了值但是Default为null的实例,即使已经设置了Store,代码也会返回null.有人可以解释一下这有用吗?

Vin*_*nai 6

以下是使用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());
Run Code Online (Sandbox Code Playgroud)

根据需要调整.