我已经为我的结帐添加了额外的费用,但税额没有正确计算.
如果我执行$this-> _calculateTax($address),则税额不会正确累加;在收集功能中,它加起来包括税,但我的税额仍然是.
如果是var_dump,则在$address-> setAppliedTaxes($prevIoUsAppliedTaxes)行之后设置应用税;我确实看到了正确的金额.它转储了两次,第一次看到正确的税额只是我的额外费用,第二次是正确的总税额.但是在前端它显示了税收而没有我的额外费用税.
关于这可能是什么的任何线索?
class Company_Customer_Model_Quote_Address_Total_PrintPrepCosts extends Mage_Sales_Model_Quote_Address_Total_Abstract { public function __construct() { $this->setCode('printPrepCosts'); $this->_store = Mage::app()->getStore(); return $this; } public function collect(Mage_Sales_Model_Quote_Address $address) { parent::collect($address); $address->setPrintPrepcosts(0); $address->setTaxAmount(0); $address->setBaseTaxAmount(0); if(count($address->getAllItems()) == 0) { return $this; } $pricePrint = $this->calcTotalPrintPrepCosts(); $address->setPrintPrepcosts($pricePrint); $address->setBasePrintPrepcosts($pricePrint); $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getPrintPrepcosts()); $address->setGrandTotal($address->getGrandTotal() + $address->getPrintPrepcosts()); $this->_calculateTax($address); return $this; } protected function _calculateTax(Mage_Sales_Model_Quote_Address $address) { $calculator = Mage::getSingleton('tax/calculation'); $inclTax = Mage::getStoreConfig('tax/calculation/printing_prep_includes_tax',$this->_store); $taxRateRequest = $calculator->getRateRequest( $address,$address->getQuote()->getBillingAddress(),$address->getQuote()->getCustomerTaxClassId(),$this->_store ); // TODO undef prop _store $taxRateRequest->setProductClassId(Mage::getStoreConfig('tax/classes/printing_prep_tax_class',$this->_store)); $rate = $calculator->getRate($taxRateRequest); $baseTax = $tax = $calculator->calcTaxAmount($address->getPrepPrintcosts(),$rate,$inclTax,true); $address->addTotalAmount('tax',max(0,$tax)); $address->addBaseTotalAmount('tax',$baseTax)); $this->_saveAppliedTaxes($address,$calculator->getAppliedRates($taxRateRequest),$tax,$baseTax,$rate ); // later on added - which fixes the total,lose tax amount still off $address->setTaxAmount($tax); $address->setBaseTaxAmount($baseTax); if($inclTax) { $address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseTax); $address->setGrandTotal($address->getGrandTotal() - $tax); } } protected function _saveAppliedTaxes(Mage_Sales_Model_Quote_Address $address,$applied,$amount,$baseAmount,$rate) { $prevIoUslyAppliedTaxes = $address->getAppliedTaxes(); $process = count($prevIoUslyAppliedTaxes); foreach ($applied as $row) { if (!isset($prevIoUslyAppliedTaxes[$row['id']])) { $row['process'] = $process; $row['amount'] = 0; $row['base_amount'] = 0; $prevIoUslyAppliedTaxes[$row['id']] = $row; } if (!is_null($row['percent'])) { $row['percent'] = $row['percent'] ? $row['percent'] : 1; $rate = $rate ? $rate : 1; $appliedAmount = $amount/$rate*$row['percent']; $baseAppliedAmount = $baseAmount/$rate*$row['percent']; } else { $appliedAmount = 0; $baseAppliedAmount = 0; foreach ($row['rates'] as $rate) { $appliedAmount += $rate['amount']; $baseAppliedAmount += $rate['base_amount']; } } if ($appliedAmount || $prevIoUslyAppliedTaxes[$row['id']]['amount']) { $prevIoUslyAppliedTaxes[$row['id']]['amount'] += $appliedAmount; $prevIoUslyAppliedTaxes[$row['id']]['base_amount'] += $baseAppliedAmount; } else { unset($prevIoUslyAppliedTaxes[$row['id']]); } } $address->setAppliedTaxes($prevIoUslyAppliedTaxes); } public function fetch(Mage_Sales_Model_Quote_Address $address) { $address->addTotal(array( 'code' => $this->getCode(),'title' => "Prep Print costs",'value' => $address->getPrintPrepcosts(),)); return $this; }@H_403_8@编辑1
XML包含这个:<sales> <quote> <totals> <printPrepCosts> <class>Company_Customer_Model_Quote_Address_Total_PrintPrepCosts</class> <after>subtotal</after> <before>tax</before> </printPrepCosts> </totals> </quote> </sales>@H_403_8@编辑2
我已经将以下行添加到我的calcTax函数中,这确实修复了总计,但TAX的数量仍然是关闭的.$address->setTaxAmount($tax); $address->setBaseTaxAmount($baseTax);@H_403_8@输出 – 示例
Subtotal € 67,50 printPrepCosts € 40,00 Shipping € 50,00 TAX € 22,33 Total € 187,43@H_403_8@编辑3
我的不好,只有GoMage onepage checkout给出了正确的总计,购物车没有.常规的Magento onepage checkout也提供了错误的格式.
我找到了一个解决方法,它不是最好的解决方案,但确实有效:)
原文链接:https://www.f2er.com/php/137251.html在我的地址中,我将税收设置为一个额外的变量,称为税,并在观察者中使用它来操纵税收.
class Company_Client_Model_Observer { public function setCorrectTax ($observer) { $quote = $observer->getQuote(); foreach ($quote->getAllAddresses() as $address) { $printPrepCosts = $address->getPrintPrepcosts(); if(!empty($printPrepCosts)) { $address->setTaxAmount($address->tax); } } } }@H_403_8@和XML
<events> <sales_quote_collect_totals_after> <observers> <client> <type>singleton</type> <class>client/observer</class> <method>setCorrectTax</method> </client> </observers> </sales_quote_collect_totals_after> </events>@H_403_8@