Shopify/function-examples

Product Discount Functions - Discount Percentage rounding bug

meandillar opened this issue · 11 comments

I have a product discount function that outputs a discount percentage based on a mixture of a preconfigured value and the cart item pricing. Sometimes the percentage needs to be a decimal like 2.1739130434782608 but it seems that Shopify is rounding this number somehow when making the calculation.

For example:

Line item price is $23
Percentage discount is 2.1739130434782608
Expected price after discount is $22.50
Actual output in the cart shows $22.51

With quantity of 2 the total price shows $45.01 which leads me to think that the percentage discount is being rounded to 2 decimal places.

Screenshots of function output and cart:
Screenshot 2023-10-13 at 4 45 15 PM
Screenshot 2023-10-13 at 4 46 20 PM

Please direct API questions and issues to Partner Support or Community Forums.

jjdave commented

This may be expected behaviour due to the rounding rules applied. When working in discounts, I recall rounding occurring based on the currency used. See https://shopify.workplace.com/groups/720774362667566/permalink/736690961075906/

#TIL Currency Codes and their designated decimal places having an impact on discounts. Shahriar Rahman and I found some interesting results in fixing some tests.

Example

shop_currency_rate = 0.01
JPY currency is 0 d.p.
Discount applied as 10% of 1200 JPY which is 120 JPY.
Money.new(120,"JPY") * shop_currency_rate returns a 1 USD discount

In contrast, OMR has 3 d.p. so we get:
Money.new(120,"OMR") * shop_currency_rate returns a 1.200 USD discount

@jjdave I can't view the above workplace link, it seems to be an internal shopify link.

Rounding of the actual monetry amount is not the issue though. It seems that the discount percentage output by the function is being rounded, so I don't think the above example is relevant

jjdave commented

@jjdave I can't view the above workplace link, it seems to be an internal shopify link.

Rounding of the actual monetry amount is not the issue though. It seems that the discount percentage output by the function is being rounded, so I don't think the above example is relevant

Ah, I thought this was an internal raised issue. Yeah, the link won't work. I added the text of the link as the example just in case.

As for the discount rate rounding, we can ask the discount team.

jjdave commented

Hey @meandillar Our discounts team will review this use case in due course.

@jjdave thanks, I have raised this with Partner Support as suggested by nickwesselman so they are hopefully already looking at it.

@nova-srahman Great to see that someone is investigating this. Would it be possible to re-open this issue or link to an open issue? I'd love to be kept in the loop about any progress with this because my support ticket with Partner Support was closed as it was added to their list with no timeframe of completion.

We will very shortly be switching over to discount functions from Shopify Scripts, but because of this bug our pricing isn't always accurate.

@jjdave @nova-srahman hey folks any word on progress for this? We're still seeing the same problem and hit a dead end with Shopify Discussions and Partner Support

Edit: In the screenshot below these products have the exact same discount applied to them but the pricing is different on each product.

Screenshot 2024-01-15 at 10 14 57 AM

@jjdave @nova-srahman Are there any updates for this topic? We still have the problem and get a lot of complaints about this.

From @meandillar 's example: If you would up the quantity of the 'Chocolate' variant in that cart, the price per item now shows correctly (35.11) because the rounding is applied differently for some reason.

Please direct API questions and issues to Partner Support or Community Forums.

@samihibrahim as mentioned previously in this thread the issue has already been raised with Partner Support and on the Community Forums but both have resulted in no action.

Do you have any other suggestions on how this issue can be addressed if not in github, Partner Support or community forums?