magento - get attribute option label by store view

可紊 提交于 2019-12-08 07:34:05

问题


Like the title, how can I get the attribute option value of a specific store view instead of the current store view ?

What I am trying to implement is something like this :

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

The attributeOptionLabel is the current attribute option label.


回答1:


Simple! Ref 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()
);


来源:https://stackoverflow.com/questions/13683378/magento-get-attribute-option-label-by-store-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!