Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix: prices saved wrongly in stores whose language uses a decimal comma

Damian Legawiec2d1f3a33bd99
diff --git a/docs/changelog.mdx b/docs/changelog.mdx
index 540752b33e..6ff68bc93d 100644
--- a/docs/changelog.mdx
+++ b/docs/changelog.mdx
@@ -15,6 +15,16 @@ Keep up with the latest features and improvements in Spree Commerce!
</div>
+<Update label="Prices save correctly in every language" description="October 9, 2026" tags={["Pricing", "Dashboard"]}>
+ Stores whose language writes a comma as the decimal separator, such as Dutch, German or French, could save the wrong price. A price entered as €49,50 was stored as €4950,00, and saving an unchanged €99 again turned it into €990 and then €9900. Prices, costs, weights and dimensions are now saved exactly as entered, whatever the store's language.
+
+ Taxes and discounts in yen are now rounded to whole yen, and partial captures in yen are recorded at their real amount.
+
+ If you edited prices in such a store before this update, check them.
+
+ **Learn more:** [Upgrade guide](/developer/upgrades/5.6-to-6.0#money)
+</Update>
+
<Update label="Email template editor" description="October 6, 2026" tags={["Emails", "Dashboard"]}>
Merchants can now change what their customer emails say and how they look, right in the dashboard, without asking a developer. Order confirmations, shipping notifications, refunds, password resets, the layout around every email and the shared blocks such as item rows are all editable under **Settings → Emails → Templates**.
diff --git a/packages/dashboard/e2e/global-setup.ts b/packages/dashboard/e2e/global-setup.ts
index 371e8eb5f4..6d8ffa712f 100644
--- a/packages/dashboard/e2e/global-setup.ts
+++ b/packages/dashboard/e2e/global-setup.ts
@@ -164,8 +164,15 @@ const BOOTSTRAP_RUBY = [
'transfer_source.stock_levels.where(variant: inventory_product.default_variant).first_or_create!.update!(count_on_hand: 500)',
'inventory_level = transfer_destination.stock_levels.where(variant: inventory_product.default_variant).first_or_create!',
`unless inventory_level.stock_reservations.exists?; inventory_cart = Spree::Cart.create!(store: s, currency: s.default_currency, email: '[email protected]'); inventory_line = inventory_cart.line_items.create!(variant: inventory_product.default_variant, quantity: ${FIXTURE_INVENTORY_RESERVED}); inventory_level.stock_reservations.create!(cart: inventory_cart, line_item: inventory_line, quantity: ${FIXTURE_INVENTORY_RESERVED}, expires_at: 10.years.from_now); end`,
+ // A store whose language writes a comma decimal (Dutch) and prices in EUR:
+ // the server reads every request in the store's language, so this is where
+ // a price is misread if anything parses money by locale. Its name sorts after
+ // the default store's, so signing in still opens the default store first.
+ `comma_store = Spree::Store.find_by(code: 'e2e-nl') || Spree::Store.create!(code: 'e2e-nl', name: 'Winkel', url: 'nl.example.com', mail_from_address: '[email protected]', default_currency: 'EUR', default_locale: 'nl')`,
+ 'Spree::Seeds::StoreResources.call(store: comma_store); Spree::Stores::ProvisionDefaults.call(store: comma_store, country: Spree::Country.find_by_iso!("NL"), locale: "nl", currency: "EUR") unless comma_store.stock_locations.exists?',
+ 'comma_store.add_user(admin, Spree::Role.default_admin_role(comma_store)) unless comma_store.role_users.exists?(user: admin)',
'port = ENV.fetch("PORT", 3010)',
- 'puts JSON.generate(api_url: "http://localhost:#{port}", admin_email: admin.email, admin_password: "spree123", store_id: s.prefixed_id, store_name: s.name)',
+ 'puts JSON.generate(api_url: "http://localhost:#{port}", admin_email: admin.email, admin_password: "spree123", store_id: s.prefixed_id, store_name: s.name, comma_store_id: comma_store.prefixed_id)',
].join('; ')
export default async function globalSetup() {
diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.ts
index 67473bf05c..ae074ed896 100644
--- a/packages/dashboard/e2e/helpers.ts
+++ b/packages/dashboard/e2e/helpers.ts
@@ -205,6 +205,8 @@ export interface E2ECredentials {
admin_password: string
store_id: string
store_name: string
+ /** A store whose language writes a comma decimal (nl) and prices in EUR. */
+ comma_store_id: string
}
/** Credentials plus the JWT from the login response (Admin API Bearer auth). */
diff --git a/packages/dashboard/e2e/products-prices-inventory.spec.ts b/packages/dashboard/e2e/products-prices-inventory.spec.ts
index cb72809527..e9544140b9 100644
--- a/packages/dashboard/e2e/products-prices-inventory.spec.ts
+++ b/packages/dashboard/e2e/products-prices-inventory.spec.ts
@@ -236,6 +236,117 @@ test.describe('product prices — single variant', () => {
})
})
+// ---------------------------------------------------------------------------
+// Money entry — separators, currencies and the store's language
+// ---------------------------------------------------------------------------
+
+// Prices typed with either separator must persist exactly, in every currency,
+// and saving the product again must leave them as they are. The API returns
+// "49.5" for 49.50 until amounts are written to the currency's decimals, so the
+// expectations allow the trailing zero to be missing; what they rule out is a
+// separator read the wrong way (4950, 990).
+test.describe('product prices — separators and currencies', () => {
+ function priceCell(card: Locator): Locator {
+ return card.getByRole('textbox', { name: /^price for default$/i })
+ }
+
+ async function showCurrency(page: Page, card: Locator, currency: string): Promise<void> {
+ await card.getByRole('combobox').first().click()
+ await page.getByRole('option', { name: currency }).click()
+ }
+
+ async function saveProduct(page: Page): Promise<void> {
+ await page.getByRole('button', { name: /save product/i }).click()
+ await expect(page.getByRole('button', { name: /save product/i })).toBeDisabled({
+ timeout: 30_000,
+ })
+ }
+
+ // Saves the product with only its name changed, the way a merchant saves it
+ // again without opening the prices.
+ async function saveAgainUntouched(page: Page, name: string): Promise<void> {
+ await page.reload()
+ await page.getByLabel(/^name$/i).fill(name)
+ await saveProduct(page)
+ }
+
+ test('USD and EUR prices typed with either separator persist exactly and survive repeated saves', async ({
+ page,
+ }) => {
+ const creds = await login(page)
+ const productName = `E2E Separators ${Date.now()}`
+ await createProduct(page, creds.store_id, productName)
+
+ const card = pricesCard(page)
+ // USD is shown in English: a comma groups thousands.
+ await fillGridCell(priceCell(card), '1,234.56')
+ // EUR is shown in German: a period groups thousands, a comma is the decimal.
+ await showCurrency(page, card, 'EUR')
+ await fillGridCell(priceCell(card), '1.234,56')
+ await saveProduct(page)
+
+ await saveAgainUntouched(page, `${productName} (2)`)
+ await saveAgainUntouched(page, `${productName} (3)`)
+
+ await page.reload()
+ const reloaded = pricesCard(page)
+ await expect(priceCell(reloaded)).toHaveValue('1234.56')
+ await showCurrency(page, reloaded, 'EUR')
+ await expect(priceCell(reloaded)).toHaveValue('1234,56')
+ })
+
+ test('a EUR price typed with a comma, a period or no decimals persists exactly', async ({
+ page,
+ }) => {
+ const creds = await login(page)
+
+ for (const [typed, shown] of [
+ ['49,50', /^49,50?$/],
+ // A period before two digits cannot be grouping: it is the decimal.
+ ['19.50', /^19,50?$/],
+ ['99', /^99(,0+)?$/],
+ ] as const) {
+ const productName = `E2E EUR ${typed} ${Date.now()}`
+ await createProduct(page, creds.store_id, productName)
+ const card = pricesCard(page)
+ await showCurrency(page, card, 'EUR')
+ await fillGridCell(priceCell(card), typed)
+ await saveProduct(page)
+ await saveAgainUntouched(page, `${productName} (2)`)
+
+ await page.reload()
+ const reloaded = pricesCard(page)
+ await showCurrency(page, reloaded, 'EUR')
+ await expect(priceCell(reloaded)).toHaveValue(shown)
+ }
+ })
+
+ // The reported bug: in a store whose language writes a comma decimal, the
+ // server read "49.50" as 4950, and every save of an unchanged 99 added a zero.
+ test('a store whose language writes a comma decimal saves its prices exactly', async ({
+ page,
+ }) => {
+ const creds = await login(page)
+
+ for (const [typed, shown] of [
+ ['49,50', /^49,50?$/],
+ ['99', /^99(,0+)?$/],
+ ['1.234,56', /^1234,56$/],
+ ] as const) {
+ const productName = `E2E Dutch ${typed} ${Date.now()}`
+ await createProduct(page, creds.comma_store_id, productName)
+ await fillGridCell(priceCell(pricesCard(page)), typed)
+ await saveProduct(page)
+
+ await saveAgainUntouched(page, `${productName} (2)`)
+ await saveAgainUntouched(page, `${productName} (3)`)
+
+ await page.reload()
+ await expect(priceCell(pricesCard(page))).toHaveValue(shown)
+ }
+ })
+})
+
// ---------------------------------------------------------------------------
// Inventory grid — multi-variant: every (variant × location) editable
// ---------------------------------------------------------------------------
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
index 6eb3362594..565714e5aa 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
@@ -730,10 +730,7 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
# The Admin API contract is canonical decimal strings (`"29.99"`, period
# decimal). Clients (the dashboard) normalize localized input
# client-side before sending — the API is not asked to parse comma-vs-
- # period. See docs/plans/5.5-client-side-money-normalization.md. (The
- # models still tolerate localized input for the legacy Rails admin, but
- # that is not part of the Admin API contract and is covered by the
- # `Spree::LocalizedNumber` unit specs.)
+ # period. See docs/plans/5.5-client-side-money-normalization.md.
it 'accepts amounts as canonical decimal strings (symmetric with reads)' do
post :create, params: {
name: 'String Price Product',
@@ -830,6 +827,37 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
expect(product.reload.name).to eq('Updated Name')
end
+ # A store whose language writes a comma decimal (nl, de, fr) must still
+ # read the dashboard's canonical "49.50" as forty-nine fifty, and saving an
+ # untouched price must not grow it by a power of ten.
+ context 'when the request resolves a comma-decimal locale' do
+ let(:variant) { product.default_variant }
+
+ before { allow(controller).to receive(:current_locale).and_return('nl') }
+
+ def save_price(amount)
+ patch :update, params: {
+ id: product.prefixed_id,
+ variants: [{ id: variant.prefixed_id, prices: [{ currency: 'USD', amount: amount }] }]
+ }, as: :json
+ expect(response).to have_http_status(:ok), response.body
+ variant.prices.base_prices.find_by(currency: 'USD').amount
+ end
+
+ it 'stores a canonical amount as written' do
+ expect(save_price('49.50')).to eq(BigDecimal('49.50'))
+ end
+
+ it 'keeps a price stable across repeated saves of what the API returned' do
+ save_price('99')
+ returned = json_response['variants']&.first&.dig('prices')&.first&.dig('amount') ||
+ variant.prices.base_prices.find_by(currency: 'USD').amount.to_s
+
+ expect(save_price(returned)).to eq(BigDecimal('99'))
+ expect(save_price(variant.prices.base_prices.find_by(currency: 'USD').amount.to_s)).to eq(BigDecimal('99'))
+ end
+ end
+
it 'assigns a product type by prefixed id and returns it' do
product_type = create(:product_type, store: store)
diff --git a/spree/core/app/models/concerns/spree/typed_adjustment_line.rb b/spree/core/app/models/concerns/spree/typed_adjustment_line.rb
index 299f9d82c8..3710bcd20b 100644
--- a/spree/core/app/models/concerns/spree/typed_adjustment_line.rb
+++ b/spree/core/app/models/concerns/spree/typed_adjustment_line.rb
@@ -38,10 +38,6 @@ module Spree
end
end
- def amount=(amount)
- self[:amount] = Spree::LocalizedNumber.parse(amount)
- end
-
def currency
owner&.currency
end
diff --git a/spree/core/app/models/spree/gift_card.rb b/spree/core/app/models/spree/gift_card.rb
index 1f8ce05e86..7a65770360 100644
--- a/spree/core/app/models/spree/gift_card.rb
+++ b/spree/core/app/models/spree/gift_card.rb
@@ -82,12 +82,6 @@ module Spree
#
money_methods :amount, :amount_used, :amount_authorized, :amount_remaining
- # Sets the amount
- # @param amount [String]
- def amount=(amount)
- self[:amount] = Spree::LocalizedNumber.parse(amount)
- end
-
# Calculates the remaining amount
# @return [Decimal]
def amount_remaining
diff --git a/spree/core/app/models/spree/gift_card_batch.rb b/spree/core/app/models/spree/gift_card_batch.rb
index c98f929ec2..e87339a690 100644
--- a/spree/core/app/models/spree/gift_card_batch.rb
+++ b/spree/core/app/models/spree/gift_card_batch.rb
@@ -34,10 +34,6 @@ module Spree
money_methods :amount
- def amount=(amount)
- self[:amount] = Spree::LocalizedNumber.parse(amount)
- end
-
self.whitelisted_ransackable_attributes = %w[prefix]
def generate_gift_cards
diff --git a/spree/core/app/models/spree/payment.rb b/spree/core/app/models/spree/payment.rb
index ac0383a475..dd393e7098 100644
--- a/spree/core/app/models/spree/payment.rb
+++ b/spree/core/app/models/spree/payment.rb
@@ -255,16 +255,6 @@ module Spree
end
end
- def amount=(amount)
- self[:amount] =
- case amount
- when String
- separator = I18n.t('number.currency.format.separator')
- number = amount.delete("^0-9-#{separator}\.").tr(separator, '.')
- number.to_d if number.present?
- end || amount
- end
-
# Resizes a store credit payment that has not been taken yet. Completion
# takes it against the eligibility event recorded for its amount, so the
# new amount needs one of its own.
diff --git a/spree/core/app/models/spree/price.rb b/spree/core/app/models/spree/price.rb
index 82018c5438..e39567213a 100644
--- a/spree/core/app/models/spree/price.rb
+++ b/spree/core/app/models/spree/price.rb
@@ -102,10 +102,6 @@ module Spree
Spree::Money.new(amount || 0, currency: currency.upcase)
end
- def amount=(amount)
- self[:amount] = amount.blank? ? nil : Spree::LocalizedNumber.parse(amount)
- end
-
# Returns the amount in cents
# @return [Integer]
def amount_in_cents
@@ -116,12 +112,6 @@ module Spree
Spree::Money.new(compare_at_amount || 0, currency: currency)
end
- def compare_at_amount=(value)
- calculated_value = Spree::LocalizedNumber.parse(value) if value.present?
-
- self[:compare_at_amount] = calculated_value
- end
-
# Returns the compare at amount for display
# @return [Spree::Money, nil]
def display_compare_at_amount
@@ -139,9 +129,7 @@ module Spree
end
alias_attribute :price, :amount
- alias_method :price=, :amount=
alias_attribute :compare_at_price, :compare_at_amount
- alias_method :compare_at_price=, :compare_at_amount=
# Whether this figure is the merchant's answer for the buyer's geography
# already. A price list narrowed by market or country states its prices for
diff --git a/spree/core/app/models/spree/price_list.rb b/spree/core/app/models/spree/price_list.rb
index 645e2a9ddc..fadf0c310c 100644
--- a/spree/core/app/models/spree/price_list.rb
+++ b/spree/core/app/models/spree/price_list.rb
@@ -389,9 +389,8 @@ module Spree
current = current_values[price_id]
- # Parse amounts using LocalizedNumber for proper decimal handling
- amount = attrs[:amount].present? ? Spree::LocalizedNumber.parse(attrs[:amount]) : nil
- compare_at_amount = attrs[:compare_at_amount].present? ? Spree::LocalizedNumber.parse(attrs[:compare_at_amount]) : nil
+ amount = attrs[:amount].presence&.to_d
+ compare_at_amount = attrs[:compare_at_amount].presence&.to_d
# Clear compare_at_amount if it equals amount
compare_at_amount = nil if compare_at_amount == amount
diff --git a/spree/core/app/models/spree/store_credit.rb b/spree/core/app/models/spree/store_credit.rb
index 8d2f0513da..907939a95f 100644
--- a/spree/core/app/models/spree/store_credit.rb
+++ b/spree/core/app/models/spree/store_credit.rb
@@ -105,10 +105,6 @@ module Spree
extend Spree::DisplayMoney
money_methods :amount, :amount_used, :amount_remaining, :amount_authorized
- def amount=(amount)
- self[:amount] = Spree::LocalizedNumber.parse(amount)
- end
-
self.whitelisted_ransackable_attributes = %w[customer_id created_by_id amount currency memo]
self.whitelisted_ransackable_associations = %w[customer created_by]
self.whitelisted_ransackable_scopes = %w[outstanding from_gift_card]
diff --git a/spree/core/app/models/spree/variant.rb b/spree/core/app/models/spree/variant.rb
index bb127f7d47..3b83321ea2 100644
--- a/spree/core/app/models/spree/variant.rb
+++ b/spree/core/app/models/spree/variant.rb
@@ -289,12 +289,12 @@ module Spree
relation.where(conditions.reduce(:or)).distinct
end
- # FIXME: cost price should be represented with DisplayMoney class
- LOCALIZED_NUMBERS = %w(cost_price weight depth width height)
+ # A blank value leaves these as they were rather than clearing them.
+ KEPT_WHEN_BLANK = %w(cost_price weight depth width height)
- LOCALIZED_NUMBERS.each do |m|
+ KEPT_WHEN_BLANK.each do |m|
define_method("#{m}=") do |argument|
- self[m] = Spree::LocalizedNumber.parse(argument) if argument.present?
+ super(argument) if argument.present?
end
end
diff --git a/spree/core/app/services/spree/prices/bulk_upsert.rb b/spree/core/app/services/spree/prices/bulk_upsert.rb
index 31ed309458..a40b84d416 100644
--- a/spree/core/app/services/spree/prices/bulk_upsert.rb
+++ b/spree/core/app/services/spree/prices/bulk_upsert.rb
@@ -371,13 +371,9 @@ module Spree
[row[:variant_id].to_s, row[:currency], row[:price_list_id].to_s]
end
- # Parses locale-aware decimal input ("1.234,56" in DE, "1,234.56"
- # in en-US). Numeric values pass through; blank values become nil.
+ # Blank values become nil.
def parse_amount(value)
- return nil if value.blank?
- return value if value.is_a?(Numeric)
-
- Spree::LocalizedNumber.parse(value)
+ value.presence&.to_d
end
def sweep(affected_keys, clear_rows)
diff --git a/spree/core/app/workflows/spree/fulfillments/create.rb b/spree/core/app/workflows/spree/fulfillments/create.rb
index c5be208569..c233a60157 100644
--- a/spree/core/app/workflows/spree/fulfillments/create.rb
+++ b/spree/core/app/workflows/spree/fulfillments/create.rb
@@ -320,8 +320,8 @@ module Spree
end
# Strict decimal parsing (same semantics as Shipment#cost=, which the
- # update_columns freeze path bypasses) — the lenient LocalizedNumber
- # would turn garbage into 0, and 0 is a legal cost here.
+ # update_columns freeze path bypasses) — a lenient parse would turn
+ # garbage into 0, and 0 is a legal cost here.
#
# @return [BigDecimal, Numeric, nil] nil when no cost was given (blank
# counts as omitted); a failure Result for malformed or negative input
diff --git a/spree/core/lib/spree/localized_number.rb b/spree/core/lib/spree/localized_number.rb
index 73348703b9..00c1febb2b 100644
--- a/spree/core/lib/spree/localized_number.rb
+++ b/spree/core/lib/spree/localized_number.rb
@@ -1,7 +1,13 @@
module Spree
+ # Deprecated: Spree no longer parses numbers by locale. Its APIs take
+ # canonical decimal strings ("1234.56"); localizing input is the client's job.
class LocalizedNumber
# Strips all non-price-like characters from the number, taking into account locale settings.
def self.parse(number)
+ Spree::Deprecation.warn(
+ 'Spree::LocalizedNumber is deprecated and will be removed in Spree 6.1. ' \
+ 'Parse a canonical decimal string with BigDecimal, or Spree::Money::Rounding.parse_canonical for API input.'
+ )
return number unless number.is_a?(String)
separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
diff --git a/spree/core/spec/lib/spree/localized_number_spec.rb b/spree/core/spec/lib/spree/localized_number_spec.rb
index ed2b1706f6..4942e7628b 100644
--- a/spree/core/spec/lib/spree/localized_number_spec.rb
+++ b/spree/core/spec/lib/spree/localized_number_spec.rb
@@ -1,8 +1,14 @@
require 'spec_helper'
describe Spree::LocalizedNumber do
+ it 'warns that it is deprecated' do
+ expect(Spree::Deprecation).to receive(:warn).with(/LocalizedNumber is deprecated/)
+ described_class.parse('1.5')
+ end
+
context '.parse' do
before do
+ allow(Spree::Deprecation).to receive(:warn)
I18n.enforce_available_locales = false
allow(I18n).to receive(:locale).and_return(I18n.default_locale)
I18n.backend.store_translations(:de, number: { currency: { format: { delimiter: '.', separator: ',' } } })
diff --git a/spree/core/spec/models/spree/gift_card_batch_spec.rb b/spree/core/spec/models/spree/gift_card_batch_spec.rb
index e2f918a4a9..3bb1940776 100644
--- a/spree/core/spec/models/spree/gift_card_batch_spec.rb
+++ b/spree/core/spec/models/spree/gift_card_batch_spec.rb
@@ -38,12 +38,10 @@ RSpec.describe Spree::GiftCardBatch, type: :model do
end
describe '#amount=' do
- let(:amount) { '1,599,99' }
-
- it 'is expected to equal to localized number' do
+ it 'stores a canonical decimal exactly under a comma-decimal locale' do
gift_card_batch = build(:gift_card_batch, codes_count: 2, prefix: 'batch_')
- gift_card_batch.amount = amount
- expect(gift_card_batch.amount).to eq(Spree::LocalizedNumber.parse(amount))
+ I18n.with_locale(:nl) { gift_card_batch.amount = '49.50' }
+ expect(gift_card_batch.amount).to eq(BigDecimal('49.50'))
end
end
diff --git a/spree/core/spec/models/spree/payment_spec.rb b/spree/core/spec/models/spree/payment_spec.rb
index 1c4f72b7b6..5e8473d626 100644
--- a/spree/core/spec/models/spree/payment_spec.rb
+++ b/spree/core/spec/models/spree/payment_spec.rb
@@ -1079,22 +1079,6 @@ describe Spree::Payment, type: :model do
end
end
- context 'amount contains a dollar sign' do
- let(:amount) { '$2.99' }
-
- it '#amount' do
- expect(subject.amount).to eql(BigDecimal('2.99'))
- end
- end
-
- context 'amount contains a comma' do
- let(:amount) { '$2,999.99' }
-
- it '#amount' do
- expect(subject.amount).to eql(BigDecimal('2999.99'))
- end
- end
-
context 'amount contains a negative sign' do
let(:amount) { '-2.99' }
@@ -1130,53 +1114,12 @@ describe Spree::Payment, type: :model do
end
end
- context 'when the locale uses a coma as a decimal separator' do
- before do
- I18n.backend.store_translations(:fr, number: { currency: { format: { delimiter: ' ', separator: ',' } } })
- allow(I18n).to receive(:locale).and_return(:fr)
- allow(I18n.config).to receive(:locale).and_return(:fr)
+ context 'when the locale writes a comma decimal' do
+ let(:amount) { '49.50' }
- subject.amount = amount
- end
-
- context 'amount is a decimal' do
- let(:amount) { '2,99' }
-
- it '#amount' do
- expect(subject.amount).to eql(BigDecimal('2.99'))
- end
- end
-
- context 'amount contains a $ sign' do
- let(:amount) { '2,99 $' }
-
- it '#amount' do
- expect(subject.amount).to eql(BigDecimal('2.99'))
- end
- end
-
- context 'amount is a number' do
- let(:amount) { 2.99 }
-
- it '#amount' do
- expect(subject.amount).to eql(BigDecimal('2.99'))
- end
- end
-
- context 'amount contains a negative sign' do
- let(:amount) { '-2,99 $' }
-
- it '#amount' do
- expect(subject.amount).to eql(BigDecimal('-2.99'))
- end
- end
-
- context 'amount uses a dot as a decimal separator' do
- let(:amount) { '2.99' }
-
- it '#amount' do
- expect(subject.amount).to eql(BigDecimal('2.99'))
- end
+ it 'stores a canonical decimal exactly' do
+ I18n.with_locale(:nl) { subject.amount = amount }
+ expect(subject.amount).to eql(BigDecimal('49.50'))
end
end
end
diff --git a/spree/core/spec/models/spree/price_spec.rb b/spree/core/spec/models/spree/price_spec.rb
index d2907158a6..c476d89bad 100644
--- a/spree/core/spec/models/spree/price_spec.rb
+++ b/spree/core/spec/models/spree/price_spec.rb
@@ -113,14 +113,15 @@ describe Spree::Price, type: :model do
describe '#amount=' do
let(:price) { build :price }
- let(:amount) { '3,0A0' }
- before do
- price.amount = amount
+ it 'stores a canonical decimal exactly under a comma-decimal locale' do
+ I18n.with_locale(:nl) { price.amount = '49.50' }
+ expect(price.amount).to eq(BigDecimal('49.50'))
end
- it 'is expected to equal to localized number' do
- expect(price.amount).to eq(Spree::LocalizedNumber.parse(amount))
+ it 'does not grow when what it read back is saved again' do
+ I18n.with_locale(:nl) { price.amount = '99.0' }
+ expect(price.amount).to eq(BigDecimal('99'))
end
end
@@ -132,8 +133,8 @@ describe Spree::Price, type: :model do
price.compare_at_amount = compare_at_amount
end
- it 'is expected to equal to localized number' do
- expect(price.compare_at_amount).to eq(Spree::LocalizedNumber.parse(compare_at_amount))
+ it 'stores a canonical decimal exactly' do
+ expect(price.compare_at_amount).to eq(BigDecimal('169.99'))
end
context 'with empty string being passed as value' do
diff --git a/spree/core/spec/models/spree/store_credit_spec.rb b/spree/core/spec/models/spree/store_credit_spec.rb
index b9fb9cfb31..48a3a2f566 100644
--- a/spree/core/spec/models/spree/store_credit_spec.rb
+++ b/spree/core/spec/models/spree/store_credit_spec.rb
@@ -280,12 +280,9 @@ describe Spree::StoreCredit, type: :model do
end
describe '#amount=' do
- let(:amount) { '1,599,99' }
-
- before { store_credit.amount = amount }
-
- it 'is expected to equal to localized number' do
- expect(store_credit.amount).to eq(Spree::LocalizedNumber.parse(amount))
+ it 'stores a canonical decimal exactly under a comma-decimal locale' do
+ I18n.with_locale(:nl) { store_credit.amount = '49.50' }
+ expect(store_credit.amount).to eq(BigDecimal('49.50'))
end
end
diff --git a/spree/core/spec/models/spree/variant_spec.rb b/spree/core/spec/models/spree/variant_spec.rb
index c99c40a279..8a7373a259 100644
--- a/spree/core/spec/models/spree/variant_spec.rb
+++ b/spree/core/spec/models/spree/variant_spec.rb
@@ -576,9 +576,16 @@ describe Spree::Variant, type: :model do
end
describe '#cost_price=' do
- it 'uses LocalizedNumber.parse' do
- expect(Spree::LocalizedNumber).to receive(:parse).with('1,599.99')
- subject.cost_price = '1,599.99'
+ it 'stores a canonical decimal exactly under a comma-decimal locale' do
+ record = variant
+ I18n.with_locale(:nl) { record.cost_price = '8.50' }
+ expect(variant.cost_price).to eq(BigDecimal('8.50'))
+ end
+
+ it 'keeps the value when given a blank' do
+ variant.cost_price = '8.50'
+ variant.cost_price = ''
+ expect(variant.cost_price).to eq(BigDecimal('8.50'))
end
end
@@ -629,16 +636,17 @@ describe Spree::Variant, type: :model do
end
describe '#set_price' do
- it 'parses a localized amount' do
- variant.set_price('USD', '1,599.99')
- expect(variant.price_in('USD').amount).to eq(1599.99)
+ it 'stores a canonical amount exactly' do
+ variant.set_price('USD', '1599.99')
+ expect(variant.price_in('USD').amount).to eq(BigDecimal('1599.99'))
end
end
describe '#weight=' do
- it 'uses LocalizedNumber.parse' do
- expect(Spree::LocalizedNumber).to receive(:parse).with('1,599.99')
- subject.weight = '1,599.99'
+ it 'stores a canonical decimal exactly under a comma-decimal locale' do
+ record = variant
+ I18n.with_locale(:nl) { record.weight = '0.2' }
+ expect(variant.weight).to eq(BigDecimal('0.2'))
end
end