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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Remove continent-based markets from sample data (#14503)
Damian Legawiec6fcc01abe9cc
diff --git a/spree/core/app/services/spree/sample_data/loader.rb b/spree/core/app/services/spree/sample_data/loader.rbindex c97149d9e9..83457d5fe6 100644--- a/spree/core/app/services/spree/sample_data/loader.rb+++ b/spree/core/app/services/spree/sample_data/loader.rb@@ -14,9 +14,6 @@ module Spreeputs 'Loading sample configuration data...'load_configuration_data- puts 'Loading sample markets...'- load_ruby_file('markets')-puts 'Loading sample channels...'load_ruby_file('channels')diff --git a/spree/core/db/sample_data/markets.rb b/spree/core/db/sample_data/markets.rbdeleted file mode 100644index b5e533837b..0000000000--- a/spree/core/db/sample_data/markets.rb+++ /dev/null@@ -1,67 +0,0 @@-store = Spree::Store.default--# The default market says where the shop sells from — the merchant answered-# that at first-run setup, so sample data builds around it and never-# overwrites it. Resetting it here used to flip a store set up as German back-# to a US store on every `spree:load_sample_data`.-default_market = store.markets.default.first || store.markets.order(:position).first-home_isos = default_market&.country_codes.to_a--# Each market names its countries as ISO codes directly — the zone seeds these-# groupings used to come from are gone. Countries already assigned to another-# market in the store are skipped, because Spree::MarketCountry requires each-# country to belong to at most one market per store.-EU_ISOS = %w[PL FI PT RO DE FR SK HU SI IE AT ES IT BE SE LV BG LT CY LU MT DK NL EE HR CZ GR].freeze--eu_market = store.markets.find_or_initialize_by(name: 'Europe')--# Any market may already hold an EU country — the merchant's own default, or-# one they created themselves — and a country belongs to at most one market-# per store, so claiming it twice aborts the load.-eu_assigned_isos = Spree::MarketCountry.joins(:market).- where(spree_markets: { store_id: store.id, deleted_at: nil }).- then { |scope| eu_market.persisted? ? scope.where.not(market_id: eu_market.id) : scope }.- pluck(:country_code).to_set--eu_countries = (EU_ISOS - home_isos).filter_map { |iso| Spree::Country.by_iso(iso) }.- reject { |country| eu_assigned_isos.include?(country.iso) }--if eu_countries.any?- eu_market.currency = 'EUR'- eu_market.default_locale = 'de'- eu_market.supported_locales = 'de,fr,es,it'- eu_market.countries = eu_countries- eu_market.save!-end--[- { name: 'South America', isos: %w[AR BO BR CL CO EC FK GF GY PY PE SR UY VE],- currency: 'USD', default_locale: 'es', supported_locales: 'es,pt' },- { name: 'Middle East', isos: %w[BH EG IR IQ IL JO KW LB OM QA SA SY TR AE YE],- currency: 'USD', default_locale: 'en', supported_locales: 'en,ar' },- { name: 'Africa', isos: %w[DZ AO BJ BW BF BI CV CM CF TD KM CG CD CI DJ GQ ER SZ ET GA GM GH GN GW KE LS LR LY- MG MW ML MR MU YT MA MZ NA NE NG RE RW SH ST SN SC SL SO ZA SS SD TZ TG TN UG ZM ZW],- currency: 'USD', default_locale: 'en', supported_locales: 'en,fr,ar' },- { name: 'Asia', isos: %w[AF AM AZ BD BT BN KH CN CX CC GE HK IN ID JP KZ KG LA MO MY MV MN MM NP- KP PK PS PH SG KR LK TW TJ TH TM UZ VN],- currency: 'USD', default_locale: 'en', supported_locales: 'en' },- { name: 'Oceania', isos: %w[AU NZ PG FJ SB VU NC PF WS AS GU KI MH FM NR NU NF MP PW PN TK TO TV WF CK],- currency: 'AUD', default_locale: 'en', supported_locales: 'en' }-].each do |attrs|- market = store.markets.find_or_initialize_by(name: attrs[:name])-- assigned_scope = Spree::MarketCountry.joins(:market).- where(spree_markets: { store_id: store.id, deleted_at: nil })- assigned_scope = assigned_scope.where.not(market_id: market.id) if market.persisted?- assigned_isos = assigned_scope.pluck(:country_code).to_set-- countries = attrs[:isos].filter_map { |iso| Spree::Country.by_iso(iso) }.- reject { |country| assigned_isos.include?(country.iso) }- next if countries.empty?-- market.currency = attrs[:currency]- market.default_locale = attrs[:default_locale]- market.supported_locales = attrs[:supported_locales]- market.countries = countries- market.save!-enddiff --git a/spree/core/spec/services/spree/sample_data/loader_spec.rb b/spree/core/spec/services/spree/sample_data/loader_spec.rbindex 5a8e793389..8e7ead6cf1 100644--- a/spree/core/spec/services/spree/sample_data/loader_spec.rb+++ b/spree/core/spec/services/spree/sample_data/loader_spec.rb@@ -152,10 +152,11 @@ RSpec.describe Spree::SampleData::Loader, type: :service, without_global_store:expect(price_list.prices.where(currency: currency).pluck(:variant_id)).to match_array(eligible_variant_ids)end- wholesale_price = price_list.prices.where(currency: 'EUR').where.not(amount: nil).first+ wholesale_price = price_list.prices.where.not(amount: nil).firstexpect(wholesale_price).to be_present- base_price = Spree::Price.find_by(price_list_id: nil, variant_id: wholesale_price.variant_id, currency: 'EUR')+ base_price = Spree::Price.find_by(price_list_id: nil, variant_id: wholesale_price.variant_id,+ currency: wholesale_price.currency)expect(wholesale_price.amount).to eq((base_price.amount * 0.6).round(2))end