【问题标题】:Magento - Get session GrandTotal?Magento - 获取会话 GrandTotal?
【发布时间】:2014-11-06 18:26:41
【问题描述】:

现在我正在使用 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";
?>  

但它没有打印总计的价值。 我的错误在哪里,我怎样才能让这件事发挥作用?

提前致谢!

【问题讨论】:

    标签: php magento


    【解决方案1】:

    只需复制并运行它

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

    【讨论】:

      【解决方案2】:
       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();
      

      【讨论】:

      • 好吧,但我实际上如何获取登录用户的 id ?
      • 可以,可以通过customer id,获取订单转化为购物车数据
      【解决方案3】:

      只需将以下代码复制并粘贴到您想要的文件中即可。

      $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
      

      【讨论】:

        【解决方案4】:

        这对我来说没问题。

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-08-19
          • 1970-01-01
          • 1970-01-01
          • 2011-09-09
          • 1970-01-01
          相关资源
          最近更新 更多