Alexis
12/15/2022, 3:31 PMkennyadsl
from_context method, which is responsible to select the currency to use when picking the price of the variants. This is the default implementation: https://github.com/solidusio/solidus/blob/553c26e2a647dc0d8807a4393777670f1db20277/core/app/models/spree/variant/pricing_options.rb#L55-L60.
In your class, you can use whatever logic you want to understand where to user is located and map that location with a specific currency.Alexis
12/15/2022, 3:44 PMEdwin Cruz
12/15/2022, 4:05 PM[5] pry(main)> Spree::Variant.last.price_for(Spree::Variant::PricingOptions.new(currency: 'USD'))
=> #<Spree::Money:0x0000000111cf1018 @money=#<Money fractional:1599 currency:USD>, @options={:sign_before_symbol=>true, :currency=>"USD"}>
[6] pry(main)> Spree::Variant.last.price_for(Spree::Variant::PricingOptions.new(currency: 'MXN'))
=> #<Spree::Money:0x0000000112711278 @money=#<Money fractional:14000 currency:MXN>, @options={:sign_before_symbol=>true, :currency=>"MXN"}>
[7] pry(main)>Edwin Cruz
12/15/2022, 4:06 PMkennyadsl
Edwin Cruz
12/15/2022, 4:09 PMkennyadsl
from_context method, in the context we already have that informationEdwin Cruz
12/15/2022, 4:17 PMAlexis
12/16/2022, 5:04 PMkennyadsl
Alexis
12/16/2022, 5:41 PM