2011-11-11 84 views
3

我想在购物车中显示每种产品的总价格(通过ID)。Magento - 如何获得购物车中单个产品的小计?

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); 

任何帮助是值得欢迎的。

回答

6

你可以使用:

$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(); 
    } 
} 
+1

这就是它!非常感谢你 :-) – tecmec

相关问题