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.

Aligned typed preferences with the money changes on main

Damian Legawiecebd4e2c44b10
diff --git a/CLAUDE.md b/CLAUDE.md
index 376e2892d0..9ff7954b82 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -336,7 +336,7 @@ attribute :variant_id
- Serialize with `Model.api_type_for(record.type)` (or `record.class.api_type`); resolve writes with `subclassed_via` / `find_by_api_type` / `Model.class_name_for_api_type`, which match the registry only, so a class name is rejected as an unknown type
- Override `def self.api_type` to keep the wire value stable across a class rename — the default is derived, so renaming otherwise changes a public identifier
-- Build pickers from the family's `…/types` endpoint (`{ type, label, preference_schema }`), never a hardcoded list — extension kinds then appear for free
+- Build pickers from the family's `…/types` endpoint (`{ type, label, schema }`, where `schema` is the JSON Schema of the type's preferences), never a hardcoded list — extension kinds then appear for free
- Adding a built-in kind means updating the serializer's `comment:` list in the same change (see the value-list tiers below)
**Registry-selected strategy classes** (fulfillment, delivery-rate, pickup-point, payout, tax and digital-asset providers, order routing strategies — plain Ruby, stored as a class-name string on a column or preference):
diff --git a/docs/api-reference/store.yaml b/docs/api-reference/store.yaml
index 53bda73bb8..d98995f517 100644
--- a/docs/api-reference/store.yaml
+++ b/docs/api-reference/store.yaml
@@ -11854,50 +11854,21 @@ components:
- id
- name
- code
- PreferenceField:
+ PreferenceSchema:
type: object
- description: A single configurable preference on a payment method, promotion
- rule/action, or calculator. The frontend uses `type` + `default` to render
- a sensible input.
- properties:
- key:
- type: string
- example: amount_min
- type:
- type: string
- example: decimal
- description: string | text | password | integer | decimal | boolean | array
- | hash
- default:
- description: Default value (any JSON type), null when there is no default
- nullable: true
- required:
- - key
- - type
- PromotionActionCalculator:
- type: object
- description: The action's nested calculator (when the action carries one — null
- for actions like `free_shipping`)
- properties:
- type:
- type: string
- example: flat_rate
- description: Wire shorthand for the calculator subclass
- label:
- type: string
- example: Flat Rate
- preferences:
- type: object
- additionalProperties: true
- preference_schema:
- type: array
- items:
- "$ref": "#/components/schemas/PreferenceField"
- required:
- - type
- - label
- - preferences
- - preference_schema
+ description: 'The JSON Schema (draft 2020-12) of a type''s `preferences`: one
+ property per setting, with `format` (`money`, `currency`, `iso-country`, `prefixed-id`,
+ …), `enum`, `default`, `x-spree-secret` for a secret and `x-spree-prefix`
+ for an id list. Unknown keys are refused.'
+ additionalProperties: true
+ example:
+ type: object
+ properties:
+ amount:
+ type: string
+ format: money
+ default: '0.0'
+ additionalProperties: false
PromotionActionLineItem:
type: object
description: One row in a `create_line_items` action — the variant added to
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index aad2920a4c..cf457488b9 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -849,7 +849,7 @@ Other changes that come with it:
- **Numbers are no longer parsed by locale.** Price, variant, payment, refund, store credit, gift card, discount and fee amounts take a number or a canonical decimal string (`"1234.56"`); any other text raises `Spree::Money::InvalidFormat`, which the API answers with `invalid_money_format`. Before 6.0 they were re-read under the request's language, so a store whose language writes a comma decimal (Dutch, German, French) saved the dashboard's `49.50` as 4950, and an unchanged price grew tenfold on each save. Send canonical decimal strings (`"1234.56"`) and convert localized input in the client. `Spree::LocalizedNumber` still works with a warning until 6.1. If your prices were saved in a comma-decimal store before upgrading, check them.
- **Rounding follows the currency.** Taxes, percentage discounts, promotion splits and shipping markups round to the currency's own decimal places from the ISO 4217 table: whole yen, three decimals for dinar. Two-decimal currencies are unchanged. Open carts in other currencies may change by less than one minor unit the next time they are recalculated. Placed orders do not change. Spree now gives the Hungarian forint two decimal places, as ISO 4217 does.
-- **Money on the API is written to each currency's decimals.** Every amount in the Store, Admin and Seller APIs, and so in webhook payloads and email variables, is a decimal string with exactly its currency's decimal places: `"10.00"` (was `"10.0"`), `"1000"` in yen (was `"1000.0"`), `"1.500"` in dinar. Unit prices keep up to four decimals. Fields that were JSON numbers are now strings: `cart.order_minimum` and `order_minimum_shortfall`, the product filter price range `min`/`max`, report money metrics and percentages, and the store's `preferred_default_minimum_payout_amount` and `preferred_default_commission_tax_rate`. Clients comparing these strings, or parsing them as numbers, should switch to exact decimal arithmetic; the SDKs export `sumMoney`, `subtractMoney`, `multiplyMoney`, `compareMoney` and `isZeroMoney`.
+- **Money on the API is written to each currency's decimals.** Every amount in the Store, Admin and Seller APIs, and so in webhook payloads and email variables, is a decimal string with exactly its currency's decimal places: `"10.00"` (was `"10.0"`), `"1000"` in yen (was `"1000.0"`), `"1.500"` in dinar. Unit prices keep up to four decimals. Fields that were JSON numbers are now strings: `cart.order_minimum` and `order_minimum_shortfall`, the product filter price range `min`/`max`, report money metrics and percentages, and the store's `default_minimum_payout_amount` and `default_commission_tax_rate`. Clients comparing these strings, or parsing them as numbers, should switch to exact decimal arithmetic; the SDKs export `sumMoney`, `subtractMoney`, `multiplyMoney`, `compareMoney` and `isZeroMoney`.
- **Admin and Seller writes refuse JSON numbers for money.** Amounts and rates, including those inside `preferences`, must be canonical decimal strings (`"19.99"`). A number, a localized or grouped string, or more decimals than the field holds is answered with `422` and `invalid_money_format`, naming the field.
- **Amounts may not carry more decimals than they can keep.** Now that the columns hold four decimals, the database no longer rounds away a fraction of a cent, so a payment, refund, store credit, gift card, fee or discount with more decimals than its currency has (`10.0049` dollars) fails validation with `too_many_decimals`. Unit prices and cost prices allow four, tax rates five decimals of the fraction (`rate_percent` `"7.125"`, not `"7.1255"`), and price list percentages three. Round in your own code before saving. A manual order discount's `value` and a commission rate's `value` are read as strictly as other money fields.
- **The Admin and Seller APIs no longer return `display_*` money fields.** Responses carry the amount (`"29.99"`) with its currency, and the client formats it in the reader's own language. Before 6.0 the server formatted a copy in the request's language, which could disagree with the editable amount beside it. Format with `Intl.NumberFormat` or your platform's equivalent. The Store API, webhook payloads and email templates keep their `display_*` fields, and labels such as `display_name` are unchanged.
diff --git a/packages/admin-sdk/src/types/generated/DeliveryMethod.ts b/packages/admin-sdk/src/types/generated/DeliveryMethod.ts
index 5e8f766511..d30e37553b 100644
--- a/packages/admin-sdk/src/types/generated/DeliveryMethod.ts
+++ b/packages/admin-sdk/src/types/generated/DeliveryMethod.ts
@@ -1,7 +1,7 @@
-// Typelizer digest b2dab789219ed7e08f944230d1715dc6
+// Typelizer digest 6db13c5a972bfd8abbd189f4e59085d7
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-import type {DeliveryMethodService, DeliveryMethodRule} from '@/types'
+import type {TypedDeliveryCalculator, DeliveryMethodService, DeliveryMethodRule} from '@/types'
interface DeliveryMethod {
id: string;
@@ -36,8 +36,7 @@ interface DeliveryMethod {
pickup_point_provider: string | null;
/** Rate provider; null prices through the calculator. Built-in: internal, freight. Provider gems register more (e.g. easy_post). */
rate_provider: string | null;
- calculator_type: string | null;
- calculator_preferences: Record<string, unknown> | null;
+ calculator: TypedDeliveryCalculator | null;
}
export default DeliveryMethod;
diff --git a/packages/admin-sdk/src/types/generated/Store.ts b/packages/admin-sdk/src/types/generated/Store.ts
index db3cd057f4..d92b9497ca 100644
--- a/packages/admin-sdk/src/types/generated/Store.ts
+++ b/packages/admin-sdk/src/types/generated/Store.ts
@@ -1,4 +1,4 @@
-// Typelizer digest ecef3492ed9ea6c3b5e9855520a8cfcd
+// Typelizer digest 3a555a09b00095bd8b2223e026a5b1ac
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {SetupTask} from '@/types'
@@ -8,63 +8,63 @@ interface Store {
metadata: Record<string, unknown>;
name: string;
code: string;
- preferred_storefront_url: string | null;
default_currency: string;
default_locale: string;
default_country_code: string | null;
mail_from_address: string | null;
customer_support_email: string | null;
new_order_notifications_email: string | null;
- preferred_send_consumer_transactional_emails: boolean;
- preferred_email_accent_color: string | null;
- preferred_email_background_color: string | null;
- preferred_email_card_color: string | null;
- preferred_email_text_color: string | null;
- preferred_email_heading_color: string | null;
- preferred_email_font: 'inter' | 'system' | 'helvetica' | 'georgia' | 'roboto' | 'lato' | 'merriweather' | null;
- preferred_admin_locale: string | null;
- preferred_timezone: string;
- preferred_weight_unit: 'g' | 'kg' | 'lb' | 'oz';
- preferred_unit_system: string;
- preferred_storefront_access: string;
- preferred_guest_checkout: boolean;
- preferred_always_include_confirm_step: boolean;
- preferred_company_field_enabled: boolean;
- preferred_address_requires_company: boolean;
- preferred_address_requires_phone: boolean;
- preferred_capture_method: string;
- preferred_track_inventory_levels: boolean;
- preferred_stock_reservations_enabled: boolean;
- preferred_low_stock_threshold: number;
- preferred_tax_using_ship_address: boolean;
- preferred_track_price_history: boolean;
- preferred_show_products_without_price: boolean;
- preferred_disable_sku_validation: boolean;
- preferred_pricing_provider: string;
- preferred_inventory_provider: string;
- preferred_pricing_provider_failure_policy: string;
- preferred_inventory_provider_failure_policy: string;
- preferred_default_payouts_schedule_interval: string;
- preferred_auto_approve_sellers: boolean;
- preferred_auto_approve_seller_products: boolean;
- preferred_send_seller_transactional_emails: boolean;
- preferred_document_number_format: string;
- preferred_order_number_prefix: string;
- preferred_order_number_suffix: string;
- preferred_order_number_sequence_start: number;
- preferred_limit_digital_download_count: boolean;
- preferred_digital_asset_authorized_clicks: number;
- preferred_limit_digital_download_days: boolean;
- preferred_digital_asset_authorized_days: number;
created_at: string;
updated_at: string;
/** Order routing strategy. Built-in: rules. Extensions may register more. */
- preferred_order_routing_strategy: string;
+ order_routing_strategy: string;
/** Payout provider; null uses the installation default. Built-in: system. Provider gems register more (e.g. stripe). */
- preferred_payout_provider: string | null;
+ payout_provider: string | null;
+ admin_locale: string | null;
+ timezone: string;
+ storefront_url: string | null;
+ weight_unit: 'g' | 'kg' | 'lb' | 'oz';
+ unit_system: string;
+ storefront_access: 'public' | 'prices_hidden' | 'login_required';
+ guest_checkout: boolean;
+ always_include_confirm_step: boolean;
+ company_field_enabled: boolean;
+ address_requires_company: boolean;
+ address_requires_phone: boolean;
+ capture_method: 'checkout' | 'on_dispatch' | 'manual';
+ track_inventory_levels: boolean;
+ stock_reservations_enabled: boolean;
+ low_stock_threshold: number;
+ tax_using_ship_address: boolean;
+ track_price_history: boolean;
+ show_products_without_price: boolean;
+ disable_sku_validation: boolean;
+ pricing_provider: string;
+ inventory_provider: string;
+ pricing_provider_failure_policy: 'fallback' | 'strict';
+ inventory_provider_failure_policy: 'fallback' | 'strict';
+ default_payouts_schedule_interval: 'daily' | 'weekly' | 'biweekly' | 'monthly' | 'manual';
+ auto_approve_sellers: boolean;
+ auto_approve_seller_products: boolean;
+ send_seller_transactional_emails: boolean;
+ document_number_format: 'sequential' | 'random';
+ order_number_prefix: string;
+ order_number_suffix: string;
+ order_number_sequence_start: number;
+ limit_digital_download_count: boolean;
+ digital_asset_authorized_clicks: number;
+ limit_digital_download_days: boolean;
+ digital_asset_authorized_days: number;
+ send_consumer_transactional_emails: boolean;
+ email_accent_color: string | null;
+ email_background_color: string | null;
+ email_card_color: string | null;
+ email_text_color: string | null;
+ email_heading_color: string | null;
+ email_font: 'inter' | 'system' | 'helvetica' | 'georgia' | 'roboto' | 'lato' | 'merriweather' | null;
order_number_sequence_started: boolean;
- preferred_default_minimum_payout_amount: string | null;
- preferred_default_commission_tax_rate: string | null;
+ default_minimum_payout_amount: string | null;
+ default_commission_tax_rate: string | null;
url: string;
api_url: string;
setup_tasks: Array<SetupTask>;
diff --git a/packages/admin-sdk/src/zod/generated/Store.ts b/packages/admin-sdk/src/zod/generated/Store.ts
index 7ffd18c85a..730756d56e 100644
--- a/packages/admin-sdk/src/zod/generated/Store.ts
+++ b/packages/admin-sdk/src/zod/generated/Store.ts
@@ -7,61 +7,61 @@ export const StoreSchema = z.object({
metadata: z.record(z.string(), z.unknown()),
name: z.string(),
code: z.string(),
- preferred_storefront_url: z.string().nullable(),
default_currency: z.string(),
default_locale: z.string(),
default_country_code: z.string().nullable(),
mail_from_address: z.string().nullable(),
customer_support_email: z.string().nullable(),
new_order_notifications_email: z.string().nullable(),
- preferred_send_consumer_transactional_emails: z.boolean(),
- preferred_email_accent_color: z.string().nullable(),
- preferred_email_background_color: z.string().nullable(),
- preferred_email_card_color: z.string().nullable(),
- preferred_email_text_color: z.string().nullable(),
- preferred_email_heading_color: z.string().nullable(),
- preferred_email_font: z.string().nullable(),
- preferred_admin_locale: z.string().nullable(),
- preferred_timezone: z.string(),
- preferred_weight_unit: z.string(),
- preferred_unit_system: z.string(),
- preferred_storefront_access: z.string(),
- preferred_guest_checkout: z.boolean(),
- preferred_always_include_confirm_step: z.boolean(),
- preferred_company_field_enabled: z.boolean(),
- preferred_address_requires_company: z.boolean(),
- preferred_address_requires_phone: z.boolean(),
- preferred_capture_method: z.string(),
- preferred_track_inventory_levels: z.boolean(),
- preferred_stock_reservations_enabled: z.boolean(),
- preferred_low_stock_threshold: z.number(),
- preferred_tax_using_ship_address: z.boolean(),
- preferred_track_price_history: z.boolean(),
- preferred_show_products_without_price: z.boolean(),
- preferred_disable_sku_validation: z.boolean(),
- preferred_pricing_provider: z.string(),
- preferred_inventory_provider: z.string(),
- preferred_pricing_provider_failure_policy: z.string(),
- preferred_inventory_provider_failure_policy: z.string(),
- preferred_default_payouts_schedule_interval: z.string(),
- preferred_auto_approve_sellers: z.boolean(),
- preferred_auto_approve_seller_products: z.boolean(),
- preferred_send_seller_transactional_emails: z.boolean(),
- preferred_document_number_format: z.string(),
- preferred_order_number_prefix: z.string(),
- preferred_order_number_suffix: z.string(),
- preferred_order_number_sequence_start: z.number(),
- preferred_limit_digital_download_count: z.boolean(),
- preferred_digital_asset_authorized_clicks: z.number(),
- preferred_limit_digital_download_days: z.boolean(),
- preferred_digital_asset_authorized_days: z.number(),
created_at: z.string(),
updated_at: z.string(),
- preferred_order_routing_strategy: z.string(),
- preferred_payout_provider: z.string().nullable(),
+ order_routing_strategy: z.string(),
+ payout_provider: z.string().nullable(),
+ admin_locale: z.string().nullable(),
+ timezone: z.string(),
+ storefront_url: z.string().nullable(),
+ weight_unit: z.string(),
+ unit_system: z.string(),
+ storefront_access: z.string(),
+ guest_checkout: z.boolean(),
+ always_include_confirm_step: z.boolean(),
+ company_field_enabled: z.boolean(),
+ address_requires_company: z.boolean(),
+ address_requires_phone: z.boolean(),
+ capture_method: z.string(),
+ track_inventory_levels: z.boolean(),
+ stock_reservations_enabled: z.boolean(),
+ low_stock_threshold: z.number(),
+ tax_using_ship_address: z.boolean(),
+ track_price_history: z.boolean(),
+ show_products_without_price: z.boolean(),
+ disable_sku_validation: z.boolean(),
+ pricing_provider: z.string(),
+ inventory_provider: z.string(),
+ pricing_provider_failure_policy: z.string(),
+ inventory_provider_failure_policy: z.string(),
+ default_payouts_schedule_interval: z.string(),
+ auto_approve_sellers: z.boolean(),
+ auto_approve_seller_products: z.boolean(),
+ send_seller_transactional_emails: z.boolean(),
+ document_number_format: z.string(),
+ order_number_prefix: z.string(),
+ order_number_suffix: z.string(),
+ order_number_sequence_start: z.number(),
+ limit_digital_download_count: z.boolean(),
+ digital_asset_authorized_clicks: z.number(),
+ limit_digital_download_days: z.boolean(),
+ digital_asset_authorized_days: z.number(),
+ send_consumer_transactional_emails: z.boolean(),
+ email_accent_color: z.string().nullable(),
+ email_background_color: z.string().nullable(),
+ email_card_color: z.string().nullable(),
+ email_text_color: z.string().nullable(),
+ email_heading_color: z.string().nullable(),
+ email_font: z.string().nullable(),
order_number_sequence_started: z.boolean(),
- preferred_default_minimum_payout_amount: z.string().nullable(),
- preferred_default_commission_tax_rate: z.string().nullable(),
+ default_minimum_payout_amount: z.string().nullable(),
+ default_commission_tax_rate: z.string().nullable(),
url: z.string(),
api_url: z.string(),
setup_tasks: z.array(SetupTaskSchema),
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/marketplace.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/marketplace.tsx
index 5da958342d..f61ca53dbb 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/marketplace.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/marketplace.tsx
@@ -97,13 +97,10 @@ function MarketplaceSettingsPage({ store }: { store: Store }) {
(store.default_payouts_schedule_interval as (typeof PAYOUT_SCHEDULE_INTERVALS)[number]) ??
'monthly',
// `String` only until the regenerated Store type reads these as the decimal strings the API sends.
- default_minimum_payout_amount: String(
- store.default_minimum_payout_amount ?? '0',
- ),
+ default_minimum_payout_amount: String(store.default_minimum_payout_amount ?? '0'),
auto_approve_sellers: store.auto_approve_sellers ?? false,
auto_approve_seller_products: store.auto_approve_seller_products ?? false,
- send_seller_transactional_emails:
- store.send_seller_transactional_emails ?? true,
+ send_seller_transactional_emails: store.send_seller_transactional_emails ?? true,
commission_tax_rate_percentage:
fractionToPercent(String(store.default_commission_tax_rate ?? '')) || '0',
},
@@ -154,16 +151,12 @@ function MarketplaceSettingsPage({ store }: { store: Store }) {
try {
await updateMutation.mutateAsync({
payout_provider: values.payout_provider,
- default_payouts_schedule_interval:
- values.default_payouts_schedule_interval,
+ default_payouts_schedule_interval: values.default_payouts_schedule_interval,
default_minimum_payout_amount: values.default_minimum_payout_amount,
auto_approve_sellers: values.auto_approve_sellers,
auto_approve_seller_products: values.auto_approve_seller_products,
- send_seller_transactional_emails:
- values.send_seller_transactional_emails,
- default_commission_tax_rate: percentToFraction(
- values.commission_tax_rate_percentage,
- ),
+ send_seller_transactional_emails: values.send_seller_transactional_emails,
+ default_commission_tax_rate: percentToFraction(values.commission_tax_rate_percentage),
})
form.reset(values)
toastManager.add({ type: 'success', title: t('admin.messages.store_settings_updated') })
diff --git a/packages/seller-dashboard-starter/package.json b/packages/seller-dashboard-starter/package.json
index f68a04ebfb..06c6cb2718 100644
--- a/packages/seller-dashboard-starter/package.json
+++ b/packages/seller-dashboard-starter/package.json
@@ -18,7 +18,6 @@
"dependencies": {
"@spree/admin-sdk": "workspace:^",
"@spree/seller-dashboard": "workspace:^",
- "@spree/admin-sdk": "workspace:^",
"@spree/dashboard-core": "workspace:^",
"@spree/dashboard-ui": "workspace:^",
"@spree/seller-sdk": "workspace:^",
diff --git a/spree/api/app/controllers/concerns/spree/api/v3/strict_money_params.rb b/spree/api/app/controllers/concerns/spree/api/v3/strict_money_params.rb
index f84b685c1f..384fc3b454 100644
--- a/spree/api/app/controllers/concerns/spree/api/v3/strict_money_params.rb
+++ b/spree/api/app/controllers/concerns/spree/api/v3/strict_money_params.rb
@@ -15,14 +15,16 @@ module Spree
amount compare_at_amount cost cost_price price unit_cost refund_amount settled_amount
minimum_payout_amount min_amount max_amount markup_flat
amount_min amount_max first_item additional_item minimal_amount normal_amount discount_amount
- base_amount minimum_item_total maximum_item_total preferred_default_minimum_payout_amount
+ base_amount minimum_item_total maximum_item_total default_minimum_payout_amount
+ preferred_default_minimum_payout_amount
].freeze
UNIT_PRICE_KEYS = %w[price compare_at_amount cost_price unit_cost].freeze
RATE_KEYS = %w[
rate rate_percent percent flat_percent base_percent markup_percent percentage
- price_adjustment_percentage commission_tax_rate preferred_default_commission_tax_rate
+ price_adjustment_percentage commission_tax_rate default_commission_tax_rate
+ preferred_default_commission_tax_rate
].freeze
# Values the merchant or a provider owns, stored as sent.
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/delivery_methods_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/delivery_methods_controller_spec.rb
index 0e6189ce93..b739605ab8 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/delivery_methods_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/delivery_methods_controller_spec.rb
@@ -240,11 +240,11 @@ RSpec.describe Spree::Api::V3::Admin::DeliveryMethodsController, type: :controll
patch :update, params: {
id: delivery_method.prefixed_id,
- calculator: { type: 'flexi_rate', preferences: { first_item: 5 } }
+ calculator: { type: 'flexi_rate', preferences: { max_items: 'many' } }
}, as: :json
expect(response).to have_http_status(:unprocessable_content)
- expect(json_response['error']['details']).to have_key('/calculator/preferences/first_item')
+ expect(json_response['error']['details']).to have_key('/calculator/preferences/max_items')
expect(delivery_method.reload.calculator).to eq(calculator)
end
diff --git a/spree/core/app/models/concerns/spree/preference_schema/json_schema.rb b/spree/core/app/models/concerns/spree/preference_schema/json_schema.rb
index 3640230fef..91fd2171dd 100644
--- a/spree/core/app/models/concerns/spree/preference_schema/json_schema.rb
+++ b/spree/core/app/models/concerns/spree/preference_schema/json_schema.rb
@@ -124,10 +124,11 @@ module Spree
{ 'type' => 'string' }.merge(FORMATS.fetch(format, {}).transform_keys(&:to_s))
end
- # The default in the form the API returns it: decimals as exact strings.
+ # The default in the form the API takes it back: a decimal as its exact
+ # string without trailing zeros ("100", "0.23"), as every API decimal is.
def self.wire_default(default, definition)
return default if default.nil?
- return BigDecimal(default.to_s, exception: false)&.as_json if definition[:type] == :decimal
+ return Spree::Money::Rounding.format_decimal(default) if definition[:type] == :decimal
default.as_json
end
diff --git a/spree/core/spec/models/spree/preference_schema/json_schema_spec.rb b/spree/core/spec/models/spree/preference_schema/json_schema_spec.rb
index 3ec2203376..25e50aad1e 100644
--- a/spree/core/spec/models/spree/preference_schema/json_schema_spec.rb
+++ b/spree/core/spec/models/spree/preference_schema/json_schema_spec.rb
@@ -23,7 +23,7 @@ describe Spree::PreferenceSchema::JsonSchema do
it 'types money as an exact decimal string, nullable when it has no default' do
expect(property(Spree::Promotion::Rules::ItemTotal, :amount_min)).to include(
- 'type' => 'string', 'format' => 'money', 'pattern' => described_class::DECIMAL_PATTERN, 'default' => '100.0'
+ 'type' => 'string', 'format' => 'money', 'pattern' => described_class::DECIMAL_PATTERN, 'default' => '100'
)
expect(property(Spree::Promotion::Rules::ItemTotal, :amount_max)['type']).to eq(%w[string null])
end