Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento: tax wrong on extra fee in checkout
    text
    copied!<p>I've added an extra fee to my checkout and but the tax isn't calculated correctly.</p> <p>The amount of tax is not added up correctly, if I do $this->_calculateTax($address); in the collect function it is added up to the total including tax but my amount of tax is still of then. </p> <p>if is var_dump the set applied taxes after the line $address->setAppliedTaxes($previouslyAppliedTaxes); I do see the correct amount. It dumps this twice, the first time I see the correct amount of tax of just my extra fee, the second the correct amount of total tax. But in the frontend it shows the tax without the tax of my extra fee.</p> <p>Any clue on what this could be?</p> <pre><code> class Company_Customer_Model_Quote_Address_Total_PrintPrepCosts extends Mage_Sales_Model_Quote_Address_Total_Abstract { public function __construct() { $this-&gt;setCode('printPrepCosts'); $this-&gt;_store = Mage::app()-&gt;getStore(); return $this; } public function collect(Mage_Sales_Model_Quote_Address $address) { parent::collect($address); $address-&gt;setPrintPrepcosts(0); $address-&gt;setTaxAmount(0); $address-&gt;setBaseTaxAmount(0); if(count($address-&gt;getAllItems()) == 0) { return $this; } $pricePrint = $this-&gt;calcTotalPrintPrepCosts(); $address-&gt;setPrintPrepcosts($pricePrint); $address-&gt;setBasePrintPrepcosts($pricePrint); $address-&gt;setBaseGrandTotal($address-&gt;getBaseGrandTotal() + $address-&gt;getPrintPrepcosts()); $address-&gt;setGrandTotal($address-&gt;getGrandTotal() + $address-&gt;getPrintPrepcosts()); $this-&gt;_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-&gt;_store); $taxRateRequest = $calculator-&gt;getRateRequest( $address, $address-&gt;getQuote()-&gt;getBillingAddress(), $address-&gt;getQuote()-&gt;getCustomerTaxClassId(), $this-&gt;_store ); // TODO undef prop _store $taxRateRequest-&gt;setProductClassId(Mage::getStoreConfig('tax/classes/printing_prep_tax_class', $this-&gt;_store)); $rate = $calculator-&gt;getRate($taxRateRequest); $baseTax = $tax = $calculator-&gt;calcTaxAmount($address-&gt;getPrepPrintcosts(), $rate, $inclTax, true); $address-&gt;addTotalAmount('tax', max(0, $tax)); $address-&gt;addBaseTotalAmount('tax', max(0, $baseTax)); $this-&gt;_saveAppliedTaxes($address, $calculator-&gt;getAppliedRates($taxRateRequest), $tax, $baseTax, $rate ); // later on added - which fixes the total, lose tax amount still off $address-&gt;setTaxAmount($tax); $address-&gt;setBaseTaxAmount($baseTax); if($inclTax) { $address-&gt;setBaseGrandTotal($address-&gt;getBaseGrandTotal() - $baseTax); $address-&gt;setGrandTotal($address-&gt;getGrandTotal() - $tax); } } protected function _saveAppliedTaxes(Mage_Sales_Model_Quote_Address $address, $applied, $amount, $baseAmount, $rate) { $previouslyAppliedTaxes = $address-&gt;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-&gt;setAppliedTaxes($previouslyAppliedTaxes); } public function fetch(Mage_Sales_Model_Quote_Address $address) { $address-&gt;addTotal(array( 'code' =&gt; $this-&gt;getCode(), 'title' =&gt; "Prep Print costs", 'value' =&gt; $address-&gt;getPrintPrepcosts(), )); return $this; } </code></pre> <p>EDIT 1 XML contains this:</p> <pre><code> &lt;sales&gt; &lt;quote&gt; &lt;totals&gt; &lt;printPrepCosts&gt; &lt;class&gt;Company_Customer_Model_Quote_Address_Total_PrintPrepCosts&lt;/class&gt; &lt;after&gt;subtotal&lt;/after&gt; &lt;before&gt;tax&lt;/before&gt; &lt;/printPrepCosts&gt; &lt;/totals&gt; &lt;/quote&gt; &lt;/sales&gt; </code></pre> <p>EDIT 2 I have added the following lines to my calcTax function, this does fix the grand total but the amount of TAX is still off.</p> <pre><code> $address-&gt;setTaxAmount($tax); $address-&gt;setBaseTaxAmount($baseTax); </code></pre> <p>OUTPUT - example</p> <pre><code>Subtotal € 67,50 printPrepCosts € 40,00 Shipping € 50,00 TAX € 22,33 Total € 187,43 </code></pre> <p>EDIT 3 My bad, only the GoMage onepage checkout gives the correct grand total, the cart doesn't. The regular Magento onepage checkout gives the wrong grandtotal as well. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload