Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在magento订单总额中添加发票费用税_Magento_Payment Gateway - Fatal编程技术网

无法在magento订单总额中添加发票费用税

无法在magento订单总额中添加发票费用税,magento,payment-gateway,Magento,Payment Gateway,我正在研究magento 1.7。我在支付网关上工作,在那里我已经添加了发票费,现在我必须在税务组中添加发票费税 请任何人帮助解决这个问题,这里是按照我的代码,我已经尝试添加税收金额,但仍然没有工作,可能是我做错了什么 <?php class ***_******_Model_Quote_TaxTotal extends Mage_Sales_Model_Quote_Address_Total_Tax { public function collect(Mage_Sal

我正在研究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;
    }

}

您的代码必须遵循我已遵循我修改了您的代码

<?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;
    }
}

<?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;
    }
}