这里有一些线程解释了如何在购物车或结帐中获取产品属性。 但是,我就是无法让它工作。
在购物车中,我可以看到产品属性,但在结帐中看不到。
从我读到的内容来看,结帐不知道产品,所以我需要加载它。 这可以解释为什么我没有看到它。
我已经尝试了很多东西,但我要么没有将我的运输步骤加载到购物车中,要么它只是不显示。
任何帮助都会很棒! 这是我在自定义运输模块中的代码。
$cart = Mage::getSingleton('checkout/session');
//Order value by category
$gold = 0;
foreach ($cart->getQuote()->getAllItems() as $item) {
$itemPrice = $item->getPrice();
$qty = $item->getQty();
$metalType = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getAttributeText('metal');
if ($metalType == "Gold") {
//Apply some business logic
$gold = $itemPrice * $qty;
}
}
Magento获得购物车单件商品价格含税
Magento产品属性获取值
在Mage_Sales_Model_Resource_Quote_Item_Collection
对象的afterLoad
中,调用一个方法来_assignProducts
每个引用项。 此方法使用以下代码加载产品集合:
$productCollection = Mage::getModel('catalog/product')->getCollection()
->setStoreId($this->getStoreId())
->addIdFilter($this->_productIds)
->addAttributeToSelect(Mage::getSingleton('sales/quote_config')->getProductAttributes())
->addOptionsToResult()
->addStoreFilter()
->addUrlRewrite()
->addTierPriceData();
如果通过以下方式将产品属性添加到新模块的配置.xml中,则应将其添加为要在产品系列中选择的属性。
<sales>
<quote>
<item>
<product_attributes>
<metal/>
</product_attributes>
</item>
</quote>
</sales>