I'm currently using this snippet to show the cart totals in the topcart of my Magento shop. My problem is that it's not always updating when products is put in cart, it's just showing 0$, especially configurable products. But when a second product is put in the cart, it's working again.

Am I missing something, should there be a "check" of some kind before this piece of code?

<?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>
有帮助吗?

解决方案

You can also try following code it works for me

<?php echo Mage::helper('checkout/cart')->getQuote()->getSubtotal() ?>

其他提示

Make sure your top cart block is extending a relevant block type such as Mage_Checkout_Block_Cart_Sidebar. If you do, you will have access to useful functionality that will save you rewriting unnecessary code.

For example, if you extend Mage_Checkout_Block_Cart_Sidebar - you can call getSubtotal()

An alternative would be to use the following:

Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();

you can use this code:

$subtotals= Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();

echo $formattedPrice = Mage::helper('core')->currency($subtotals , true, false);

None of the above worked for me but I was able to get the subtotal using this:

$orderObj = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$orderSubTotal = $orderObj->getSubtotal();
echo $orderSubTotal;

This refers to the success.phtml page.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top