我有一個自定義屬性,我需要在購物車中顯示。該屬性是一個下拉像這樣:Magento - 在config.xml中檢索購物車中的自定義屬性LABEL
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 /值(即67),但我希望能夠獲得標籤(即倉庫)
我知道我可以從ID獲得一個標籤,像這樣:
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("section");
if ($attr->usesSource()) {
$_label = $attr->getSource()->getOptionText("67");
}
但我想通過我的模塊,以獲取標籤,所以我可以剪切的額外databae查詢,無需加載的產品型號再次。我的購物車每個訂單可以有20件以上的商品,所以使用這種最後一種方法可以稍微減慢它的速度。
Spot on。性能似乎也沒有受到影響。謝謝 – 2015-06-01 14:57:08
如果您想獲得StoreLabel而不是AttributeText,您會做什麼?當我的代碼碰到頁面時,我似乎無法獲取StoreLabel。 '$ _item-> getProduct->的getAttribute( 'attribute_code') - > getStoreLabel();' – Xander 2015-07-23 15:49:50