我正在研究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>
答案 0 :(得分: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;
}
}