The Klarna module is sending wrong amounts to Klarna when the ordered products belongs to a category discount.
In VirtueMart:
Original product price: 389.00
Category Discount: 60%
Sales Price: 155.60
In Klarna Online:
Price: 156.60
Discount: 120%
Final Amount: -31.12
= The store has to pay the customer for buying! ;)
A quickfix is to edit line 453 in
/plugins/vmpayment/klarna/klarna/helpers/klarnahandler.php
From:
$item_discount_percent = (double)(round (abs (($item->product_subtotal_discount / $item->product_quantity) * 100 / $price), 2));
To:
$item_discount_percent = (double)(round (abs (($item->product_total_discount / $item->product_quantity) * 100 / $price), 2));
Then the amount will be right for the invoice, but it will not show the discount percent. So it needs a different and better fix, as the real issue is wrong product price being sent over, combined with wrong discount percent.
[attachment cleanup by admin]
Hello
We have done some new testing with the Klarna team, and we have not been able to reproduce your problem.
Don't know what testing you did, but here you have the calculation rules used by the store. Plus product and tax setup.
[attachment cleanup by admin]
I have now installed a fresh VirtueMart 2.0.24 with standard demo data, changed country and currencies, added category discount - and bang. Wrong amount at Klarna.
You have me on Skype, let me know if you need access to this setup, or help with this testing...
But according to the code and amounts in this test, the calculation done here is:
Quote790.88 / 1 x 100 / 765.57 = 103.306 (rounded to 103.31)
So I guess the bug is (partly) in line 442:
$price = $basePriceWithTax = !empty($item->basePriceWithTax) ? $item->basePriceWithTax : $item->product_final_price;
Hope it helps. :)
[attachment cleanup by admin]
Hello
QuoteYou have me on Skype, let me know if you need access to this setup, or help with this testing...
I have a lot of people on skype. So better you contact me when you see that i am online.
We have done with the klarna team new tests this week.
I will give you the new version of the klarna plugin, and we can check if this error is still there.
Hello
Ok, we found the problem when the discount is set as DBtax.
We are working on it.
Hello
QuoteOk, we found the problem when the discount is set as DBtax.
In case of klarna payments, it is not possible to set discounts with the DB rules. Only DArules should be used.
Sorry, but that really seams like a lazy "solution".
It's not normal to do the calculation of discount after tax...
Rued, that is not our failure.
You can clearly see that virtuemart provides both solutions. But Klarna means that they must recalculate the results again and they only support the discount AFTER tax, cause it is the normal way to display prices in (at least) germany, sweden in B2C. They do not accept the results calculated by vm.
We also explained them, that recalculation via a percentage leads always to rounding errors.
Hello
QuoteWe also explained them, that recalculation via a percentage leads always to rounding errors.
That is why now you will see the discount like this
[attachment cleanup by admin]
It's possible to do a correct calculation of this in other systems, but not in VirtueMart... but that's not your fault no...
Displaying the discount including tax is fine, no problem. But it's not normal to do the calculation of discount itself after tax.
All amounts needed is in the cart, it's just the think about how to use it that is odd now.
Hello
This is how the DAtax and DBtax is solved with klarna
EXAMPLE 1:
Product with a discount after tax of -2.00 KR
Product price w/o tax= 10.00
Product price with tax 21%=12,10
Discount= - 2.00
Final price: Product price with tax and discount=10.10 KR
what is sent to Klarna:
Line 1:
- Unit price= 12.10
- Tax= 21%
- Price including VAT
then Klarna calculates the price Excluding VAT=10.00
Line 2: for the discount
Unit Price:-2.00
- Tax= 0%
- Price including VAT
then Klarna calculates the price Excluding VAT=-2.00
For this example: everything is OK
12.10 - 2.00= 10.00
EXAMPLE 2:
Product with a discount BEFORE tax of -2.00 KR
Product price w/o tax= 10.00
discount BEFORE Tax=-2.00
Product price w/o tax with discount BEFORE tax=8.00
Final price: Product price with tax and discount=9.68
What is sent to Klarna:
Line 1:
- Unit price= 12.10
- Tax= 21%
then Klarna calculates the price Excluding VAT=10.00
Line 2: for the discount
Unit Price:
- unit price: -2.00
- Tax: 21%
- Price not including VAT
then Klarna calculates the price including VAT=2.42