magento - 按商店视图获取属性选项标签

时间:2012-12-03 12:34:39

标签: magento magento-1.7

与标题一样,如何获取特定商店视图的属性选项值而不是当前商店视图?

我想要实现的是这样的:

public function getAttributeOptionValue($attributeCode, $attributeOptionLabel, $storeView)

attributeOptionLabel是当前属性选项标签。

1 个答案:

答案 0 :(得分:12)

简单!参考Mage_Eav_Model_Entity_Attribute::getStoreLabel() [link]

<?php

include 'app/Mage.php';
Mage::app('default');

//Generic access
$eavConfig = Mage::getSingleton('eav/config');
/* @var $eavConfig Mage_Eav_Model_Config */

$eavAttribute = $eavConfig->getAttribute(
    Mage_Catalog_Model_Product::ENTITY,  // 'catalog_product'; see db.eav_entity_type
    'description'                        // attribute code
);
/* @var $eavAttribute Mage_Eav_Model_Entity_Attribute */

Zend_Debug::dump(
    $eavAttribute->getStoreLabel('admin')
);


//For a given EAV entity-based model, the resource requires only the attribute
$product = Mage::getModel('catalog/product')->load(2);
/* @var $product Mage_Catalog_Model_Product */

$productAttribute = $product->getResource()->getAttribute('description');
/* @var $productAttribute Mage_Eav_Model_Entity_Attribute */

Zend_Debug::dump(
    $productAttribute->getStoreLabel('admin')
);

//It's also possible to get all labels:
Zend_Debug::dump(
    $productAttribute->getStoreLabels()
);
相关问题