![](/img/trans.png)
[英]How do I edit a product attribute using PHP during a cart checkout in Magento?
[英]Magento product attribute not showing in checkout, shows in cart
这里有一些线程解释如何在购物车或结帐中获取产品属性。 但是,我只是无法正常工作。
在购物车中,我可以看到产品属性,但在结帐处却看不到。
根据我的阅读,结帐不了解该产品,因此我需要加载它。 这可以解释为什么我看不到它。
我已经尝试了很多东西,但是要么我的运输步骤无法加载到购物车中,要么就没有显示。
任何帮助将是巨大的! 这是我的自定义运输模块中的代码。
$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;
}
}
在Mage_Sales_Model_Resource_Quote_Item_Collection
对象的afterLoad
中, Mage_Sales_Model_Resource_Quote_Item_Collection
了一个方法_assignProducts
到每个报价项目。 此方法使用以下代码加载产品集合:
$productCollection = Mage::getModel('catalog/product')->getCollection()
->setStoreId($this->getStoreId())
->addIdFilter($this->_productIds)
->addAttributeToSelect(Mage::getSingleton('sales/quote_config')->getProductAttributes())
->addOptionsToResult()
->addStoreFilter()
->addUrlRewrite()
->addTierPriceData();
如果通过以下方式将产品属性添加到新模块的config.xml中,则应将其添加为要在产品集合中选择的属性。
<sales>
<quote>
<item>
<product_attributes>
<metal/>
</product_attributes>
</item>
</quote>
</sales>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.