VirtoCommerce / vc-storefront

Virto Commerce Storefront - ASP.NET Core 8.0

Home Page:http://virtocommerce.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Percentage discounts are incorrectly rounded

benb1n opened this issue · comments

Version info:

  • Browser version: Chrome 67.0.3396.87
  • Platform version: 2.13.27
  • Storefront version: 3.1.4

Expected behavior

When a discount is applied, the discount amount is rounded first, then applied to the order. Instead, it is not rounded until it's applied, which causes the order total to be incorrect.

Actual behavior

It applies the discount rounding at the end, which causes the order total to be off. The order totals are inconsistent. See screenshot below.

Steps to reproduce

  1. Create a 10% discount coupon code.
  2. Add an item to the cart that will have a rounding issue, like a 49.95 product.
  3. Apply the coupon.

Note that this is a high priority fix.

image

@IgorisB

@benb1n The VC platform and storefront don't use rounded values in the arithmetic operations and don't store rounded values in DB.
In this case, rounded values are used only for display purposes.
image
image
image

@tatarincev I'm not sure if I understand what you mean. Are you saying that it's a display issue only, and therefore a bug in the storefront? What I see when I look at the cart in the database is that the discount amount is not rounded (which should be fine), but the order total is not rounded either. An order total should be a rounded value.

Here's what I expect to see, both in the UI and in the database.
Subtotal : 49.95
Discount : 5.00 (4.995, rounded up for UI display)
Total: 44.95 (not 44.96 as in the screenshot above, which is using the unrounded discount value and then rounding)

The discount amount should be rounded first before it is applied to the order total. Right now it's not, and an order total should be a rounded amount that uses the rounded amount of total discounts subtracted. Again, reference the screenshot I originally gave and you'll see the inconsistency.

image

I'm pretty sure I tested this exact scenario a couple weeks ago and it behaved as expected, but now it's not. I've updated modules and storefront since then, so something likely broke it recently.

We might be talking about the same thing, but I couldn't tell from your response if you agreed that this was not working as intended. Either way, this is high priority for us this week. Let me know if there's anything more I can do to help. We can hope on a Skype call if needed in case I'm not understanding something still. Thanks!

@IgorisB

@benb1n All ok, I got your issue, tomorrow will try to prepare some solution for this.

@tatarincev Great - thanks! Here's a screenshot of the order totals in case that's helpful.

image

We're migrating data from Woo Commerce, and it calculates it as rounding towards zero for discounts. Here's the same scenario but with Woo values from the database:

49.95

  • 4.99

44.96

@benb1n I'm still in progress of this issue, it took little bit more time what I expected :)

@tatarincev Looks like there's still a rounding issue with discounts on order line item. But things at the order level look good.

image

image

@tatarincev - We are still experiencing rounding issues with the discounts. The attached checkout screenshot shows the error from your demo site. This was using the discount code disc102 which takes 10% from the cart. The correct rounded discount should be $5.00. The total in this case comes out correct, but you can see above the discounted amount in the line item is off.

I’ve also attached screenshots of the completed order page and the order detail in the platform. As you can see the the line item amount is off when the discount is cart level. This is not the expected behavior.

screen shot 2018-06-26 at 4 22 47 pm

screen shot 2018-06-26 at 4 30 41 pm

screen shot 2018-06-26 at 4 33 58 pm

@asvishnyakov @tatarincev Just to be clear, the discount total for a cart-level discount should be managed at the order level. Our customers should not have to split the difference of the discount at the line item level if they need to change it in the admin for a subscription prototype order. That would lead to further rounding issues. They should be able to change the discount amount on the order. What they really want is the ability to do it through a coupon code like how it was originally entered in the shopping cart. Their main use case for editing an order is for a subscription prototype. Be sure to review any fixes against our 10% off cart total for various quantities of products that have a price ending in .95 (39.95, 49.95, etc). Thanks for your help on this.

@asvishnyakov @tatarincev Any update on this?

@benb1n We had discussion today at the evening, I think tomorrow @tatarincev will write you resolution.

@benb1n Yes, in VC, the discount Get []% off Cart subtotal has always been applied at the level of the cart items, and this has led to this rounding issue. In the next module releases and commits, we have changed this behavior,
vc-module-core 2.25.4
vc-module-dynamic-expressions 2.12.7
7d88fe9

and now all the promition rewards with type Get []% off Cart subtotal will be applied to the cart subtotal instead the distribution between the cart items.
image
image
image

Thanks @tatarincev @asvishnyakov @IgorisB - this worked great!