AltaPay / plugin-magento2

MIT License
0 stars 3 forks source link

Problems in the order lines when there are discounts #12

Closed ghost closed 3 years ago

ghost commented 7 years ago

The problems occur when there is a discount:

  1. The item id is duplicated (it's using the same id for the item and for the discount)
  2. The order lines are not adding up. In the attached example:

5×133.15−68.33+5 = 602.42

But the total amount is 596.77 .

image

ghost commented 7 years ago

Martin's answer:

It actually appears that Magento2 is adding a item row for discount, depending on which type of discount it is.

There are 3 types of discount methods (by default)

1 - Direct discount on the product (added directly on the product) (special price) 2 - Catalog discount, normally used for something like "buy 3 pay for 2" things

3 - Basket discount, normally when the price depends on other items in the basket, the delivery address or the payment method

(All these can ofcourse configures on thousands methods)

1 - This is not creating a new item line

2 and #3 - Is creating a new item line

(Properly because there can be more discounts on a product - while in #1 - there can only be 1 discount)

So should I add all discounts on a product to the same line? (there CAN be some rounding where 1 or 2 pennies are missing)

Or should I add #2 and #3 as individual item lines, and just add the a discount to the item id in your end?

ghost commented 7 years ago

Emerson's answer:

You could add all discounts on a product to the same line, but if there are too many rounding problems I think it's better not to do it.

So I suppose you can add #2 and #3 as individual lines. Just make sure that the item ids are all unique. For the discount lines you can create the ids if it's easier (for example: discount1, discount2, etc).

lb-altapay-com commented 7 years ago

The problem is still present in 2.1.9, but I see, this as a Magento limitation and something, that we should document.

lsv commented 6 years ago

Just for a notice

This is what happens when you have multiple rules cart rules.

First I have a coupon code which I have applied (called Discount 5%)

Then there is a general cart rule, which gives me 20,- when order total is over 200,-

All discount things are added to 1 discount line, and the name for the discount is "random" choosen (properly the description of the first rule ID)

So I would properly give a documentation that only 1 cart price rule should be applied!

The discount amount is NOT added to each product, only 1 general discount line is added

$order->getDiscountDescription(),
$order->getDiscountAmount()

No tax is available for the cart price rules.

selection_079

lsv commented 6 years ago

ping @lb-altapay-com

lb-altapay-com commented 6 years ago

This is as expected. This is something, that AltaPay needs to document.

lsv commented 6 years ago
orderLines[2][description]: | Discount 5% off coupon
orderLines[2][itemId]: | discount
orderLines[2][quantity]: | 1
orderLines[2][unitPrice]: | -44.5
orderLines[2][goodsType]: | handling

And this is how it looks when you get it.

goodType = Handling correct?

lsv commented 6 years ago

and also itemId = discount (just the name I gave it...) description is the same as in the checkout

lsv commented 6 years ago

Just an update - This is a actually order to your

orderLines[0][description]: | Portia Capri
-- | --
orderLines[0][itemId]: | WP13-29-Green
orderLines[0][quantity]: | 1.0000
orderLines[0][unitPrice]: | 49
orderLines[0][taxAmount]: | 9.8
orderLines[0][goodsType]: | item
orderLines[1][description]: | Portia Capri
orderLines[1][itemId]: | 0
orderLines[1][quantity]: | 1
orderLines[1][unitPrice]: | -4.46
orderLines[1][goodsType]: | handling
orderLines[2][description]: | Daria Bikram Pant
orderLines[2][itemId]: | WP10-29-Black
orderLines[2][quantity]: | 2.0000
orderLines[2][unitPrice]: | 102
orderLines[2][taxAmount]: | 20.4
orderLines[2][goodsType]: | item
orderLines[3][description]: | Daria Bikram Pant
orderLines[3][itemId]: | 0
orderLines[3][quantity]: | 1
orderLines[3][unitPrice]: | -9.29
orderLines[3][goodsType]: | handling
orderLines[4][description]: | Sahara Leggings
orderLines[4][itemId]: | WP05-29-Red
orderLines[4][quantity]: | 1.0000
orderLines[4][unitPrice]: | 75
orderLines[4][taxAmount]: | 15
orderLines[4][goodsType]: | item
orderLines[5][description]: | Sahara Leggings
orderLines[5][itemId]: | 0
orderLines[5][quantity]: | 1
orderLines[5][unitPrice]: | -6.83
orderLines[5][goodsType]: | handling
orderLines[6][description]: | Aeon Capri
orderLines[6][itemId]: | WP07-29-Blue
orderLines[6][quantity]: | 2.0000
orderLines[6][unitPrice]: | 96
orderLines[6][taxAmount]: | 19.2
orderLines[6][goodsType]: | item
orderLines[7][description]: | Aeon Capri
orderLines[7][itemId]: | 0
orderLines[7][quantity]: | 1
orderLines[7][unitPrice]: | -8.74
orderLines[7][goodsType]: | handling
orderLines[8][description]: | Cora Parachute Pant
orderLines[8][itemId]: | WP04-29-White
orderLines[8][quantity]: | 1.0000
orderLines[8][unitPrice]: | 75
orderLines[8][taxAmount]: | 15
orderLines[8][goodsType]: | item
orderLines[9][description]: | Cora Parachute Pant
orderLines[9][itemId]: | 0
orderLines[9][quantity]: | 1
orderLines[9][unitPrice]: | -6.83
orderLines[9][goodsType]: | handling
orderLines[10][description]: | Emma Leggings
orderLines[10][itemId]: | WP02-28-Blue
orderLines[10][quantity]: | 1.0000
orderLines[10][unitPrice]: | 42
orderLines[10][taxAmount]: | 8.4
orderLines[10][goodsType]: | item
orderLines[11][description]: | Emma Leggings
orderLines[11][itemId]: | 0
orderLines[11][quantity]: | 1
orderLines[11][unitPrice]: | -3.82
orderLines[11][goodsType]: | handling
orderLines[12][description]: | Ida Workout Parachute Pant
orderLines[12][itemId]: | WP03-29-Purple
orderLines[12][quantity]: | 1.0000
orderLines[12][unitPrice]: | 48
orderLines[12][taxAmount]: | 9.6
orderLines[12][goodsType]: | item
orderLines[13][description]: | Ida Workout Parachute Pant
orderLines[13][itemId]: | 0
orderLines[13][quantity]: | 1
orderLines[13][unitPrice]: | -4.38
orderLines[13][goodsType]: | handling
orderLines[14][description]: | 5% off coupon, 20,- price reduction
orderLines[14][itemId]: | discount
orderLines[14][quantity]: | 1
orderLines[14][unitPrice]: | -44.3500
orderLines[14][goodsType]: | handling
orderLines[15][description]: | flatrate
orderLines[15][itemId]: | flatrate
orderLines[15][quantity]: | 1
orderLines[15][unitPrice]: | 45.0000
orderLines[15][goodsType]: | shipment

All items have a corresponding handling line, which is a mix of the 5% discount pr product and the 20,- fixed amount on the whole order discount, giving each product (5% + (20 / 9)) kr in the handling for each item line - Which WILL give a weird amount of unit conversation (øre afrunding)

So I can either remove the handling on each item, and just keep the whole order handling (14)

Which do you prefer?

In master branch I have removed the item handling, and only keeping the total discount handling If you want to keep for each item then uncomment these lines https://github.com/AltaPay/magento2/blob/master/Model/Generator.php#L185-L194

If you want to remove the total order handling, comment/remove the line

https://github.com/AltaPay/magento2/blob/master/Model/Generator.php#L197-L207

lsv commented 6 years ago

ping @lb-altapay-com

BushraAsif commented 3 years ago

We are now sending unique item ids with each product. Also, we have created a new orderline with the name of Compensation so if there is any amount left it will be sent in compensation orderline. The fix is already available in the latest versions.