如何获取单个属性的所有商店视图的所有选项?


13

我正在尝试为单个属性(例如)检索所有商店视图的所有选项color

对于属性,color我创建了两个选项bluewhite。我尝试了以下代码,该代码假定为所有商店视图返回所有选项标签,但仅为admin我返回选项标签。

$option_arr = array();
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
  $option_arr[$option['value']] = $option['label'];
}
// $option_arr contains Array([4] => Blue, [3] => White)

下面的方法对于获取color每个商店视图的所有属性标题均适用,但不适用于选项。

$product = Mage::getModel('catalog/product')->load();
$attribute_title = $product->getResource()->getAttribute('color');
// $attribute_title contains Array([1] => ~~~, [2] =>Color, [3] => Couleur, [4] => Còôlòôr)

我的颜色属性和选项的屏幕截图。

Answers:


16
    /**
     * @var $config  Mage_Eav_Model_Config
     * @var $options Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection
     */
    $storeId   = 3;
    $config    = Mage::getModel('eav/config');
    $attribute = $config->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'color');
    $values    = $attribute->setStoreId($storeId)->getSource()->getAllOptions();
    print_r($values);

    //here is another method
    $options = Mage::getResourceModel('eav/entity_attribute_option_collection');
    $values  = $options->setAttributeFilter($attribute->getId())->setStoreFilter($storeId)->toOptionArray();
    print_r($values);

以及如何将其保存到1个特定的storeview?
snh_nl
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.