在购物车中获得全面的总计&发票

时间:2017-06-23 11:11:29

标签: magento magento-1.9 magento-1.9.1 magento-1.9.2.1 magento-1.9.2.4

我想要舍入总计所以,我已经创建了自定义模块并重写了核心模型

我的重写模型代码在

之下

1。 Mage_Sales_Model_Quote_Address_Total_Grand

<?php
class Lr_Roundtotal_Model_Quote_Address_Total_Grand extends Mage_Sales_Model_Quote_Address_Total_Grand
{
    public function collect(Mage_Sales_Model_Quote_Address $address)    
    {        
        $grandTotal     = $address->getGrandTotal();        
        $baseGrandTotal = $address->getBaseGrandTotal();        
        $totals     = array_sum($address->getAllTotalAmounts());        
        $baseTotals = array_sum($address->getAllBaseTotalAmounts());        
        $address->setGrandTotal(round($grandTotal+$totals)); //Modificated        
        $address->setBaseGrandTotal(round($baseGrandTotal+$baseTotals)); //Modificated        
        //$address->setGrandTotal($grandTotal+$totals);  --Original        
        //$address->setBaseGrandTotal($baseGrandTotal+$baseTotals); --Original        
        return $this;    
    } 

    public function fetch(Mage_Sales_Model_Quote_Address $address)    
    {        
        $address->addTotal(array(            
            'code'  => $this->getCode(),            
            'title' => Mage::helper('sales')->__('Grand Total'),            
            'value' => round($address->getGrandTotal()),            
            'netvalue' => round($address->getGrandTotal()),            
            'area'  => 'footer',        
        ));                
        return $this;    
    }   
}

,第二个是

2.Mage_Sales_Model_Order_Invoice

<?php
    class Lr_Roundtotal_Model_Order_Invoice extends Mage_Sales_Model_Order_Invoice
    {
        public function pay()
        {
            if ($this->_wasPayCalled) {
                return $this;
            }
            $this->_wasPayCalled = true;

            $invoiceState = self::STATE_PAID;
            if ($this->getOrder()->getPayment()->hasForcedState()) {
                $invoiceState = $this->getOrder()->getPayment()->getForcedState();
            }

            $this->setState($invoiceState);

            $this->getOrder()->getPayment()->pay($this);
            $this->getOrder()->setTotalPaid(
                round($this->getOrder()->getTotalPaid()+$this->getGrandTotal())  //Modificated 
                // $this->getOrder()->getTotalPaid()+$this->getGrandTotal()  --Original
            );
            $this->getOrder()->setBaseTotalPaid(
                round($this->getOrder()->getBaseTotalPaid()+$this->getBaseGrandTotal())  //Modificated 
                // $this->getOrder()->getBaseTotalPaid()+$this->getBaseGrandTotal()  --Original
            );
            Mage::dispatchEvent('sales_order_invoice_pay', array($this->_eventObject=>$this));
            return $this;
        }   
    }

=&gt;例如

小计:990.00

折扣:120.70

总计: 869.00 (四舍五入)

发票

小计:990.00

折扣:120.70

总计: 869.30 (未完成)

我想要购物车中的相同总额和发票所以,请帮助我

提前致谢

1 个答案:

答案 0 :(得分:0)

在本地覆盖核心文件后,请执行以下代码。

首先在HELPER文件中创建一个函数,如下所示(无需创建新模块,但可以将此函数放在任何模块助手文件中):

Namespace_module_helper_data extends Mage_Core_Helper_Abstract 
{
   public function getFormatedPrice($price)     
   {
     return Mage::getModel('directory/currency')->format($price, array('display'=>Zend_Currency::NO_SYMBOL), false);    
   } 
}

然后您可以使用此功能,您需要在magento的任何位置舍入价格。

您可以使用如下的帮助函数:

$helper = Mage::helper('modulename'); // module name means name of the module in which you have create helper

使用以下圆形价格的函数:

$price = 120.12456;
echo $helper->getFormatedPrice($price); // you can get round price as per your store.

由于