Magento - 获取会话GrandTotal?

时间:2014-11-06 18:26:42

标签: php magento

现在我正在使用Mangeto 1.9.1,我试图在Magento主目录中的外部php文件中获取会话顺序的GrandTotal值。

这是我的php文件:

<?php
    error_reporting(E_ALL | E_STRICT);
    $mageFilename = 'app/Mage.php';
    require_once $mageFilename;
    $app = Mage::app('default'); 
    Mage::app();


    $quote = Mage::getModel('checkout/session')->getQuote();
    $quoteData= $quote->getData();
    $grandTotal=$quoteData['grand_total'];


    echo "Grand: - $grandTotal";
?>  

但它没有印刷总计的价值。 我的错误在哪里,我可以使这件事有效?

提前致谢!

4 个答案:

答案 0 :(得分:3)

只需复制并运行

$grand=Mage::helper('checkout')->formatPrice(Mage::getModel('checkout/cart')->getQuote()->getGrandTotal());

答案 1 :(得分:0)

 Get less, because magento only when the user logs on, the only initialization shopping cart 
 information, you can simulate login reacquisition.you can use this code:
 $customer_id='8261';
 echo Mage::getModel('sales/quote')->loadByCustomer($customer_id)->getGrandTotal();

答案 2 :(得分:0)

只需将代码复制并粘贴到您希望的文件中即可。

$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount();//total items in cart

$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object

$subtotal = round($totals["subtotal"]->getValue()); //Subtotal value

$grandtotal = round($totals["grand_total"]->getValue()); //Grandtotal value

答案 3 :(得分:0)

我可以。

$grand=Mage::helper('checkout')->formatPrice(Mage::getModel('checkout/cart')->getQuote()->getGrandTotal());