2011-11-11 81 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

相關問題