gpt4 book ai didi

Magento - 如何获取购物车中单个产品的小计?

转载 作者:行者123 更新时间:2023-12-02 16:51:38 25 4
gpt4 key购买 nike

我想显示购物车中每种产品的总价(按 ID)。

qty | single price | total
2 | $ 2.00 | $ 4.00 <-- that's what i need
3 | $ 5.00 | $ 15.00
| Subtotals: | $ 19.00 <-- that's what i get with the code below

$totals = Mage::getSingleton("checkout/cart")->getQuote()->getTotals();
$subtotal = $totals["subtotal"]->getValue();
echo Mage::helper('checkout')->formatPrice($subtotal);

欢迎任何帮助。

最佳答案

您可以使用:

$productId = 5;//put here the product id you want the price
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllItems();
foreach ($items as $item) {
if ($item->getProductId() == $productId) {
$priceInclVat = $item->getRowTotalInclTax();
}
}

关于Magento - 如何获取购物车中单个产品的小计?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8091227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com