1

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

我想要实现的是这样的:

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

attributeOptionLabel 是当前属性选项标签。

4

1 回答 1

12

简单的!参考Mage_Eav_Model_Entity_Attribute::getStoreLabel()[链接]

<?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()
);
于 2012-12-03T14:05:42.413 回答