【问题标题】:unable to add invoice fee tax in magento order total无法在 magento 订单总额中添加发票费用税
【发布时间】:2013-08-28 11:17:11
【问题描述】:

我正在开发 magento 1.7。我正在开发支付网关,我已经添加了发票费用现在我必须在税组添加发票费用的税金

请任何人帮助解决这个问题,这是按照我的代码进行的

<?php

class ***_******_Model_Quote_TaxTotal
    extends Mage_Sales_Model_Quote_Address_Total_Tax
{

    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        $quote = $address->getQuote();
        if (($quote->getId() == null)
            || ($address->getAddressType() != "shipping")
        ) {
            return $this;
        }

        $payment = $quote->getPayment();
        if (($payment->getMethod() != 'invoice')
            && (!count($quote->getPaymentsCollection()))
        ) {
            return $this;
        }

        try {
            /**
             * Instead of relying on hasMethodInstance which would not always
             * work when i.e the order total is reloaded with coupon codes, we
             * try to get the instance directly instead.
             */
            $methodInstance = $payment->getMethodInstance();
        } catch (Mage_Core_Exception $e) {
            return $this;
        }

        if (!$methodInstance instanceof Mage_Payment_Model_Method_Abstract) {
            return $this;
        }

        if ($methodInstance->getCode() != 'invoice') {
            return $this;
        }

        $fee = $methodInstance->getAddressInvoiceFee($address);
        if(Mage::getStoreConfig('payment/invoice/tax_class') == '' ){
            return $this;
        }

        $invoiceFee = $baseInvoiceFee = Mage::getStoreConfig('payment/invoice/_fee');

        $fee = Mage::helper('invoice')->getInvoiceFeeArray($invoiceFee, $address, null);

        if (!is_array($fee)) {
            return $this;
        }
        $address->setTaxAmount($address->getTaxAmount() + 5454+ $fee['taxamount']);
        $address->setBaseTaxAmount(
            $address->getBaseTaxAmount() + 5454+ $fee['base_taxamount']
        );

        $address->setInvoiceTaxAmount($fee['taxamount']);
        $address->setBaseInvoiceTaxAmount($fee['base_taxamount']);
        return $this;
    }

}

这是 config.xml

    <sales>
        <quote>
            <totals>
                <fee>
                    <class>invoice/sales_quote_address_total_fee</class>
                </fee>
                <invoicetax>
                    <class>invoice/quote_taxTotal</class>
                    <after>subtotal,discount,shipping,tax</after>
                    <before>grand_total</before>
                </invoicetax>
            </totals>
        </quote>
    </sales>

【问题讨论】:

    标签: magento payment-gateway


    【解决方案1】:

    你的代码必须关注我已经修改了你的代码

    <?php
    
    class *****_******_Model_Quote_TaxTotal extends Mage_Sales_Model_Quote_Address_Total_Tax
    {
        public function collect(Mage_Sales_Model_Quote_Address $address)
        {
            $collection = $address->getQuote()->getPaymentsCollection();
            if ($collection->count() <= 0 || $address->getQuote()->getPayment()->getMethod() == null) {
                return $this;
            }
    
            $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
    
            if ($paymentMethod->getCode() != 'invoice') {            
                return $this;
            }
    
            $store = $address->getQuote()->getStore();        
    
            $items = $address->getAllItems();
            if (!count($items)) {
                return $this;
            }
    
            $custTaxClassId = $address->getQuote()->getCustomerTaxClassId();
    
            $taxCalculationModel = Mage::getSingleton('tax/calculation');
            /* @var $taxCalculationModel Mage_Tax_Model_Calculation */
            $request = $taxCalculationModel->getRateRequest(
                $address,
                $address->getQuote()->getBillingAddress(),
                $custTaxClassId,
                $store
            );
            $InvoiceTaxClass = Mage::helper('invoice')->getInvoiceTaxClass($store);
    
            $InvoiceTax      = 0;
            $InvoiceBaseTax  = 0;
    
            if ($InvoiceTaxClass) {
                if ($rate = $taxCalculationModel->getRate($request->setProductClassId($InvoiceTaxClass))) {
    
                    if (!Mage::helper('invoice')->InvoicePriceIncludesTax()) {
                        $InvoiceTax    = $address->getFeeAmount() * $rate/100;
                        $InvoiceBaseTax= $address->getBaseFeeAmount() * $rate/100;
                    } else {
                        $InvoiceTax    = $address->getPaymentTaxAmount();
                        $InvoiceBaseTax= $address->getBasePaymentTaxAmount();
                    }
    
                    $InvoiceTax    = $store->roundPrice($InvoiceTax);
                    $InvoiceBaseTax= $store->roundPrice($InvoiceBaseTax);
    
                    $address->setTaxAmount($address->getTaxAmount() + $InvoiceTax);
                    $address->setBaseTaxAmount($address->getBaseTaxAmount() + $InvoiceBaseTax);
    
                    $this->_saveAppliedTaxes(
                        $address,
                        $taxCalculationModel->getAppliedRates($request),
                        $InvoiceTax,
                        $InvoiceBaseTax,
                        $rate
                    );
                }
            }
    
            if (!Mage::helper('invoice')->InvoicePriceIncludesTax()) {
                $address->setInvoiceTaxAmount($InvoiceTax);
                $address->setBaseInvoiceTaxAmount($InvoiceBaseTax);
            }
    
            $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentTaxAmount());
            $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentTaxAmount());
    
            return $this;
        }
    
        public function fetch(Mage_Sales_Model_Quote_Address $address)
        {        
            $store = $address->getQuote()->getStore();
            /**
             * Modify subtotal
             */
    
             if (Mage::getSingleton('tax/config')->displayCartSubtotalBoth($store) ||
                Mage::getSingleton('tax/config')->displayCartSubtotalInclTax($store)) {
    
                if ($address->getSubtotalInclTax() > 0) {
                    $subtotalInclTax = $address->getSubtotalInclTax();
                } else {
                    $subtotalInclTax = $address->getSubtotal()+ $address->getTaxAmount() -
                        $address->getShippingTaxAmount() - $address->getPaymentTaxAmount();
                }            
    
                $address->addTotal(
                    array(
                        'code'      => 'subtotal',
                        'title'     => Mage::helper('sales')->__('Subtotal'),
                        'value'     => $subtotalInclTax,
                        'value_incl_tax' => $subtotalInclTax,
                        'value_excl_tax' => $address->getSubtotal()
                    )
                );
            }
            return $this;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-23
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 2015-04-12
      • 1970-01-01
      • 2011-09-26
      相关资源
      最近更新 更多