2014-11-06 92 views
0

現在我正在使用Mangeto 1.9.1,並且正在嘗試在主Magento目錄中的外部php文件中獲取會話順序的GrandTotal值。Magento - 獲取會話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"; 
?> 

但它不打印總計價值。 我的錯誤在哪裏我可以使這件事情工作?

在此先感謝!

回答

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(); 
+0

Okey但實際上我可以得到登錄的用戶的ID? – user2942786 2014-11-08 16:29:37

+0

是的,您可以通過客戶ID獲取轉換成購物車數據的訂單 – 2014-11-10 15:17:54

2

只需複製並運行它

$grand=Mage::helper('checkout')->formatPrice(Mage::getModel('checkout/cart')->getQuote()->getGrandTotal()); 
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