Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from price to price_cents using :with_currency is inaccurate for currencies without subunits #696

Open
basabin54 opened this issue Apr 16, 2024 · 0 comments

Comments

@basabin54
Copy link

basabin54 commented Apr 16, 2024

This is fairly niche and I have work arounds, but I figured I'd bring this up just in case there is an easy fix

Assuming the following models:

Class Product < ApplicationRecord
  # has attribute currency

  has_many :variants
end
Class Variant < ApplicationRecord
  belongs_to :product

  monetize :price_cents, with_currency: ->(variant) { variant.product.currency }
end

then when creating a variant through the relationship like this assuming a product with currency = "KRW" (South Korean Won - a currency without subunits):

@product.variants.new(price: 20)

I get back a variant with price_cents set to 2000 when it should only be 20 since KRW units and subunits should be equal.

Seems like :price_cents is being converted from :price with the default system currency when the currency through the relationship to product should be used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant