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.

Remove code deprecated for Spree 6.0 (#14396)

Damian Legawiecfbdb50a3b298
diff --git a/docs/developer/how-to/custom-order-routing.mdx b/docs/developer/how-to/custom-order-routing.mdx
index de37b42171..1969308bf4 100644
--- a/docs/developer/how-to/custom-order-routing.mdx
+++ b/docs/developer/how-to/custom-order-routing.mdx
@@ -234,9 +234,6 @@ First register the class so it's selectable (this is the allowlist the model val
```ruby
# config/initializers/spree.rb
Spree.order_routing.strategies << 'Acme::Oms::Strategy'.constantize
-
-# Optionally drop the legacy escape hatch:
-# Spree.order_routing.strategies.delete(Spree::OrderRouting::Strategy::Legacy)
```
Then select it by class name string — set on `Spree::Store` (default) or `Spree::Channel` (override). Setting an unregistered class fails validation.
diff --git a/docs/developer/upgrades/5.4-to-5.5.mdx b/docs/developer/upgrades/5.4-to-5.5.mdx
index 8b5ec40148..4a21411ef2 100644
--- a/docs/developer/upgrades/5.4-to-5.5.mdx
+++ b/docs/developer/upgrades/5.4-to-5.5.mdx
@@ -258,7 +258,7 @@ store.update!(preferred_order_routing_strategy: 'Spree::OrderRouting::Strategy::
The Legacy strategy delegates to `Spree::Stock::Coordinator`, which is the exact pre-5.5 packing pipeline — every active stock location is packed, the Prioritizer distributes inventory units across the resulting packages, and no merchant routing rules are consulted. Your existing customizations on `Coordinator`, `Packer`, `Prioritizer`, and the splitters keep working unchanged.
<Warning>
-`Spree::OrderRouting::Strategy::Legacy` and `Spree::Stock::Coordinator` are slated for removal in Spree 6.0. Use this only as a temporary escape hatch while you evaluate the new Rules strategy. New 5.5+ installations should stay on the default Rules strategy.
+`Spree::OrderRouting::Strategy::Legacy` **was removed in Spree 6.0**. It exists only on the 5.5/5.6 line, as a temporary escape hatch while you evaluate the Rules strategy. Stores still carrying this value fall back to the default Rules strategy on 6.0 (with a logged warning), so clear the preference before upgrading.
</Warning>
## Behavior changes to review
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index 914061d465..ecc3442749 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -213,6 +213,73 @@ Removed keys (their classes no longer exist): `carts_validate_service` (completi
If you override a workflow seam, subclass the shipped workflow (or implement the same `perform` keyword contract) — workflow arguments are plain Ruby keywords, so a mismatch raises `ArgumentError` at call time, not silently.
+## Removed in 6.0
+
+These were deprecated in 5.x and are **gone now** — there is no bridge, so calls raise `NoMethodError`. Most were one-line delegations to a replacement that already exists.
+
+| Removed | Use instead |
+|---|---|
+| `Product#default_image`, `#featured_image`, `#primary_image` | `#primary_media` |
+| `Variant#default_image`, `#primary_image` | `#primary_media` |
+| `Address#user_default_billing?`, `#user_default_shipping?` | `#is_default_billing?`, `#is_default_shipping?` |
+| `OptionType#color?` | `#color_swatch?` |
+| `Category#set_store` | `#ensure_store` |
+| `Category.for_taxonomy` | `.for_store` |
+| `Store#admin_users` | `#users` |
+| `Store#supported_shipping_zones` | `#countries_with_shipping_coverage` |
+| `Spree.searcher_class` | `Spree.search_provider` |
+| `Spree.admin_user_class.spree_admin_created?` | `.spree_admin.exists?` |
+| `BaseMailer#set_email_locale` | wrap the action body in `with_store_locale(store) { ... }` |
+| `Asset#styles`, `ImageMethods#generate_url`, `#original_url` | Active Storage variants with `cdn_image_url` |
+| `Spree::ImageMethods`, `Spree::NumberAsParam` (concerns) | deleted — `NumberAsParam` was already a no-op; prefixed IDs come from `Spree::PrefixedId` |
+| `Product.with_option`, `.with`, `.in_name`, `.in_name_or_keywords`, `.in_name_or_description`, `.with_ids`, `.for_user` | `.with_option_value`, `.search`, `where(id: ids)` |
+| `Product.add_search_scope` | plain `scope :name, -> { ... }` |
+| `Spree::Image::Configuration::ActiveStorage` | deleted — an empty no-op module; all logic lives in `Spree::Asset` |
+| `Spree::OrderRouting::Strategy::Legacy` | `Spree::OrderRouting::Strategy::Rules` (see below) |
+
+### The Legacy order-routing strategy is gone
+
+`Spree::OrderRouting::Strategy::Legacy` — the pre-5.5 escape hatch that delegated straight to `Spree::Stock::Coordinator` and consulted no routing rules — is removed and no longer registered in `Spree.order_routing.strategies`.
+
+A store or channel still carrying `preferred_order_routing_strategy: 'Spree::OrderRouting::Strategy::Legacy'` **keeps working**: `Order#order_routing_strategy` ignores unregistered classes, logs a warning, and falls back to `Strategy::Rules`. Clear the stale preference to silence the warning — note that saving such a record now fails validation, since the value is no longer in the registry.
+
+`Spree::Stock::Coordinator` itself stays — cart fulfillment building, exchanges, and claims still use it.
+
+### `Store.default` no longer builds a store
+
+`Spree::Store.default` returned an **unpersisted** `Store.new(default: true)` when no default store existed. It now returns `nil`.
+
+This matters more than it looks: `Spree::Current.store` falls back to `Store.default`, and every `Spree::SingleStoreResource` model resolves its own `store` from `Spree::Current.store`. Without a default store, those records now fail validation with "Store can't be blank" instead of silently attaching to a throwaway store.
+
+Make sure a default store exists before creating store-scoped records, and set `Spree::Current.store` in jobs, rake tasks, and tests that run outside a request.
+
+### The `DefaultPrice` concern is gone — `price_in` / `set_price` is the interface
+
+`Spree::DefaultPrice` and the `enable_legacy_default_price` setting are removed, along with the `has_one :default_price` association on `Variant`. Prices live in `spree_prices`, one row per currency, and a price is always an **amount plus a currency** — there is no longer an implicit "the" price.
+
+The single-currency accessors are gone from both `Variant` and `Product`:
+
+| Removed | Use instead |
+|---|---|
+| `variant.price`, `product.price` | `variant.price_in(currency).amount` or `amount_in(currency)` |
+| `variant.price = x`, `product.price = x` | `variant.set_price(currency, x)` |
+| `variant.default_price` | `variant.price_in(currency)` |
+| `variant.currency`, `product.currency` | the currency is an argument now — pass the one you mean |
+| `display_price`, `display_amount` | `price_in(currency).display_amount` |
+| `compare_at_price=` | `set_price(currency, amount, compare_at_amount)` |
+| `display_compare_at_price` | `price_in(currency).display_compare_at_amount` |
+| `price_including_vat_for(opts)` | `price_in(currency).price_including_vat_for(opts)` |
+| `has_default_price?` | `prices.base_prices.exists?(currency: currency)` |
+
+The `compare_at_price` **reader** (which resolves against `cost_currency`) is unchanged on both `Variant` and `Product` — only the writer is gone. So are the `price_in` / `amount_in` / `compare_at_amount_in` readers.
+
+Also note:
+
+- **Ransack:** `default_price` is no longer a searchable association on `Variant`; query `prices` instead.
+- **`Spree::PermittedAttributes`:** the dead `:price` and `:compare_at_price` entries are dropped from `product_attributes` and `variant_attributes`. Prices were already written as nested `prices: [{ amount:, currency: }]` under variants — the top-level keys had no writer behind them.
+- Localized number parsing still happens: `Spree::Price#amount=` runs `Spree::LocalizedNumber.parse`, so `set_price(currency, '1,599.99')` works as `price=` did.
+- The variant validation that inferred a missing price from the product's default variant is gone. Set prices explicitly (the product and variant factories already do).
+
## Deprecated in 6.0, removed in 6.1
Every rename keeps the legacy name working for one release with a deprecation warning. The notable ones:
diff --git a/packages/dashboard/e2e/global-setup.ts b/packages/dashboard/e2e/global-setup.ts
index 482eb97ca8..03633d3af7 100644
--- a/packages/dashboard/e2e/global-setup.ts
+++ b/packages/dashboard/e2e/global-setup.ts
@@ -55,7 +55,8 @@ const BOOTSTRAP_RUBY = [
`taxonomy = s.taxonomies.find_or_create_by!(name: 'Categories')`,
`category = taxonomy.taxons.where(name: '${FIXTURE_PROMO_TAXON}').first_or_create!(parent: taxonomy.root)`,
`shipping_category = Spree::ShippingCategory.first || Spree::ShippingCategory.create!(name: 'Default')`,
- `product = Spree::Product.where(name: '${FIXTURE_PROMO_PRODUCT}').first_or_create!(price: 19.99, shipping_category: shipping_category, store: s, status: 'active')`,
+ `product = Spree::Product.where(name: '${FIXTURE_PROMO_PRODUCT}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active')`,
+ `product.default_variant.set_price(s.default_currency, 19.99)`,
`product.taxons << category unless product.taxons.include?(category)`,
// Stock the promo product on the store's default stock location so
// order-creation tests can add it to a draft order without the
@@ -67,20 +68,20 @@ const BOOTSTRAP_RUBY = [
// I → row-action clone/delete) so the serial suite can mutate them in any
// order without poisoning siblings. All start `active` so the status spec
// sees a clean transition.
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_A}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_B}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_C}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_D}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_E}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_F}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_G}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_H}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_I}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_J}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_K}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_L}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_M}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
- `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_N}').first_or_create!(price: 9.99, shipping_category: shipping_category, store: s, status: 'active').update!(status: 'active')`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_A}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_B}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_C}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_D}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_E}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_F}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_G}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_H}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_I}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_J}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_K}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_L}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_M}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
+ `Spree::Product.where(name: '${FIXTURE_BULK_PRODUCT_N}').first_or_create!(shipping_category: shipping_category, store: s, status: 'active').tap { |p| p.default_variant.set_price(s.default_currency, 9.99); p.update!(status: 'active') }`,
// Second channel beyond the seeded default; the channels bulk-action
// and filter specs need a non-default channel to add/remove against.
`bulk_channel = s.channels.where(code: '${FIXTURE_BULK_CHANNEL_CODE}').first_or_create!(name: '${FIXTURE_BULK_CHANNEL_NAME}')`,
diff --git a/spree/api/spec/serializers/spree/api/v3/price_history_serializer_spec.rb b/spree/api/spec/serializers/spree/api/v3/price_history_serializer_spec.rb
index 9c8df59fbb..d34a65ba4e 100644
--- a/spree/api/spec/serializers/spree/api/v3/price_history_serializer_spec.rb
+++ b/spree/api/spec/serializers/spree/api/v3/price_history_serializer_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
RSpec.describe Spree::Api::V3::PriceHistorySerializer do
let(:store) { @default_store }
let(:variant) { create(:variant) }
- let(:price) { variant.default_price }
+ let(:price) { variant.price_in(variant.cost_currency) }
let(:base_params) { { store: store, currency: 'USD' } }
let(:price_history) do
@@ -43,7 +43,7 @@ end
RSpec.describe Spree::Api::V3::Admin::PriceHistorySerializer do
let(:store) { @default_store }
let(:variant) { create(:variant) }
- let(:price) { variant.default_price }
+ let(:price) { variant.price_in(variant.cost_currency) }
let(:base_params) { { store: store, currency: 'USD' } }
let(:price_history) do
diff --git a/spree/core/app/mailers/spree/base_mailer.rb b/spree/core/app/mailers/spree/base_mailer.rb
index fe238fc655..97d126f596 100644
--- a/spree/core/app/mailers/spree/base_mailer.rb
+++ b/spree/core/app/mailers/spree/base_mailer.rb
@@ -64,19 +64,6 @@ module Spree
end
end
- # @deprecated Each mailer action now wraps its body in {#with_store_locale},
- # which also activates the store's translation fallbacks and restores the
- # previous locale afterwards. This method mutates `I18n.locale` for the rest
- # of the thread without restoring it. Will be removed in Spree 6.0.
- def set_email_locale
- Spree::Deprecation.warn(
- 'Spree::BaseMailer#set_email_locale is deprecated and will be removed in Spree 6.0. ' \
- 'Wrap the mailer action body in `with_store_locale(store, locale) { ... }` instead.'
- )
- locale = @order&.locale.presence || @order&.store&.default_locale || current_store&.default_locale
- I18n.locale = locale if locale.present?
- end
-
protected
# The "<store> <subject> #<number>" subject line shared by customer-facing
diff --git a/spree/core/app/models/concerns/spree/default_price.rb b/spree/core/app/models/concerns/spree/default_price.rb
deleted file mode 100644
index efb2ff4ccf..0000000000
--- a/spree/core/app/models/concerns/spree/default_price.rb
+++ /dev/null
@@ -1,138 +0,0 @@
-module Spree
- module DefaultPrice
- extend ActiveSupport::Concern
-
- DEPRECATION_MSG = 'Spree::DefaultPrice is deprecated and will be removed in Spree 6.0. ' \
- 'Use variant.set_price(currency, amount) and variant.price_in(currency) instead.'
-
- included do
- has_one :default_price,
- -> { with_deleted.where(currency: Spree::Store.default.default_currency) },
- class_name: 'Spree::Price',
- dependent: :destroy
-
- after_save :save_default_price, if: -> { Spree::Config.enable_legacy_default_price }
-
- def price
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.price
- else
- price_in(Spree::Store.default.default_currency).amount
- end
- end
-
- def price=(value)
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.price = value
- else
- set_price(Spree::Store.default.default_currency, value)
- end
- end
-
- def currency
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.currency
- else
- Spree::Store.default.default_currency
- end
- end
-
- def currency=(value)
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.currency = value
- end
- # no-op when legacy is disabled — currency is determined by the store
- end
-
- def display_price
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.display_price
- else
- price_in(Spree::Store.default.default_currency).display_amount
- end
- end
-
- def display_amount
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.display_amount
- else
- price_in(Spree::Store.default.default_currency).display_amount
- end
- end
-
- def compare_at_price
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.compare_at_price
- else
- price_in(Spree::Store.default.default_currency).compare_at_amount
- end
- end
-
- def compare_at_price=(value)
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.compare_at_price = value
- else
- default_currency = Spree::Store.default.default_currency
- price_record = price_in(default_currency)
- price_record.compare_at_amount = value
- price_record.save! if price_record.persisted?
- end
- end
-
- def display_compare_at_price
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.display_compare_at_price
- else
- price_in(Spree::Store.default.default_currency).display_compare_at_amount
- end
- end
-
- def price_including_vat_for(price_options)
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- find_or_build_default_price.price_including_vat_for(price_options)
- else
- price_in(Spree::Store.default.default_currency).price_including_vat_for(price_options)
- end
- end
-
- def has_default_price?
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- !default_price.nil?
- else
- prices.base_prices.any? { |p| p.currency == Spree::Store.default.default_currency }
- end
- end
-
- def find_or_build_default_price
- Spree::Deprecation.warn(Spree::DefaultPrice::DEPRECATION_MSG)
- if Spree::Config.enable_legacy_default_price
- default_price || build_default_price
- else
- prices.base_prices.find { |p| p.currency == Spree::Store.default.default_currency } ||
- prices.build(currency: Spree::Store.default.default_currency)
- end
- end
-
- private
-
- def default_price_changed?
- default_price && (default_price.changed? || default_price.new_record?)
- end
-
- def save_default_price
- default_price.save if default_price_changed?
- end
- end
- end
-end
diff --git a/spree/core/app/models/concerns/spree/image_methods.rb b/spree/core/app/models/concerns/spree/image_methods.rb
deleted file mode 100644
index 7ac3ec1aa6..0000000000
--- a/spree/core/app/models/concerns/spree/image_methods.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module Spree
- module ImageMethods
- extend ActiveSupport::Concern
-
- def generate_url(size:, gravity: 'centre', quality: 80, background: [0, 0, 0])
- Spree::Deprecation.warn("ImageMethods#generate_url is deprecated and will be removed in Spree 6.0. Please use active storage variants with cdn_image_url")
-
- return if size.blank?
-
- size = size.gsub(/\s+/, '')
-
- return unless size.match(/(\d+)x(\d+)/)
-
- width, height = size.split('x').map(&:to_i)
- gravity = translate_gravity_for_mini_magick(gravity)
-
- # FIXME: bring back support for background color
-
- cdn_image_url(attachment.variant(resize_and_pad: [width, height, { gravity: gravity }], saver: { quality: quality }))
- end
-
- def original_url
- Spree::Deprecation.warn("ImageMethods#original_url is deprecated and will be removed in Spree 6.0. Please use active storage variants with cdn_image_url")
-
- cdn_image_url(attachment)
- end
-
- private
-
- def translate_gravity_for_mini_magick(gravity)
- variant_processor = Rails.application.config.active_storage.variant_processor
-
- if gravity.downcase == 'centre' && [:mini_magick, nil].include?(variant_processor)
- 'center'
- else
- gravity
- end
- end
- end
-end
diff --git a/spree/core/app/models/concerns/spree/number_as_param.rb b/spree/core/app/models/concerns/spree/number_as_param.rb
deleted file mode 100644
index 52f7d2e7c1..0000000000
--- a/spree/core/app/models/concerns/spree/number_as_param.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module Spree
- module NumberAsParam
- extend ActiveSupport::Concern
-
- included do
- Spree::Deprecation.warn(
- 'Spree::NumberAsParam is deprecated and will be removed in Spree 6.0. ' \
- 'Models now use Spree::PrefixedId with Sqids-based prefixed_id method instead. ' \
- 'This concern no longer provides any functionality and can be safely removed.'
- )
- end
- end
-end
diff --git a/spree/core/app/models/concerns/spree/product_scopes.rb b/spree/core/app/models/concerns/spree/product_scopes.rb
index 7c675778ec..7def3f7614 100644
--- a/spree/core/app/models/concerns/spree/product_scopes.rb
+++ b/spree/core/app/models/concerns/spree/product_scopes.rb
@@ -3,16 +3,6 @@ module Spree
extend ActiveSupport::Concern
included do
- cattr_accessor :search_scopes do
- []
- end
-
- def self.add_search_scope(name, &block)
- Spree::Deprecation.warn("add_search_scope is deprecated and will be removed in Spree 6.0. Use scope :#{name}, &block instead or use method instead")
- singleton_class.send(:define_method, name.to_sym, &block)
- search_scopes << name.to_sym
- end
-
scope :ascend_by_updated_at, -> { order("#{Product.quoted_table_name}.updated_at ASC") }
scope :descend_by_updated_at, -> { order("#{Product.quoted_table_name}.updated_at DESC") }
scope :ascend_by_name, -> { order("#{Product.quoted_table_name}.name ASC") }
@@ -169,20 +159,6 @@ module Spree
order(Arel.sql("#{min_position_sql} ASC"))
}
- # Deprecated — remove in 6.0. Not used internally.
- def self.with_option(option)
- Spree::Deprecation.warn('with_option is deprecated and will be removed in Spree 6.0.')
- if option.is_a?(OptionType)
- joins(:option_types).where(spree_option_types: { id: option.id })
- elsif option.is_a?(Integer)
- joins(:option_types).where(spree_option_types: { id: option })
- elsif OptionType.column_for_attribute('id').type == :uuid
- joins(:option_types).where(spree_option_types: { name: option }).or(Product.joins(:option_types).where(spree_option_types: { id: option }))
- else
- joins(:option_types).where(OptionType.table_name => { name: option })
- end
- end
-
scope :with_option_value, ->(option, value) {
option_type_id = case option
when OptionType then option.id
@@ -228,37 +204,6 @@ module Spree
scope
end
- # Deprecated — remove in 6.0. Not used internally.
- def self.with(value)
- Spree::Deprecation.warn('Product.with is deprecated and will be removed in Spree 6.0.')
- includes(variants: :option_values).
- where("#{OptionValue.table_name}.name = ?", value)
- end
-
- # Deprecated — remove in 6.0. Use .search scope instead.
- def self.in_name(words)
- Spree::Deprecation.warn('in_name is deprecated and will be removed in Spree 6.0. Use .search instead.')
- like_any([:name], prepare_words(words))
- end
-
- # Deprecated — remove in 6.0. Use .search scope instead.
- def self.in_name_or_keywords(words)
- Spree::Deprecation.warn('in_name_or_keywords is deprecated and will be removed in Spree 6.0. Use .search instead.')
- like_any([:name, :meta_keywords], prepare_words(words))
- end
-
- # Deprecated — remove in 6.0. Use .search scope instead.
- def self.in_name_or_description(words)
- Spree::Deprecation.warn('in_name_or_description is deprecated and will be removed in Spree 6.0. Use .search instead.')
- like_any([:name, :description, :meta_description, :meta_keywords], prepare_words(words))
- end
-
- # Deprecated — remove in 6.0. Use where(id: ids) directly.
- def self.with_ids(*ids)
- Spree::Deprecation.warn('with_ids is deprecated and will be removed in Spree 6.0. Use where(id: ids) instead.')
- where(id: ids)
- end
-
scope :not_deleted, -> {
where("#{Product.quoted_table_name}.deleted_at IS NULL or #{Product.quoted_table_name}.deleted_at >= ?", Time.zone.now)
}
@@ -335,16 +280,6 @@ module Spree
available(nil, currency)
end
- # Deprecated — remove in 6.0. Not used internally.
- def self.for_user(user = nil)
- Spree::Deprecation.warn('for_user is deprecated and will be removed in Spree 6.0.')
- if user.try(:has_spree_role?, 'admin')
- with_deleted
- else
- not_deleted.where(status: 'active')
- end
- end
-
# Orders products by best-selling metrics (+units_sold_count+, +revenue+)
# tracked directly on +spree_products+. Uses Arel::Nodes::As so that
# ORDER BY expressions appear in SELECT and work with DISTINCT (same
@@ -373,15 +308,6 @@ module Spree
end
private_class_method :price_table_name
- # Produce an array of keywords for use in scopes.
- # Always return array with at least an empty string to avoid SQL errors
- def self.prepare_words(words)
- return [''] if words.blank?
-
- a = words.split(/[,\s]/).map(&:strip)
- a.any? ? a : ['']
- end
- private_class_method :prepare_words
end
end
end
diff --git a/spree/core/app/models/concerns/spree/user_roles.rb b/spree/core/app/models/concerns/spree/user_roles.rb
index ac7ebdbec8..9d60cd8dc4 100644
--- a/spree/core/app/models/concerns/spree/user_roles.rb
+++ b/spree/core/app/models/concerns/spree/user_roles.rb
@@ -47,11 +47,6 @@ module Spree
role_users.where(resource: resource).joins(:role).where(Spree::Role.table_name => { name: role_name }).exists?
end
- def self.spree_admin_created?
- Spree::Deprecation.warn('Spree.admin_user_class.spree_admin_created? is deprecated and will be removed in Spree 5.5')
- spree_admin.exists?
- end
-
# Returns true if the user has the admin role for a given resource
#
# @param resource [Spree::Base] The resource to check the admin role for
diff --git a/spree/core/app/models/spree/address.rb b/spree/core/app/models/spree/address.rb
index 27d7100bf5..73c807a62f 100644
--- a/spree/core/app/models/spree/address.rb
+++ b/spree/core/app/models/spree/address.rb
@@ -120,16 +120,6 @@ module Spree
end.flatten
end
- def user_default_billing?
- Spree::Deprecation.warn('Spree::Address#user_default_billing? is deprecated and will be removed in Spree 6.0. Use #is_default_billing? instead.')
- is_default_billing?
- end
-
- def user_default_shipping?
- Spree::Deprecation.warn('Spree::Address#user_default_shipping? is deprecated and will be removed in Spree 6.0. Use #is_default_shipping? instead.')
- is_default_shipping?
- end
-
# In 6.0 these become real columns on Address, replacing User#bill_address_id / ship_address_id.
# For now they delegate to the User FK so the API shape is stable.
def is_default_billing?
diff --git a/spree/core/app/models/spree/asset.rb b/spree/core/app/models/spree/asset.rb
index 7f6c587866..1a7ef286c4 100644
--- a/spree/core/app/models/spree/asset.rb
+++ b/spree/core/app/models/spree/asset.rb
@@ -4,7 +4,6 @@ module Spree
include Support::ActiveStorage
include Rails.application.routes.url_helpers
- include Spree::ImageMethods # legacy, will be removed in Spree 6
include Spree::Metafields
include Spree::Metadata
@@ -135,22 +134,6 @@ module Spree
'media'
end
- # @deprecated
- def styles
- Spree::Deprecation.warn("Asset#styles is deprecated and will be removed in Spree 6.0. Please use active storage variants with cdn_image_url")
-
- self.class.styles.map do |_, size|
- width, height = size.chop.split('x').map(&:to_i)
-
- {
- url: generate_url(size: size),
- size: size,
- width: width,
- height: height
- }
- end
- end
-
private
def touch_product_variants
diff --git a/spree/core/app/models/spree/category.rb b/spree/core/app/models/spree/category.rb
index e9f8d58069..b57a794177 100644
--- a/spree/core/app/models/spree/category.rb
+++ b/spree/core/app/models/spree/category.rb
@@ -112,20 +112,6 @@ module Spree
taxonomy_ids = Spree::Taxonomy.where(store_id: store_ids).select(:id)
where(store_id: store_ids).or(where(store_id: nil, taxonomy_id: taxonomy_ids))
}
- scope :for_taxonomy, lambda { |taxonomy_name|
- Spree::Deprecation.warn('Spree::Category.for_taxonomy is deprecated and will be removed in Spree 6. Please use for_store instead.')
-
- if Spree.use_translations?
- joins(:taxonomy)
- .join_translation_table(Taxonomy)
- .where(
- Taxonomy.arel_table_alias[:name].lower.matches(taxonomy_name.downcase.strip)
- )
- else
- joins(:taxonomy).where(Spree::Taxonomy.arel_table[:name].lower.matches(taxonomy_name.downcase.strip))
- end
- }
-
#
# Search
#
@@ -452,11 +438,6 @@ module Spree
self.taxonomy = parent.taxonomy if parent.present? && taxonomy.blank?
end
- def set_store
- Spree::Deprecation.warn('Spree::Category#set_store is deprecated and will be removed in Spree 6.0. ensure_store instead.')
- ensure_store
- end
-
# Every category is store-owned. Resolve the store from the taxonomy, then the
# parent, finally the current store — so the direct column is always
# populated for new records. Guards on the raw +store_id+ column rather than
diff --git a/spree/core/app/models/spree/image/configuration/active_storage.rb b/spree/core/app/models/spree/image/configuration/active_storage.rb
deleted file mode 100644
index d044c98a22..0000000000
--- a/spree/core/app/models/spree/image/configuration/active_storage.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# @deprecated This module is now a no-op. All logic has been moved to Spree::Asset.
-# Will be removed in Spree 6.0.
-module Spree
- class Image < Asset
- module Configuration
- module ActiveStorage
- extend ActiveSupport::Concern
- end
- end
- end
-end
diff --git a/spree/core/app/models/spree/line_item.rb b/spree/core/app/models/spree/line_item.rb
index 6b622c9c64..f953facc83 100644
--- a/spree/core/app/models/spree/line_item.rb
+++ b/spree/core/app/models/spree/line_item.rb
@@ -334,7 +334,7 @@ module Spree
self.price = (variant.price_in(currency).amount || 0) +
variant.price_modifier_amount_in(currency, opts)
else
- self.price = variant.price +
+ self.price = (variant.price_in(self.currency).amount || 0) +
variant.price_modifier_amount(opts)
end
end
diff --git a/spree/core/app/models/spree/option_type.rb b/spree/core/app/models/spree/option_type.rb
index 8604b5b671..642aca1af1 100644
--- a/spree/core/app/models/spree/option_type.rb
+++ b/spree/core/app/models/spree/option_type.rb
@@ -86,13 +86,6 @@ module Spree
kind == 'color_swatch'
end
- def color?
- Spree::Deprecation.warn(
- 'Spree::OptionType#color? is deprecated. Use #color_swatch? instead. Will be removed in Spree 6.0.'
- )
- color_swatch?
- end
-
# Syncs option values from an array of hashes by mutating the in-memory
# `option_values` association — built/assigned children get persisted by
# `autosave: true` when the parent saves, and absent IDs get destroyed
diff --git a/spree/core/app/models/spree/order_routing/strategy/legacy.rb b/spree/core/app/models/spree/order_routing/strategy/legacy.rb
deleted file mode 100644
index d672b2d8ef..0000000000
--- a/spree/core/app/models/spree/order_routing/strategy/legacy.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-module Spree
- module OrderRouting
- module Strategy
- # Pre-5.5 routing behavior. Delegates to Spree::Stock::Coordinator,
- # which packs every active stock location and lets Prioritizer's
- # Adjuster distribute units across the resulting packages — no rules
- # consulted, no merchant-driven preferences, location order is
- # whatever the database returns.
- #
- # Provided as an opt-in escape hatch for merchants upgrading from 5.4
- # who are not ready to adopt rules-based routing. Configure via:
- #
- # store.update!(preferred_order_routing_strategy: 'Spree::OrderRouting::Strategy::Legacy')
- #
- # Spree 6.0 drops this strategy along with the underlying Coordinator.
- # See docs/plans/6.0-order-routing.md.
- class Legacy < Base
- def for_allocation
- Spree::Stock::Coordinator.new(order).packages
- end
-
- # Stock decrement / restock today happens via Spree::Shipment's state
- # machine (after_ship / after_cancel). The strategy hooks below are
- # part of the contract for the future reservation + typed-movement
- # phase. In 5.5 they are no-ops; existing model callbacks already do
- # the right thing.
- def for_sale(fulfillment:); end
- def for_release; end
- def for_cancellation; end
- end
- end
- end
-end
diff --git a/spree/core/app/models/spree/product.rb b/spree/core/app/models/spree/product.rb
index b933348eb7..b48c41783d 100644
--- a/spree/core/app/models/spree/product.rb
+++ b/spree/core/app/models/spree/product.rb
@@ -331,15 +331,16 @@ module Spree
# demand, so `product.sku = ...` still works before the product is persisted.
[
:sku, :barcode, :weight, :height, :width, :depth, :dimensions_unit, :weight_unit,
- :price, :price_in, :amount_in, :compare_at_price, :compare_at_amount_in,
- :currency, :cost_currency, :cost_price, :track_inventory
+ :price_in, :amount_in, :compare_at_amount_in,
+ :cost_currency, :cost_price, :track_inventory
].each do |method_name|
delegate method_name, to: :default_variant, allow_nil: true
delegate :"#{method_name}=", to: :find_or_build_default_variant
end
- delegate :display_amount, :display_price, :has_default_price?, :track_inventory?,
- :display_compare_at_price, :images, to: :default_variant, allow_nil: true
+ # Read-only delegations: these have no product-level writer. Prices are
+ # written per currency through the default variant's +set_price+.
+ delegate :compare_at_price, :track_inventory?, :images, to: :default_variant, allow_nil: true
state_machine :status, initial: :draft do
event :activate do
@@ -439,24 +440,6 @@ module Spree
@variant_for_images ||= find_variant_for_images
end
- # @deprecated Use #primary_media instead.
- def default_image
- Spree::Deprecation.warn('Spree::Product#default_image is deprecated and will be removed in Spree 6.0. Please use Spree::Product#primary_media instead.')
- primary_media
- end
-
- # @deprecated Use #primary_media instead.
- def featured_image
- Spree::Deprecation.warn('Spree::Product#featured_image is deprecated and will be removed in Spree 6.0. Please use Spree::Product#primary_media instead.')
- primary_media
- end
-
- # @deprecated Use #primary_media instead.
- def primary_image
- Spree::Deprecation.warn('Spree::Product#primary_image is deprecated and will be removed in Spree 6.0. Please use Spree::Product#primary_media instead.')
- primary_media
- end
-
# Returns secondary media for Product (for hover effects).
# @return [Spree::Asset, nil]
def secondary_image
@@ -577,13 +560,6 @@ module Spree
variants.any?(&:backordered?)
end
- def self.like_any(fields, values)
- conditions = fields.product(values).map do |(field, value)|
- arel_table[field].matches("%#{value}%")
- end
- where conditions.inject(:or)
- end
-
# Suitable for displaying only variants that has at least one option value.
# There may be scenarios where an option type is removed and along with it
# all option values. At that point all variants associated with only those
@@ -931,7 +907,6 @@ module Spree
end
def discontinue_on_must_be_later_than_make_active_at
- Spree::Deprecation.warn('Spree::Product#discontinue_on_must_be_later_than_make_active_at is deprecated and will be removed in Spree 6.0.')
if discontinue_on < make_active_at
errors.add(:discontinue_on, :invalid_date_range)
end
diff --git a/spree/core/app/models/spree/store.rb b/spree/core/app/models/spree/store.rb
index 683e471744..6dc85312b3 100644
--- a/spree/core/app/models/spree/store.rb
+++ b/spree/core/app/models/spree/store.rb
@@ -197,18 +197,9 @@ module Spree
Spree::Current.store
end
- # @deprecated The or_initialize behavior will be removed in Spree 5.5.
+ # @return [Spree::Store, nil] the store flagged as default, if one exists
def self.default
- # workaround for Mobility bug with first_or_initialize
- if where(default: true).any?
- where(default: true).first
- else
- Spree::Deprecation.warn(
- 'Spree::Store.default returning a new unpersisted store when no default store exists is deprecated ' \
- 'and will be removed in Spree 6.0. Please ensure a default store is created before calling Store.default.'
- )
- new(default: true)
- end
+ where(default: true).first
end
def self.available_locales
@@ -334,21 +325,6 @@ module Spree
country.states.to_a
end
- # @deprecated Use {Spree::Zone.all} or {#countries_with_shipping_coverage} instead.
- # Will be removed in Spree 5.5.
- def supported_shipping_zones
- Spree::Deprecation.warn(
- 'Store#supported_shipping_zones is deprecated and will be removed in Spree 5.5. ' \
- 'Use Spree::Zone.all or Store#countries_with_shipping_coverage instead.'
- )
- zone = Spree::Zone.find_by(id: read_attribute(:checkout_zone_id))
- if zone.present?
- [zone]
- else
- Spree::Zone.includes(zone_members: :zoneable).all
- end
- end
-
# Returns countries covered by delivery methods. Methods without delivery
# zones are worldwide, so any such method means every country is covered;
# otherwise coverage is the union of the attached zones' country, state,
@@ -382,12 +358,6 @@ module Spree
end
end
- def admin_users
- Spree::Deprecation.warn('Store#admin_users is deprecated and will be removed in Spree 5.5. Please use Store#users instead.')
-
- users
- end
-
def metric_unit_system?
preferred_unit_system == 'metric'
end
diff --git a/spree/core/app/models/spree/variant.rb b/spree/core/app/models/spree/variant.rb
index 4c0d1db17a..2b844eae08 100644
--- a/spree/core/app/models/spree/variant.rb
+++ b/spree/core/app/models/spree/variant.rb
@@ -30,9 +30,6 @@ module Spree
before_destroy :ensure_not_in_complete_orders
after_destroy :remove_line_items_from_incomplete_orders
- # must include this after ensure_not_in_complete_orders to make sure price won't be deleted before validation
- include Spree::DefaultPrice
-
with_options inverse_of: :variant do
has_many :fulfillment_items, class_name: 'Spree::FulfillmentItem'
has_many :line_items
@@ -75,11 +72,7 @@ module Spree
before_validation :set_cost_currency
before_validation :apply_pending_options, if: :pending_options?
- validate :check_price, if: -> { Spree::Config.enable_legacy_default_price }
-
validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
- validates :price, numericality: { greater_than_or_equal_to: 0, allow_nil: true },
- if: -> { Spree::Config.enable_legacy_default_price }
validates :sku, uniqueness: { conditions: -> { where(deleted_at: nil) }, case_sensitive: false, scope: spree_base_uniqueness_scope },
allow_blank: true, unless: :disable_sku_validation?
@@ -186,7 +179,7 @@ module Spree
allow_destroy: false
)
- self.whitelisted_ransackable_associations = %w[option_values product tax_category prices default_price]
+ self.whitelisted_ransackable_associations = %w[option_values product tax_category prices]
self.whitelisted_ransackable_attributes = %w[weight depth width height sku discontinue_on cost_price cost_currency track_inventory
deleted_at product_id]
self.whitelisted_ransackable_scopes = %i(product_name_or_sku_cont search_by_product_name_or_sku search)
@@ -324,12 +317,6 @@ module Spree
variant_media.exists?
end
- # @deprecated Use #primary_media instead.
- def default_image
- Spree::Deprecation.warn('Spree::Variant#default_image is deprecated and will be removed in Spree 6.0. Please use Spree::Variant#primary_media instead.')
- primary_media
- end
-
# Updates primary_media_id to the first media item by position.
# Called when media is added, removed, or reordered.
# Uses gallery_media so product-level assets linked via VariantMedia are
@@ -339,24 +326,16 @@ module Spree
update_column(:primary_media_id, first_media&.id)
end
- # Returns first Image for Variant.
- # @deprecated Use #primary_media instead.
- # @return [Spree::Image, nil]
- def primary_image
- Spree::Deprecation.warn('Spree::Variant#primary_image is deprecated and will be removed in Spree 6.0. Please use Spree::Variant#primary_media instead.')
- primary_media
- end
-
# Returns second Image for Variant (for hover effects).
# @return [Spree::Image, nil]
def secondary_image
images.second
end
- # Returns all images except the default image, combining variant and product images.
+ # Returns all images except the primary media, combining variant and product images.
# @return [Array<Spree::Image>]
def additional_images
- @additional_images ||= (images + product.images).uniq.reject { |image| image.id == default_image&.id }
+ @additional_images ||= (images + product.images).uniq.reject { |image| image.id == primary_media&.id }
end
# Returns an array of hashes with the option type name, value and presentation
@@ -740,26 +719,6 @@ module Spree
Spree::Stock::Quantifier.new(self)
end
- # Ensures a new variant takes the product's default variant price when price is not supplied
- def check_price
- return if prices.any?
-
- infer_price_from_default_variant_if_needed
- end
-
- def infer_price_from_default_variant_if_needed
- default_currency = Spree::Store.default.default_currency
- current_price = price_in(default_currency).amount
-
- if current_price.nil?
- return errors.add(:base, :no_default_variant_found_to_infer_price) unless product&.default_variant
-
- # The default variant may or may not have a price yet; use it when present.
- inferred_price = product.default_variant.price_in(default_currency).amount
- set_price(default_currency, inferred_price) if inferred_price.present?
- end
- end
-
def set_cost_currency
self.cost_currency = Spree::Store.default.default_currency if cost_currency.blank?
end
diff --git a/spree/core/app/presenters/spree/data_feeds/google_presenter.rb b/spree/core/app/presenters/spree/data_feeds/google_presenter.rb
index 2f6c1bc4af..67bf3fa2db 100644
--- a/spree/core/app/presenters/spree/data_feeds/google_presenter.rb
+++ b/spree/core/app/presenters/spree/data_feeds/google_presenter.rb
@@ -43,12 +43,20 @@ module Spree
def build_items(xml)
products.includes(:primary_media, public_metafields: :metafield_definition, variants: [:primary_media, option_values: :option_type]).find_each do |product|
- product.variants.active.each do |variant|
+ product.variants.active(feed_currency).each do |variant|
build_item(xml, product, variant)
end
end
end
+ # The feed quotes every item in the store's currency, so variants are
+ # both selected and priced against it — a variant's own +cost_currency+
+ # may differ and carry no price here.
+ # @return [String]
+ def feed_currency
+ store.default_currency
+ end
+
def build_item(xml, product, variant)
image_url = image_link(variant, product)
return if image_url.nil?
@@ -66,7 +74,7 @@ module Spree
xml['g'].description product.description || format_title(product, variant)
xml['g'].link "#{store.storefront_url}/products/#{product.slug}"
xml['g'].image_link image_url
- xml['g'].price "#{variant.price} #{variant.cost_currency}"
+ xml['g'].price "#{variant.amount_in(feed_currency)} #{feed_currency}"
xml['g'].availability availability(product)
xml['g'].availability_date product.available_on.xmlschema if product.available_on.present?
end
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index 11b0a3839d..f0e26a546d 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -395,7 +395,6 @@ en:
attributes:
base:
cannot_destroy_if_attached_to_line_items: Cannot delete Variants that are added to placed Orders. In such cases, please discontinue them.
- no_default_variant_found_to_infer_price: No default variant found to infer price
spree/webhook_endpoint:
attributes:
url:
diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rb
index 46d349cb29..4310eea92b 100644
--- a/spree/core/lib/spree/core.rb
+++ b/spree/core/lib/spree/core.rb
@@ -44,7 +44,7 @@ StateMachines::Machine.ignore_method_conflicts = true
module Spree
mattr_accessor :base_class, :customer_class, :admin_user_class,
:private_storage_service_name, :public_storage_service_name,
- :cdn_host, :root_domain, :searcher_class, :events_adapter_class, :queues,
+ :cdn_host, :root_domain, :events_adapter_class, :queues,
:google_places_api_key
def self.base_class(constantize: true)
@@ -139,16 +139,6 @@ module Spree
end
end
- # @deprecated Spree.searcher_class is deprecated and will be removed in Spree 5.5. Use Spree.search_provider instead.
- def self.searcher_class=(value)
- Spree::Deprecation.warn('Spree.searcher_class is deprecated and will be removed in Spree 5.5. Use Spree.search_provider instead.')
- @@searcher_class = value
- end
-
- def self.searcher_class(constantize: true)
- @@searcher_class
- end
-
# Search provider class name. Controls product search, filtering, and faceted navigation.
#
# Spree.search_provider = 'Spree::SearchProvider::Meilisearch'
diff --git a/spree/core/lib/spree/core/configuration.rb b/spree/core/lib/spree/core/configuration.rb
index 78b8e20591..a253b084fd 100644
--- a/spree/core/lib/spree/core/configuration.rb
+++ b/spree/core/lib/spree/core/configuration.rb
@@ -48,7 +48,6 @@ module Spree
preference :currency, :string, default: 'USD', deprecated: true
preference :credit_to_new_allocation, :boolean, default: false
preference :disable_migration_check, :boolean, default: false # when turned on disables the startup warning about missing engine migrations
- preference :enable_legacy_default_price, :boolean, default: false # when enabled, keeps the legacy DefaultPrice concern active (has_one :default_price, variant.price= delegation, check_price validation). Disable (default) to use set_price exclusively.
preference :disable_sku_validation, :boolean, default: false # when turned off disables the built-in SKU uniqueness validation
preference :disable_store_presence_validation, :boolean, default: false, deprecated: true # when turned off disables Store presence validation for Products and Payment Methods
preference :events_log_enabled, :boolean, default: true # Log all Spree events to Rails logger
diff --git a/spree/core/lib/spree/core/controller_helpers/order.rb b/spree/core/lib/spree/core/controller_helpers/order.rb
index 939fc1b336..eb379089b5 100644
--- a/spree/core/lib/spree/core/controller_helpers/order.rb
+++ b/spree/core/lib/spree/core/controller_helpers/order.rb
@@ -172,7 +172,6 @@ module Spree
{ stock_items: :stock_location },
{ product: :default_variant }
]
- variant_includes << :default_price if Spree::Config.enable_legacy_default_price
{
line_items: {
diff --git a/spree/core/lib/spree/core/engine.rb b/spree/core/lib/spree/core/engine.rb
index ab64245add..f4a2d7fde4 100644
--- a/spree/core/lib/spree/core/engine.rb
+++ b/spree/core/lib/spree/core/engine.rb
@@ -192,10 +192,9 @@ module Spree
# Selectable order routing strategies. The internal Reducer collaborator
# is intentionally NOT listed — it is not a Strategy::Base. Plugins add
- # their own (or remove Legacy) via this array.
+ # their own via this array.
Rails.application.config.spree.order_routing.strategies.concat [
- Spree::OrderRouting::Strategy::Rules,
- Spree::OrderRouting::Strategy::Legacy
+ Spree::OrderRouting::Strategy::Rules
]
# Available order routing rule kinds. STI dispatches at runtime via the
diff --git a/spree/core/lib/spree/permitted_attributes.rb b/spree/core/lib/spree/permitted_attributes.rb
index 90bc0a5055..6998bc61de 100644
--- a/spree/core/lib/spree/permitted_attributes.rb
+++ b/spree/core/lib/spree/permitted_attributes.rb
@@ -185,10 +185,10 @@ module Spree
@@product_attributes = [
:name, :description, :available_on, :make_active_at, :discontinue_on, :permalink, :meta_description,
- :meta_keywords, :meta_title, :price, :sku, :deleted_at,
+ :meta_keywords, :meta_title, :sku, :deleted_at,
:weight, :height, :width, :depth,
:shipping_category_id, :tax_category_id,
- :cost_currency, :cost_price, :compare_at_price,
+ :cost_currency, :cost_price,
:slug, :track_inventory, :backorderable, :barcode, :status,
:weight_unit, :dimensions_unit,
{
@@ -313,14 +313,13 @@ module Spree
@@variant_attributes = [
:name, :presentation, :cost_price, :discontinue_on, :lock_version,
:position, :track_inventory, :preorderable, :preorder_ships_at, :backorder_limit, :tax_category_id,
- :product_id, :product, :option_values_attributes, :price, :compare_at_price,
+ :product_id, :product, :option_values_attributes,
:weight, :height, :width, :depth, :sku, :barcode, :cost_currency,
:weight_unit, :dimensions_unit,
{
options: [:id, :name, :option_value_presentation, :option_value_name, :position, :_destroy],
stock_items_attributes: [:id, :count_on_hand, :stock_location_id, :backorderable, :_destroy],
prices_attributes: [:id, :amount, :compare_at_amount, :currency, :_destroy],
- price: {},
option_value_variants_attributes: [:id, :option_value_id, :_destroy],
option_value_ids: []
}
diff --git a/spree/core/spec/mailers/spree/base_mailer_spec.rb b/spree/core/spec/mailers/spree/base_mailer_spec.rb
index a6e348805e..1439494b65 100644
--- a/spree/core/spec/mailers/spree/base_mailer_spec.rb
+++ b/spree/core/spec/mailers/spree/base_mailer_spec.rb
@@ -15,28 +15,6 @@ end
describe Spree::BaseMailer, type: :mailer do
let!(:store) { @default_store }
- describe '#set_email_locale (deprecated)' do
- subject(:mailer) { described_class.new }
-
- before do
- store.update!(default_locale: 'de')
- allow(mailer).to receive(:current_store).and_return(store)
- end
- after { I18n.locale = :en }
-
- it 'emits a deprecation warning' do
- expect(Spree::Deprecation).to receive(:warn).with(/set_email_locale is deprecated/)
- mailer.set_email_locale
- end
-
- it 'still sets I18n.locale from the store default for backwards compatibility' do
- allow(Spree::Deprecation).to receive(:warn)
- I18n.locale = :en
- mailer.set_email_locale
- expect(I18n.locale).to eq(:de)
- end
- end
-
describe '#from_address' do
subject(:mailer) { described_class.new }
diff --git a/spree/core/spec/models/concerns/spree/default_price_spec.rb b/spree/core/spec/models/concerns/spree/default_price_spec.rb
deleted file mode 100644
index b28795a910..0000000000
--- a/spree/core/spec/models/concerns/spree/default_price_spec.rb
+++ /dev/null
@@ -1,138 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::DefaultPrice do
- let(:store) { Spree::Store.default }
- let(:product) { create(:product) }
- let(:variant) { product.default_variant }
-
- describe 'with enable_legacy_default_price disabled (default)' do
- before do
- allow(Spree::Config).to receive(:enable_legacy_default_price).and_return(false)
- end
-
- describe '#price' do
- it 'returns amount from price_in for the default currency' do
- variant.set_price('USD', 29.99)
- expect(variant.price).to eq(29.99)
- end
-
- it 'returns nil when no price exists for the default currency' do
- variant.prices.destroy_all
- expect(variant.price).to be_nil
- end
- end
-
- describe '#price=' do
- it 'sets price via set_price' do
- variant.price = 19.99
- expect(variant.price_in('USD').amount).to eq(19.99)
- end
- end
-
- describe '#currency' do
- it 'returns the default store currency' do
- expect(variant.currency).to eq(store.default_currency)
- end
- end
-
- describe '#display_price' do
- it 'returns display amount for the default currency' do
- variant.set_price('USD', 10.55)
- expect(variant.display_price.to_s).to eq('$10.55')
- end
- end
-
- describe '#has_default_price?' do
- it 'returns true when a base price exists in the default currency' do
- variant.set_price('USD', 10)
- expect(variant.has_default_price?).to be true
- end
-
- it 'returns false when no base price exists in the default currency' do
- variant.prices.destroy_all
- expect(variant.has_default_price?).to be false
- end
- end
-
- describe '#set_price' do
- it 'persists the price when variant is persisted' do
- variant.set_price('USD', 42.00)
- expect(variant.price_in('USD').amount).to eq(42.00)
- expect(variant.price_in('USD')).to be_persisted
- end
-
- it 'builds price in-memory when variant is not persisted' do
- new_variant = Spree::Variant.new(product: product)
- new_variant.set_price('USD', 15.00)
- price = new_variant.prices.detect { |p| p.currency == 'USD' }
- expect(price.amount).to eq(15.00)
- expect(price).not_to be_persisted
- end
-
- it 'supports multiple currencies' do
- variant.set_price('USD', 29.99)
- variant.set_price('EUR', 27.99)
- expect(variant.price_in('USD').amount).to eq(29.99)
- expect(variant.price_in('EUR').amount).to eq(27.99)
- end
- end
-
- describe 'variant save without price' do
- it 'allows saving a variant without any price' do
- new_product = create(:product)
- default_variant = new_product.default_variant
- default_variant.prices.destroy_all
- expect { default_variant.save! }.not_to raise_error
- end
- end
-
- describe 'save_default_price callback' do
- it 'does not run' do
- variant.set_price('USD', 50.00)
- expect(variant).not_to receive(:save_default_price)
- variant.save!
- end
- end
- end
-
- describe 'with enable_legacy_default_price enabled' do
- before do
- allow(Spree::Config).to receive(:enable_legacy_default_price).and_return(true)
- end
-
- describe '#price' do
- it 'returns price from the default price record' do
- expect(variant.price).to eq(variant.default_price.amount)
- end
- end
-
- describe '#price=' do
- it 'sets price on the default price record' do
- variant.price = 25.00
- expect(variant.default_price.amount).to eq(25.00)
- end
- end
-
- describe '#has_default_price?' do
- it 'returns true when default_price exists' do
- expect(variant.has_default_price?).to be true
- end
- end
-
- describe 'save_default_price callback' do
- it 'saves the default price when it has changed' do
- variant.reload
- variant.default_price.price = 99.99
- expect(variant.default_price).to receive(:save)
- variant.save!
- end
- end
-
- describe 'check_price validation' do
- it 'runs the check_price validation' do
- new_variant = build(:variant, product: product)
- expect(new_variant).to be_valid
- end
- end
- end
-end
diff --git a/spree/core/spec/models/concerns/spree/image_methods_spec.rb b/spree/core/spec/models/concerns/spree/image_methods_spec.rb
deleted file mode 100644
index c707f9a0c4..0000000000
--- a/spree/core/spec/models/concerns/spree/image_methods_spec.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-require 'spec_helper'
-
-
-describe Spree::ImageMethods do
- describe '#generate_url' do
- let(:variant) { create(:variant) }
- let(:image) { create(:image, viewable: variant) }
-
- before (:each) do
- allow(image).to receive(:cdn_image_url)
- end
-
- context 'when gravity is not set to centre' do
- let(:gravity) { 'north' }
-
- it 'attachment.variant should receive the unchanged value of gravity' do
- expect(image.attachment).to receive(:variant).with(resize_and_pad: [48, 48, gravity: 'north'], saver: anything)
- image.generate_url(size: '48x48', gravity: gravity)
- end
- end
-
- context 'when gravity is set to centre' do
- let(:image) { create(:image, viewable: variant) }
-
- it 'attachment.variant should receive "gravity: center" when image processing variant is nil' do
- allow(Rails.application.config.active_storage).to receive(:variant_processor).and_return(nil)
- expect(image.attachment).to receive(:variant).with(resize_and_pad: [48, 48, gravity: 'center'], saver: anything)
- image.generate_url(size: '48x48')
- end
-
- it 'should return center when image processing variant is mini magick' do
- allow(Rails.application.config.active_storage).to receive(:variant_processor).and_return(:mini_magick)
- expect(image.attachment).to receive(:variant).with(resize_and_pad: [48, 48, gravity: 'center'], saver: anything)
- image.generate_url(size: '48x48')
- end
-
- it 'should return centre when image processing variant is VIPS' do
- allow(Rails.application.config.active_storage).to receive(:variant_processor).and_return(:vips)
- expect(image.attachment).to receive(:variant).with(resize_and_pad: [48, 48, gravity: 'centre'], saver: anything)
- image.generate_url(size: '48x48')
- end
- end
- end
-end
diff --git a/spree/core/spec/models/spree/calculator/shipping/price_sack_spec.rb b/spree/core/spec/models/spree/calculator/shipping/price_sack_spec.rb
index b12ba8bca5..6d245d9ede 100644
--- a/spree/core/spec/models/spree/calculator/shipping/price_sack_spec.rb
+++ b/spree/core/spec/models/spree/calculator/shipping/price_sack_spec.rb
@@ -11,7 +11,7 @@ module Spree
calculator
end
- let(:line_item) { build(:line_item, variant: variant, price: variant.price) }
+ let(:line_item) { build(:line_item, variant: variant, price: variant.amount_in(variant.cost_currency)) }
let(:variant) { create(:variant, price: 2) }
let(:inventory_unit1) { }
diff --git a/spree/core/spec/models/spree/category_spec.rb b/spree/core/spec/models/spree/category_spec.rb
index 2be35c1a65..2fc14f850a 100644
--- a/spree/core/spec/models/spree/category_spec.rb
+++ b/spree/core/spec/models/spree/category_spec.rb
@@ -104,7 +104,7 @@ RSpec.describe Spree::Category, type: :model do
end
end
- describe 'store auto-resolution (#set_store)' do
+ describe 'store auto-resolution (#ensure_store)' do
it 'falls back to the current store when none is given' do
Spree::Current.store = store
category = described_class.create!(name: 'Kitchen')
diff --git a/spree/core/spec/models/spree/image_spec.rb b/spree/core/spec/models/spree/image_spec.rb
index f0acce9a28..6f8ae9e410 100644
--- a/spree/core/spec/models/spree/image_spec.rb
+++ b/spree/core/spec/models/spree/image_spec.rb
@@ -27,14 +27,6 @@ describe Spree::Image, type: :model do
end
end
- describe '#styles' do
- it 'will return all styles for the image' do
- spree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')
- spree_image.save!
- expect(spree_image.styles).to be_kind_of(Array)
- end
- end
-
context 'cache expiration' do
let!(:image) { create(:image, position: 1, viewable: viewable) }
let!(:image_2) { create(:image, position: 2, viewable: viewable) }
diff --git a/spree/core/spec/models/spree/option_type_spec.rb b/spree/core/spec/models/spree/option_type_spec.rb
index 65ea373b31..653fe7bc31 100644
--- a/spree/core/spec/models/spree/option_type_spec.rb
+++ b/spree/core/spec/models/spree/option_type_spec.rb
@@ -146,12 +146,6 @@ describe Spree::OptionType, type: :model do
end
end
- describe '#color?' do
- it 'is deprecated and delegates to color_swatch?' do
- expect(Spree::Deprecation).to receive(:warn).with(/deprecated/)
- expect(option_type.color?).to be true
- end
- end
end
context 'touching' do
diff --git a/spree/core/spec/models/spree/order_routing/strategy/base_spec.rb b/spree/core/spec/models/spree/order_routing/strategy/base_spec.rb
index 6b5af29766..f018c05bd0 100644
--- a/spree/core/spec/models/spree/order_routing/strategy/base_spec.rb
+++ b/spree/core/spec/models/spree/order_routing/strategy/base_spec.rb
@@ -3,10 +3,7 @@ require 'spec_helper'
RSpec.describe Spree::OrderRouting::Strategy::Base, type: :model do
describe 'Spree.order_routing.strategies' do
it 'includes the core strategies and excludes the internal Reducer collaborator' do
- expect(Spree.order_routing.strategies).to include(
- Spree::OrderRouting::Strategy::Rules,
- Spree::OrderRouting::Strategy::Legacy
- )
+ expect(Spree.order_routing.strategies).to include(Spree::OrderRouting::Strategy::Rules)
expect(Spree.order_routing.strategies).not_to include(Spree::OrderRouting::Strategy::Reducer)
end
end
diff --git a/spree/core/spec/models/spree/order_routing/strategy/legacy_spec.rb b/spree/core/spec/models/spree/order_routing/strategy/legacy_spec.rb
deleted file mode 100644
index f3e2445cb6..0000000000
--- a/spree/core/spec/models/spree/order_routing/strategy/legacy_spec.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require 'spec_helper'
-
-# Strategy::Legacy delegates to Spree::Stock::Coordinator and therefore
-# inherits its pre-routing behavior wholesale: every active location packed,
-# Prioritizer's Adjuster distributes units across packages, no merchant
-# routing rules consulted.
-RSpec.describe Spree::OrderRouting::Strategy::Legacy, type: :model do
- let(:store) { @default_store }
- let(:variant_a) { create(:variant) }
- let(:variant_b) { create(:variant) }
- let!(:nyc) { create(:stock_location, name: 'NYC', default: true) }
- let!(:la) { create(:stock_location, name: 'LA', default: false) }
-
- let(:order) do
- o = create(:order, store: store, ship_address: create(:ship_address))
- create(:line_item, order: o, variant: variant_a, quantity: 1)
- create(:line_item, order: o, variant: variant_b, quantity: 1)
- o.reload
- end
-
- subject { described_class.new(order: order) }
-
- it 'splits the allocation across both locations when neither single one covers the cart' do
- nyc.stock_item_or_create(variant_a).update!(count_on_hand: 10)
- la.stock_item_or_create(variant_b).update!(count_on_hand: 10)
-
- packages = subject.for_allocation
- location_ids = packages.map { |p| p.stock_location.id }
-
- expect(location_ids).to contain_exactly(nyc.id, la.id)
- expect(packages.flat_map(&:on_hand).size).to eq(2)
- expect(packages.flat_map(&:backordered)).to be_empty
- end
-
- it 'ignores OrderRoutingRule rows entirely' do
- # PreferredLocation rule would normally make `la` the winner; Legacy
- # should not consult it.
- Spree::OrderRouting::Rules::PreferredLocation
- .where(channel: order.channel).destroy_all
- Spree::OrderRouting::Rules::PreferredLocation.create!(
- store: store, channel: order.channel, position: 0
- )
- order.update!(preferred_stock_location: la)
-
- nyc.stock_item_or_create(variant_a).update!(count_on_hand: 10)
- nyc.stock_item_or_create(variant_b).update!(count_on_hand: 10)
- la.stock_item_or_create(variant_a).update!(count_on_hand: 10)
- la.stock_item_or_create(variant_b).update!(count_on_hand: 10)
-
- expect_any_instance_of(Spree::OrderRoutingRule).not_to receive(:rank)
- subject.for_allocation
- end
-
- describe 'lifecycle hooks' do
- it 'for_sale, for_release, for_cancellation are no-ops' do
- expect { subject.for_sale(fulfillment: nil) }.not_to raise_error
- expect { subject.for_release }.not_to raise_error
- expect { subject.for_cancellation }.not_to raise_error
- end
- end
-end
diff --git a/spree/core/spec/models/spree/order_routing/strategy/parity_spec.rb b/spree/core/spec/models/spree/order_routing/strategy/parity_spec.rb
index 3c69b5b3db..6f89cb569d 100644
--- a/spree/core/spec/models/spree/order_routing/strategy/parity_spec.rb
+++ b/spree/core/spec/models/spree/order_routing/strategy/parity_spec.rb
@@ -1,10 +1,8 @@
require 'spec_helper'
-# Strategy::Rules must match Strategy::Legacy (= Spree::Stock::Coordinator)
-# on every routing-relevant scenario the legacy pipeline supported. This
-# file runs the same shared examples against both strategies; failures
-# under Rules are regressions vs. pre-5.5 behavior. Failures under Legacy
-# mean the expectation itself is wrong.
+# Strategy::Rules must preserve Spree::Stock::Coordinator behavior on every
+# routing-relevant scenario the pre-5.5 pipeline supported. Failures here are
+# regressions against that baseline.
RSpec.describe 'OrderRouting strategy parity', type: :model do
let(:store) { @default_store }
@@ -646,11 +644,6 @@ RSpec.describe 'OrderRouting strategy parity', type: :model do
end
end
- describe Spree::OrderRouting::Strategy::Legacy do
- let(:strategy_class) { described_class }
- it_behaves_like 'a routing strategy preserving Coordinator behavior'
- end
-
describe Spree::OrderRouting::Strategy::Rules do
let(:strategy_class) { described_class }
it_behaves_like 'a routing strategy preserving Coordinator behavior'
diff --git a/spree/core/spec/models/spree/price_history_spec.rb b/spree/core/spec/models/spree/price_history_spec.rb
index 0c0aef1405..780dc697b6 100644
--- a/spree/core/spec/models/spree/price_history_spec.rb
+++ b/spree/core/spec/models/spree/price_history_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Spree::PriceHistory, type: :model do
describe 'scopes' do
let(:variant) { create(:variant) }
- let(:price) { variant.default_price }
+ let(:price) { variant.price_in(variant.cost_currency) }
before do
# Materialize lets, then clear history created by variant/price setup
diff --git a/spree/core/spec/models/spree/price_spec.rb b/spree/core/spec/models/spree/price_spec.rb
index 2abac2166c..309384a699 100644
--- a/spree/core/spec/models/spree/price_spec.rb
+++ b/spree/core/spec/models/spree/price_spec.rb
@@ -389,7 +389,7 @@ describe Spree::Price, type: :model do
describe '#record_price_history' do
let(:store) { create(:store) }
let(:variant) { create(:variant) }
- let(:price) { variant.default_price }
+ let(:price) { variant.price_in(variant.cost_currency) }
before do
# Materialize lets and clear history from setup
@@ -459,7 +459,7 @@ describe Spree::Price, type: :model do
describe '#prior_price' do
let(:variant) { create(:variant) }
- let(:price) { variant.default_price }
+ let(:price) { variant.price_in(variant.cost_currency) }
before do
price
diff --git a/spree/core/spec/models/spree/product/scopes_spec.rb b/spree/core/spec/models/spree/product/scopes_spec.rb
index 954fd26a88..aa9c2655e7 100644
--- a/spree/core/spec/models/spree/product/scopes_spec.rb
+++ b/spree/core/spec/models/spree/product/scopes_spec.rb
@@ -501,30 +501,6 @@ describe 'Product scopes', type: :model do
let!(:product) { create(:product, option_types: [option_type]) }
let!(:variant) { create(:variant, product: product, option_values: [option_value]) }
- describe '.with_option' do
- subject(:with_option) { Spree::Product.method(:with_option) }
-
- it "finds by an option type's name" do
- expect(with_option.call(option_type.name).count).to eq(1)
- end
-
- it "doesn't find any option types with an unknown name" do
- expect(with_option.call('fake').count).to eq(0)
- end
-
- it 'finds by an option type' do
- expect(with_option.call(option_type).count).to eq(1)
- end
-
- it 'finds by an id' do
- expect(with_option.call(option_type.id).count).to eq(1)
- end
-
- it 'cannot find an option type with an unknown id' do
- expect(with_option.call(0).count).to eq(0)
- end
- end
-
describe '.with_option_value' do
subject(:with_option) { Spree::Product.method(:with_option_value) }
diff --git a/spree/core/spec/models/spree/product_spec.rb b/spree/core/spec/models/spree/product_spec.rb
index 0e63c0eae9..9718e68da4 100644
--- a/spree/core/spec/models/spree/product_spec.rb
+++ b/spree/core/spec/models/spree/product_spec.rb
@@ -190,19 +190,23 @@ describe Spree::Product, type: :model do
end
end
- describe '#price' do
- # Regression test for #1173
- it 'strips non-price characters' do
- product.price = '$10'
- expect(product.price).to eq(10.0)
+ describe '#compare_at_price' do
+ it 'delegates to the default variant' do
+ product.default_variant.set_price(product.default_variant.cost_currency, 10, 20)
+ expect(product.compare_at_price).to eq(20)
end
end
- describe '#display_price' do
- before { product.price = 10.55 }
+ describe '#price_in' do
+ # Regression test for #1173
+ it 'strips non-price characters' do
+ product.default_variant.set_price('USD', '$10')
+ expect(product.price_in('USD').amount).to eq(10.0)
+ end
it 'shows the amount' do
- expect(product.display_price.to_s).to eq('$10.55')
+ product.default_variant.set_price('USD', 10.55)
+ expect(product.price_in('USD').display_amount.to_s).to eq('$10.55')
end
context 'with currency set to JPY' do
@@ -211,7 +215,7 @@ describe Spree::Product, type: :model do
end
it 'displays the currency in yen' do
- expect(product.default_variant.price_in('JPY').display_amount.to_s).to eq('¥11')
+ expect(product.price_in('JPY').display_amount.to_s).to eq('¥11')
end
end
end
@@ -700,7 +704,7 @@ describe Spree::Product, type: :model do
it 'converges delegated setters onto a single in-memory variant' do
product = build(:empty_product)
product.sku = 'PENDING'
- product.price = 10
+ product.default_variant.set_price('USD', 10)
product.weight = 2
expect(product.variants.size).to eq(1)
@@ -1863,8 +1867,8 @@ describe Spree::Product, type: :model do
context 'with hash params' do
it 'creates new variants' do
product.variants = [
- { sku: 'V1', price: 10, options: [{ name: 'Size', value: 'S' }] },
- { sku: 'V2', price: 20, options: [{ name: 'Size', value: 'M' }] }
+ { sku: 'V1', prices: [{ amount: 10, currency: 'USD' }], options: [{ name: 'Size', value: 'S' }] },
+ { sku: 'V2', prices: [{ amount: 20, currency: 'USD' }], options: [{ name: 'Size', value: 'M' }] }
]
expect(product.variants.count).to eq(2)
@@ -1891,7 +1895,6 @@ describe Spree::Product, type: :model do
it 'defers creation on new records' do
new_product = Spree::Product.new(
name: 'Deferred',
- price: 10,
shipping_category: shipping_category,
store: store,
variants: [{ sku: 'DEF-1', options: [{ name: 'Color', value: 'Red' }] }]
@@ -1939,15 +1942,15 @@ describe Spree::Product, type: :model do
shipping_category: shipping_category,
store: store,
variants: [
- { sku: 'FV-1', price: 10, options: [{ name: 'Size', value: 'S' }] },
- { sku: 'FV-2', price: 20, options: [{ name: 'Size', value: 'M' }] }
+ { sku: 'FV-1', prices: [{ amount: 10, currency: 'USD' }], options: [{ name: 'Size', value: 'S' }] },
+ { sku: 'FV-2', prices: [{ amount: 20, currency: 'USD' }], options: [{ name: 'Size', value: 'M' }] }
]
)
new_product.save!
expect(new_product.variant_count).to eq(2)
expect(new_product.default_variant.sku).to eq('FV-1')
- expect(new_product.price).to be_present
+ expect(new_product.price_in('USD').amount).to be_present
end
it 'reflects an options-less default variant in default_variant and price' do
@@ -1955,13 +1958,13 @@ describe Spree::Product, type: :model do
name: 'Fresh Simple',
shipping_category: shipping_category,
store: store,
- variants: [{ sku: 'FS-1', price: 15, options: [] }]
+ variants: [{ sku: 'FS-1', prices: [{ amount: 15, currency: 'USD' }], options: [] }]
)
new_product.save!
expect(new_product.variant_count).to eq(1)
expect(new_product.default_variant.sku).to eq('FS-1')
- expect(new_product.price).to eq(15)
+ expect(new_product.price_in('USD').amount).to eq(15)
end
end
end
@@ -2049,7 +2052,6 @@ describe Spree::Product, type: :model do
it 'defers attachment until after the product is saved' do
new_product = Spree::Product.new(
name: 'Deferred Media',
- price: 10,
shipping_category: create(:shipping_category),
store: store,
media: [{ signed_id: blob.signed_id, alt: 'Pending', position: 1 }]
@@ -2091,7 +2093,6 @@ describe Spree::Product, type: :model do
it 'does not overwrite explicit tax_category_id' do
product = Spree::Product.new(
name: 'Test',
- price: 10,
shipping_category: create(:shipping_category),
store: store,
tax_category_id: custom_tc.id
@@ -2104,7 +2105,6 @@ describe Spree::Product, type: :model do
it 'assigns default when tax_category_id is not provided' do
product = Spree::Product.new(
name: 'Test',
- price: 10,
shipping_category: create(:shipping_category),
store: store
)
diff --git a/spree/core/spec/models/spree/store_spec.rb b/spree/core/spec/models/spree/store_spec.rb
index 9f7d073ddd..0f8782349a 100644
--- a/spree/core/spec/models/spree/store_spec.rb
+++ b/spree/core/spec/models/spree/store_spec.rb
@@ -352,13 +352,8 @@ describe Spree::Store, type: :model, without_global_store: true do
described_class.delete_all
end
- it 'builds a new default store' do
- expect(described_class.default.class).to eq(described_class)
- expect(described_class.default.default).to be(true)
- end
-
- it 'does not persist the original default store' do
- expect(described_class.default.persisted?).to eq(false)
+ it 'returns nil' do
+ expect(described_class.default).to be_nil
end
end
end
@@ -741,6 +736,12 @@ describe Spree::Store, type: :model, without_global_store: true do
end
describe '#default_stock_location' do
+ # A persisted store must be the current one: stock locations are
+ # store-scoped and resolve their store from Spree::Current.
+ subject { create(:store) }
+
+ before { Spree::Current.store = subject }
+
context 'with default stock location' do
let!(:default_stock_location) { create(:stock_location, default: true) }
@@ -835,27 +836,6 @@ describe Spree::Store, type: :model, without_global_store: true do
end
end
- describe '#supported_shipping_zones' do
- context 'with checkout zone set' do
- let!(:checkout_zone) { create(:zone) }
- let(:store) { create(:store) }
-
- before { store.update_column(:checkout_zone_id, checkout_zone.id) }
-
- it 'returns the checkout zone and emits deprecation warning' do
- expect(Spree::Deprecation).to receive(:warn).with(/supported_shipping_zones is deprecated/)
- expect(store.supported_shipping_zones).to eq([checkout_zone])
- end
- end
-
- context 'when checkout zone not set' do
- it 'returns all shipping zones and emits deprecation warning' do
- expect(Spree::Deprecation).to receive(:warn).with(/supported_shipping_zones is deprecated/)
- expect(subject.supported_shipping_zones).to eq(Spree::Zone.includes(zone_members: :zoneable).all)
- end
- end
- end
-
describe '#formatted_url' do
let(:store) { build(:store, code: 'mystore', url: 'mystore.mydomain.dev') }
diff --git a/spree/core/spec/models/spree/taxon_spec.rb b/spree/core/spec/models/spree/taxon_spec.rb
index 39aaac323d..f63c7da9ee 100644
--- a/spree/core/spec/models/spree/taxon_spec.rb
+++ b/spree/core/spec/models/spree/taxon_spec.rb
@@ -54,7 +54,7 @@ describe Spree::Category, type: :model do
end
end
- describe '#set_store' do
+ describe '#ensure_store' do
it 'derives store from the taxonomy on create' do
taxon = create(:taxon, taxonomy: taxonomy, parent: taxonomy.root)
expect(taxon.store_id).to eq(taxonomy.store_id)
@@ -86,44 +86,6 @@ describe Spree::Category, type: :model do
end
context 'Scopes' do
- describe '.for_taxonomy' do
- let!(:categories_taxonomy) { store.taxonomies.find_by(name: 'Categories') || create(:taxonomy, name: 'Categories') }
- let!(:root_category) { create(:taxon, taxonomy: categories_taxonomy) }
-
- context 'when translations are disabled' do
- it 'returns the correct taxon' do
- expect(described_class.for_taxonomy('Categories')).to contain_exactly(
- root_category,
- root_category.parent
- )
- end
- end
-
- context 'when translations are enabled' do
- before do
- taxonomy
-
- Spree::Config.always_use_translations = true
- I18n.locale = :de
-
- categories_taxonomy.name = "Kategorien"
- categories_taxonomy.save!
- end
-
- after do
- Spree::Config.always_use_translations = false
- I18n.locale = :en
- end
-
- it 'returns the correct taxon' do
- expect(described_class.for_taxonomy('Kategorien')).to contain_exactly(
- root_category,
- root_category.parent
- )
- end
- end
- end
-
describe '.with_matching_name' do
let!(:taxon1) { create(:taxon, name: 'shoes', taxonomy: taxonomy) }
let!(:taxon2) { create(:taxon, name: 'Premium Shoes', taxonomy: taxonomy) }
diff --git a/spree/core/spec/models/spree/variant_spec.rb b/spree/core/spec/models/spree/variant_spec.rb
index 6576b38b52..cd27c3d8a1 100644
--- a/spree/core/spec/models/spree/variant_spec.rb
+++ b/spree/core/spec/models/spree/variant_spec.rb
@@ -4,7 +4,6 @@ describe Spree::Variant, type: :model do
let(:store) { @default_store }
let(:variant) { create(:variant, product: create(:base_product)) }
- it_behaves_like 'default_price'
it_behaves_like 'metadata'
it_behaves_like 'lifecycle events'
@@ -15,15 +14,13 @@ describe Spree::Variant, type: :model do
end
context 'validations' do
- it 'validates price is greater than 0' do
- allow(Spree::Config).to receive(:enable_legacy_default_price).and_return(true)
- variant.price = -1
- expect(variant).to be_invalid
+ it 'rejects a negative price' do
+ expect { variant.set_price(variant.cost_currency, -1) }.to raise_error(ActiveRecord::RecordInvalid)
end
- it 'validates price is 0' do
- variant.price = 0
- expect(variant).to be_valid
+ it 'allows a price of 0' do
+ variant.set_price(variant.cost_currency, 0)
+ expect(variant.price_in(variant.cost_currency).amount).to eq(0)
end
context 'SKU' do
@@ -534,10 +531,10 @@ describe Spree::Variant, type: :model do
end
end
- describe '#price=' do
- it 'uses LocalizedNumber.parse' do
- expect(Spree::LocalizedNumber).to receive(:parse).with('1,599.99')
- subject.price = '1,599.99'
+ 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)
end
end
@@ -548,16 +545,10 @@ describe Spree::Variant, type: :model do
end
end
- describe '#currency' do
- it 'returns the globally configured currency' do
- expect(variant.currency).to eql 'USD'
- end
- end
-
- describe '#display_amount' do
- it 'returns a Spree::Money' do
- variant.price = 21.22
- expect(variant.display_amount.to_s).to eql '$21.22'
+ describe '#price_in' do
+ it 'returns a price whose display amount is a Spree::Money' do
+ variant.set_price('USD', 21.22)
+ expect(variant.price_in('USD').display_amount.to_s).to eql '$21.22'
end
end
@@ -1134,8 +1125,8 @@ describe Spree::Variant, type: :model do
before { variant.destroy && variant.reload }
it 'has a price if deleted' do
- variant.price = 10
- expect(variant.price).to eq(10)
+ variant.set_price(variant.cost_currency, 10)
+ expect(variant.price_in(variant.cost_currency).amount).to eq(10)
end
end
@@ -1258,85 +1249,6 @@ describe Spree::Variant, type: :model do
end
end
- describe 'validate :check_price' do
- subject { variant.save }
-
- before do
- allow(Spree::Config).to receive(:enable_legacy_default_price).and_return(true)
- end
-
- let(:currency) { store.default_currency }
-
- context 'when variant has a price' do
- let(:variant) { build(:variant, :with_no_price, product: product) }
-
- let(:product) { create(:product, price: 11.11) }
-
- it 'keeps the existing price' do
- variant.set_price(currency, 12.34)
- expect(subject).to be(true)
- expect(variant.price_in(currency).amount).to eq(12.34)
- end
-
- context 'when variant has no price' do
- it 'infers price from the default variant' do
- expect(subject).to be(true)
- expect(variant.price_in(currency).amount).to eq(11.11)
- end
-
- context 'when there is no product' do
- let(:variant) { build(:variant, :with_no_price, product: nil) }
-
- it 'adds an error' do
- expect(subject).to be(false)
- expect(variant.errors[:base]).to contain_exactly(
- I18n.t('activerecord.errors.models.spree/variant.attributes.base.no_default_variant_found_to_infer_price')
- )
- end
- end
- end
- end
-
- context 'when variant has no default price' do
- let(:variant) { build(:variant, :with_no_price, product: product) }
-
- let(:product) { create(:product, price: 11.11) }
-
- it 'infers price from the default variant' do
- expect(subject).to be(true)
- expect(variant.price_in(currency).amount).to eq(11.11)
- end
-
- context 'when there is no default variant' do
- let(:product) { nil }
-
- it 'adds an error' do
- expect(subject).to be(false)
- expect(variant.errors[:base]).to contain_exactly(
- I18n.t('activerecord.errors.models.spree/variant.attributes.base.no_default_variant_found_to_infer_price')
- )
- end
- end
- end
-
- context 'when variant has prices' do
- let(:variant) { build(:variant, :with_no_price, prices: [price_1, price_2]) }
-
- let(:price_1) { build(:price, amount: 10, currency: 'PLN') }
- let(:price_2) { build(:price, amount: 11, currency: 'GBP') }
-
- it 'keeps the prices' do
- expect(subject).to be(true)
-
- expect(variant.prices.count).to eq(2)
- expect(variant.price_in('PLN').amount).to eq(10)
- expect(variant.price_in('GBP').amount).to eq(11)
- end
- end
-
- context 'when variant price '
- end
-
describe '#created_at' do
it 'creates variant with created_at timestamp' do
expect(variant.created_at).not_to be_nil
@@ -1416,15 +1328,6 @@ describe Spree::Variant, type: :model do
end
end
- describe '#primary_image' do
- let(:variant) { create(:variant) }
- let!(:image) { create(:image, position: 1, viewable: variant) }
-
- it 'returns the first image' do
- expect(variant.primary_image).to eq(image)
- end
- end
-
describe '#secondary_image' do
let(:variant) { create(:variant) }
let!(:image1) { create(:image, position: 1, viewable: variant) }
diff --git a/spree/core/spec/presenters/spree/data_feeds/google_presenter_spec.rb b/spree/core/spec/presenters/spree/data_feeds/google_presenter_spec.rb
index 565c6310e4..7e6f7b9c86 100644
--- a/spree/core/spec/presenters/spree/data_feeds/google_presenter_spec.rb
+++ b/spree/core/spec/presenters/spree/data_feeds/google_presenter_spec.rb
@@ -53,7 +53,22 @@ RSpec.describe Spree::DataFeeds::GooglePresenter do
end
it 'includes price' do
- expect(xml).to include("<g:price>#{variant.price} #{variant.cost_currency}</g:price>")
+ expect(xml).to include("<g:price>#{variant.amount_in(store.default_currency)} #{store.default_currency}</g:price>")
+ end
+
+ # The variant's own cost_currency is unrelated to the currency the feed
+ # quotes in, and may carry no price at all.
+ context "when the variant's cost_currency differs from the store currency" do
+ before { variant.update!(cost_currency: 'JPY') }
+
+ it 'quotes the price in the store currency' do
+ expect(xml).to include("<g:price>#{variant.amount_in(store.default_currency)} #{store.default_currency}</g:price>")
+ end
+
+ it 'emits no empty price' do
+ expect(xml).not_to include('<g:price> ')
+ expect(xml).not_to include('<g:price>JPY</g:price>')
+ end
end
end
diff --git a/spree/core/spec/services/spree/carts/upsert_items_spec.rb b/spree/core/spec/services/spree/carts/upsert_items_spec.rb
index 42bdf9fcf2..f5e41977fd 100644
--- a/spree/core/spec/services/spree/carts/upsert_items_spec.rb
+++ b/spree/core/spec/services/spree/carts/upsert_items_spec.rb
@@ -206,7 +206,7 @@ module Spree
it 'line item price matches variant price' do
expect(subject).to be_success
line_item = cart.items.find_by(variant: variant)
- expect(line_item.price).to eq(variant.price)
+ expect(line_item.price).to eq(variant.amount_in(cart.currency))
end
end
@@ -221,7 +221,7 @@ module Spree
it 'updates cart item_total' do
expect(subject).to be_success
cart.reload
- expected_total = (variant.price * 2) + variant2.price
+ expected_total = (variant.amount_in(cart.currency) * 2) + variant2.amount_in(cart.currency)
expect(cart.item_total).to eq(expected_total)
end
end
diff --git a/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb b/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb
index 1466156820..1113c9afe4 100644
--- a/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb
+++ b/spree/core/spec/services/spree/imports/row_processors/product_variant_spec.rb
@@ -227,7 +227,7 @@ RSpec.describe Spree::Imports::RowProcessors::ProductVariant, type: :service do
let!(:variant) { create(:variant, product: product, sku: 'DENIM-SHIRT-XS-BLUE', price: 50.99, option_values: [blue_option_value, xs_option_value]) }
it 'updates the variant' do
- expect { subject.process! }.to change { variant.reload.price }.from(50.99).to(62.99)
+ expect { subject.process! }.to change { variant.reload.amount_in(variant.cost_currency) }.from(50.99).to(62.99)
expect(variant.option_values.map(&:presentation).sort).to contain_exactly('Blue', 'XS')
end
diff --git a/spree/core/spec/services/spree/orders/update_spec.rb b/spree/core/spec/services/spree/orders/update_spec.rb
index 96407f0589..c92006a5fd 100644
--- a/spree/core/spec/services/spree/orders/update_spec.rb
+++ b/spree/core/spec/services/spree/orders/update_spec.rb
@@ -221,7 +221,7 @@ module Spree
order.reload
expect(order.line_items.first.quantity).to eq(2)
- expect(order.item_total).to eq(variant.price * 2)
+ expect(order.item_total).to eq(variant.amount_in(order.currency) * 2)
expect(order.total).to eq(order.item_total + order.shipment_total + order.adjustment_total)
end
end
diff --git a/spree/core/spec/support/concerns/default_price.rb b/spree/core/spec/support/concerns/default_price.rb
deleted file mode 100644
index b9e1a7d923..0000000000
--- a/spree/core/spec/support/concerns/default_price.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-shared_examples_for 'default_price' do
- subject(:instance) do
- obj = FactoryBot.create(model.name.demodulize.downcase.to_sym)
- obj.reload
- obj
- end
-
- let(:model) { described_class }
-
- before do
- allow(Spree::Config).to receive(:enable_legacy_default_price).and_return(true)
- end
-
- describe '.has_one :default_price' do
- let(:default_price_association) { model.reflect_on_association(:default_price) }
-
- it 'is a has one association' do
- expect(default_price_association.macro).to eq :has_one
- end
-
- it 'has a dependent destroy' do
- expect(default_price_association.options[:dependent]).to eq :destroy
- end
-
- it 'has the class name of Spree::Price' do
- expect(default_price_association.options[:class_name]).to eq 'Spree::Price'
- end
- end
-
- describe '#default_price' do
- it { expect(instance.default_price.class).to eql Spree::Price }
-
- it 'delegates price' do
- expect(instance.default_price).to receive(:price)
- instance.price
- end
-
- it 'delegates price_including_vat_for' do
- expect(instance.default_price).to receive(:price_including_vat_for).with({})
- instance.price_including_vat_for({})
- end
- end
-
- it { expect(instance.has_default_price?).to be_truthy }
-end