有时候我们要像下图那样显示产品的件数和总价格
1.购买的产品数
[php]<?php
if(Mage::getSingleton(‘checkout/session’)->getQuote()->getItemsSummaryQty() > 0){
$count = Mage::getSingleton(‘checkout/session’)->getQuote()->getItemsSummaryQty();
}else{
$count = 0;
}
echo $count;
?>[/php]
或
[php]<?php
if(Mage::helper(‘checkout/cart’)->getCart()->getSummaryQty() > 0){
$count = Mage::helper(‘checkout/cart’)->getCart()->getSummaryQty();
}else{
$count = 0;
}
echo $count;
?>[/php]
2. 显示总金额
[php]
<?php $subTotal = Mage::getModel(‘checkout/cart’)->getQuote()->getGrandTotal(); ?>
<?php echo Mage::helper(‘checkout’)->formatPrice($subTotal) ?>
[/php]
或者下面方法
注意:下面方法显示总金额他的货币符号不会变化,一直都是默认的符号
[php]<?php
$totals = Mage::getSingleton(‘checkout/cart’)->getQuote()->getTotals();
$subtotal = $totals["subtotal"]->getValue();
echo Mage::getModel(‘core/store’)->formatPrice($subtotal,false);
?>[/php]
可以把这句
[php]Mage::getModel(‘core/store’)->formatPrice($subtotal,false);[/php]
改成
[php]Mage::helper(‘checkout’)->formatPrice($subtotal,false);[/php]
发表评论