2013-08-28 3 views
0

나는 magento 1.7을 개발 중입니다. 나는 인보이스 수수료를 추가 한 지불 게이트웨이에서 일하고 있습니다. 세금 그룹에 인보이스 수수료를 추가해야합니다. enter image description here송장 수수료 세금을 magento order로 추가 할 수 없습니다.

이 코드를 따르는 사람은 누구나 세금을 추가하려고했습니다. 하지만 여전히 뭔가 잘못

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

} 

을하고있는 중이 될 수 있습니다 작업이는

<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> 

답변

1

코드가 내가 코드를 수정 한 다음 한 다음해야 config.xml에하지

,
<?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; 
    } 
} 
관련 문제