【发布时间】:2015-03-31 14:32:13
【问题描述】:
我有一个需要在购物车中显示的自定义属性。该属性是一个像这样的下拉列表:
Attribute Code : section
Catalog Input Type for Store Owner : Dropdown
Options:
ID/VALUE = 67 LABEL = warehouse
ID/VALUE = 69 LABEL = showroom
ID/VALUE = 70 LABEL = stockroom
为了显示这个,我有一个自定义模块和我的 config.xml,如下所示:
<global>
<sales>
<quote>
<item>
<product_attributes>
<section/>
</product_attributes>
</item>
</quote>
</sales>
我可以在购物车中调用:
$_item->getProduct()->getSection();
这将返回属性的 ID/VALUE(即 67),但我希望能够获取 LABEL(即仓库)
我知道我可以像这样从 id 中获取标签:
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("section");
if ($attr->usesSource()) {
$_label = $attr->getSource()->getOptionText("67");
}
但我想通过我的模块获取标签,这样我就可以删除额外的数据库查询并不得不再次加载产品模型。我的购物车每个订单可以有超过 20 件以上的商品,因此使用最后一种方法可以稍微减慢速度。
【问题讨论】:
标签: magento attributes cart