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
Add multi-currency support for Product Import/Export (#13872)
Damian Legawiecdd19fc1b6f0e
diff --git a/spree/core/app/models/spree/product.rb b/spree/core/app/models/spree/product.rbindex f262b419cb..295e9762b7 100644--- a/spree/core/app/models/spree/product.rb+++ b/spree/core/app/models/spree/product.rb@@ -604,14 +604,24 @@ module Spreetaxons_for_csv.fill(nil, taxons_for_csv.size...3)csv_lines = []+ all_variants = has_variants? ? variants_including_master.to_a : [master]+ default_currency = store.default_currency+ additional_currencies = store.supported_currencies_list.map(&:iso_code) - [default_currency]++ # Primary rows in the store's default currency+ all_variants.each_with_index do |variant, index|+ csv_lines << Spree::CSV::ProductVariantPresenter.new(self, variant, index, properties_for_csv, taxons_for_csv, store,+ metafields_for_csv).call+ end- if has_variants?- variants_including_master.each_with_index do |variant, index|- csv_lines << Spree::CSV::ProductVariantPresenter.new(self, variant, index, properties_for_csv, taxons_for_csv, store,- metafields_for_csv).call+ # Price-only rows for each additional currency+ additional_currencies.each do |currency|+ all_variants.each do |variant|+ next unless variant.amount_in(currency)++ csv_lines << Spree::CSV::ProductVariantPresenter.new(self, variant, 0, [], [], store,+ [], currency).callend- else- csv_lines << Spree::CSV::ProductVariantPresenter.new(self, master, 0, properties_for_csv, taxons_for_csv, store, metafields_for_csv).callendcsv_linesdiff --git a/spree/core/app/presenters/spree/csv/product_variant_presenter.rb b/spree/core/app/presenters/spree/csv/product_variant_presenter.rbindex 863a078dd8..cc68bd23c9 100644--- a/spree/core/app/presenters/spree/csv/product_variant_presenter.rb+++ b/spree/core/app/presenters/spree/csv/product_variant_presenter.rb@@ -47,18 +47,19 @@ module Spree'category3',].freeze- def initialize(product, variant, index = 0, properties = [], taxons = [], store = nil, metafields = [])+ def initialize(product, variant, index = 0, properties = [], taxons = [], store = nil, metafields = [], currency = nil)@product = product@variant = variant@index = index@properties = properties@taxons = taxons@store = store || product.stores.first- @currency = @store.default_currency+ @currency = currency || @store.default_currency+ @price_only = @currency != @store.default_currency@metafields = metafieldsend- attr_accessor :product, :variant, :index, :properties, :taxons, :store, :currency, :metafields+ attr_accessor :product, :variant, :index, :properties, :taxons, :store, :currency, :price_only, :metafields### Generates an array representing a CSV row of product variant data.@@ -72,6 +73,8 @@ module Spree## @return [Array] An array containing the combined product and variant CSV data.def call+ return price_only_row if price_only+total_on_hand = variant.total_on_handcsv = [@@ -134,6 +137,16 @@ module Spreeprivate+ def price_only_row+ csv = Array.new(CSV_HEADERS.size)+ csv[CSV_HEADERS.index('sku')] = variant.sku+ csv[CSV_HEADERS.index('slug')] = product.slug+ csv[CSV_HEADERS.index('price')] = variant.amount_in(currency)&.to_f+ csv[CSV_HEADERS.index('compare_at_price')] = variant.compare_at_amount_in(currency)&.to_f+ csv[CSV_HEADERS.index('currency')] = currency+ csv+ end+def image_url_options{ variant: :xlarge }enddiff --git a/spree/core/app/services/spree/imports/row_processors/product_variant.rb b/spree/core/app/services/spree/imports/row_processors/product_variant.rbindex e37c9f4d76..a908f8bd44 100644--- a/spree/core/app/services/spree/imports/row_processors/product_variant.rb+++ b/spree/core/app/services/spree/imports/row_processors/product_variant.rb@@ -32,7 +32,7 @@ module Spreevariant.width = attributes['width'] if attributes['width'].present?variant.depth = attributes['depth'] if attributes['depth'].present?variant.track_inventory = attributes['track_inventory'] if attributes['track_inventory'].present?- variant.option_value_variants = prepare_option_value_variants+ variant.option_value_variants = prepare_option_value_variants if options.any?if attributes['tax_category'].present?tax_category = prepare_tax_category@@ -68,7 +68,7 @@ module Spreeproduct = assign_attributes_to_product(product)product.save!- handle_metafields(product)+ handle_metafields(product) if has_product_attributes?productelse# For non-master variants, only look up the product@@ -105,7 +105,11 @@ module Spreeshipping_category = prepare_shipping_categoryproduct.shipping_category = shipping_category if shipping_category.present?end- product.taxons = prepare_taxons++ taxons = prepare_taxons+ # Full product rows (with name/status/description) clear taxons when categories are blank.+ # Price-only rows (no product attributes) never touch taxons.+ product.taxons = taxons if taxons.any? || has_product_attributes?endproduct@@ -197,6 +201,10 @@ module Spreeendend+ def has_product_attributes?+ %w[name status description category1 category2 category3].any? { |key| attributes[key].present? }+ end+def handle_metafields(product)return unless product.class.included_modules.include?(Spree::Metafields)diff --git a/spree/core/app/services/spree/sample_data/loader.rb b/spree/core/app/services/spree/sample_data/loader.rbindex c3e438da3f..e3230deeae 100644--- a/spree/core/app/services/spree/sample_data/loader.rb+++ b/spree/core/app/services/spree/sample_data/loader.rb@@ -12,6 +12,9 @@ module Spreeputs 'Loading sample configuration data...'load_configuration_data+ puts 'Loading sample markets...'+ load_ruby_file('markets')+puts 'Loading sample metafield definitions...'load_ruby_file('metafield_definitions')diff --git a/spree/core/db/sample_data/markets.rb b/spree/core/db/sample_data/markets.rbnew file mode 100644index 0000000000..fb88cc5138--- /dev/null+++ b/spree/core/db/sample_data/markets.rb@@ -0,0 +1,30 @@+store = Spree::Store.default++us = Spree::Country.find_by(iso: 'US')+ca = Spree::Country.find_by(iso: 'CA')++if us+ # Store auto-creates a default market on creation — update it rather than creating a new one+ us_market = store.markets.default.first || store.markets.order(:position).first || store.markets.new+ us_market.name = 'US'+ us_market.currency = 'USD'+ us_market.default_locale = 'en'+ us_market.default = true+ us_market.countries = [us, ca].compact+ us_market.save!+end++eu_zone = Spree::Zone.find_by(name: 'EU_VAT')++if eu_zone+ eu_countries = eu_zone.zone_members.where(zoneable_type: 'Spree::Country').map(&:zoneable)++ if eu_countries.any?+ eu_market = store.markets.find_or_initialize_by(name: 'Europe')+ 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+enddiff --git a/spree/core/db/sample_data/products.csv b/spree/core/db/sample_data/products.csvindex bb191ebc2f..de7d0f7bd7 100644--- a/spree/core/db/sample_data/products.csv+++ b/spree/core/db/sample_data/products.csv@@ -122,4 +122,91 @@ rotary-shaver-5000,ROTARY-SHAVER-5000-BLACK,,129.99,0,USD,,,,,,,,,,Color,Black,,rotary-shaver-5000,ROTARY-SHAVER-5000-DARK-BLUE,,129.99,0,USD,,,,,,,,,,Color,Dark Blue,,,https://raw.githubusercontent.com/spree/spree/main/docs/images/demo-images/rotary-shaver-5000-dark-blue.webp,2.8,5.5,2.4,in,0.7,lb,,,5000,TRUE,TRUE,,,,,,,,rotary-shaver-9000,ROTARY-SHAVER-9000,Rotary Shaver 9000,0,0,USD,active,"Premium rotary shaver with nano-precision blades, skin comfort sensor, 90-minute runtime, wireless charging pad, and cleaning station. Ultra-close shave with zero irritation.",Rotary Shaver 9000 | Spree Commerce Demo,"Browse the Rotary Shaver 9000 on the Spree Commerce demo store. Nano-precision blades, 90-min runtime, wireless charging & cleaning station included.","rotary shaver 9000, premium electric shaver, wireless charging shaver, nano-precision shaver, spree commerce demo, ecommerce example","electric shaver, rotary, personal care, premium, wireless charging",Default,Default,Personal Care -> Electric Shavers,,,,,https://raw.githubusercontent.com/spree/spree/main/docs/images/demo-images/rotary-shaver-9000.webp,,,,in,,lb,,,,,,5W,5V USB-C,3 Years,,90 minutes,,,rotary-shaver-9000,ROTARY-SHAVER-9000-CHROME,,299.99,0,USD,,,,,,,,,,Color,Chrome,,,https://raw.githubusercontent.com/spree/spree/main/docs/images/demo-images/rotary-shaver-9000-chrome.webp,2.8,5.9,2.4,in,0.8,lb,,,5000,TRUE,TRUE,,,,,,,,-rotary-shaver-9000,ROTARY-SHAVER-9000-MATTE-BLACK,,299.99,0,USD,,,,,,,,,,Color,Matte Black,,,https://raw.githubusercontent.com/spree/spree/main/docs/images/demo-images/rotary-shaver-9000-matte-black.webp,2.8,5.9,2.4,in,0.8,lb,,,5000,TRUE,TRUE,,,,,,,,\ No newline at end of file+rotary-shaver-9000,ROTARY-SHAVER-9000-MATTE-BLACK,,299.99,0,USD,,,,,,,,,,Color,Matte Black,,,https://raw.githubusercontent.com/spree/spree/main/docs/images/demo-images/rotary-shaver-9000-matte-black.webp,2.8,5.9,2.4,in,0.8,lb,,,5000,TRUE,TRUE,,,,,,,,+automatic-espresso-machine,AUTOMATIC-ESPRESSO-MACHINE-MATTE-BLACK,,819.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+automatic-espresso-machine,AUTOMATIC-ESPRESSO-MACHINE-SILVER,,819.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+automatic-espresso-machine,AUTOMATIC-ESPRESSO-MACHINE-WHITE,,819.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+semi-automatic-espresso-machine,SEMI-AUTOMATIC-ESPRESSO-MACHINE-STAINLESS-STEEL,,509.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+semi-automatic-espresso-machine,SEMI-AUTOMATIC-ESPRESSO-MACHINE-MATTE-BLACK,,509.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+drip-coffee-maker,DRIP-COFFEE-MAKER-BLACK,,84.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+drip-coffee-maker,DRIP-COFFEE-MAKER-WHITE,,84.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+drip-coffee-maker,DRIP-COFFEE-MAKER-STEEL-GREY,,84.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+digital-air-fryer-4l,DIGITAL-AIR-FRYER-4L-MATTE-BLACK,,109.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+digital-air-fryer-4l,DIGITAL-AIR-FRYER-4L-WHITE,,109.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+digital-air-fryer-6l,DIGITAL-AIR-FRYER-6L-MATTE-BLACK,,169.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+digital-air-fryer-6l,DIGITAL-AIR-FRYER-6L-SILVER,,169.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+digital-air-fryer-6l,DIGITAL-AIR-FRYER-6L-WHITE,,169.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+dual-basket-air-fryer,DUAL-BASKET-AIR-FRYER-MATTE-BLACK,,229.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+dual-basket-air-fryer,DUAL-BASKET-AIR-FRYER-STAINLESS-STEEL,,229.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+high-speed-blender,HIGH-SPEED-BLENDER-STAINLESS-STEEL,,189.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+high-speed-blender,HIGH-SPEED-BLENDER-MATTE-BLACK,,189.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+high-speed-blender,HIGH-SPEED-BLENDER-WHITE,,189.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+personal-blender,PERSONAL-BLENDER-WHITE,,46.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+personal-blender,PERSONAL-BLENDER-MINT,,46.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+personal-blender,PERSONAL-BLENDER-GREY,,46.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+electric-kettle-1-7l,ELECTRIC-KETTLE-1-7L-WHITE,,41.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+electric-kettle-1-7l,ELECTRIC-KETTLE-1-7L-BLACK,,41.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+electric-kettle-1-7l,ELECTRIC-KETTLE-1-7L-STAINLESS-STEEL,,41.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+temperature-control-kettle,TEMPERATURE-CONTROL-KETTLE-STAINLESS-STEEL,,74.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+temperature-control-kettle,TEMPERATURE-CONTROL-KETTLE-MATTE-BLACK,,74.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+2-slice-toaster,2-SLICE-TOASTER-WHITE,,37.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+2-slice-toaster,2-SLICE-TOASTER-BLACK,,37.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+2-slice-toaster,2-SLICE-TOASTER-STAINLESS-STEEL,,37.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+4-slice-toaster,4-SLICE-TOASTER-WHITE,,59.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+4-slice-toaster,4-SLICE-TOASTER-BLACK,,59.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+4-slice-toaster,4-SLICE-TOASTER-STAINLESS-STEEL,,59.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+food-processor-3l,FOOD-PROCESSOR-3L-STAINLESS-STEEL,,139.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+food-processor-3l,FOOD-PROCESSOR-3L-WHITE,,139.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+air-purifier-compact,AIR-PURIFIER-COMPACT-WHITE,,139.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+air-purifier-compact,AIR-PURIFIER-COMPACT-BLACK,,139.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+air-purifier-tower,AIR-PURIFIER-TOWER-WHITE,,329.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+air-purifier-tower,AIR-PURIFIER-TOWER-BLACK,,329.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+air-purifier-tower,AIR-PURIFIER-TOWER-GREY,,329.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+air-purifier-pro,AIR-PURIFIER-PRO-WHITE,,509.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+air-purifier-pro,AIR-PURIFIER-PRO-MATTE-BLACK,,509.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+ultrasonic-humidifier-2l,ULTRASONIC-HUMIDIFIER-2L-WHITE,,64.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+ultrasonic-humidifier-2l,ULTRASONIC-HUMIDIFIER-2L-BLACK,,64.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+smart-humidifier-4l,SMART-HUMIDIFIER-4L-WHITE,,119.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+smart-humidifier-4l,SMART-HUMIDIFIER-4L-GREY,,119.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+tower-fan,TOWER-FAN-WHITE,,84.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+tower-fan,TOWER-FAN-BLACK,,84.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+pedestal-fan,PEDESTAL-FAN-WHITE,,54.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+pedestal-fan,PEDESTAL-FAN-BLACK,,54.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+steam-generator-iron,STEAM-GENERATOR-IRON-BLUE-AND-WHITE,,229.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+steam-generator-iron,STEAM-GENERATOR-IRON-PURPLE-AND-WHITE,,229.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+handheld-garment-steamer,HANDHELD-GARMENT-STEAMER-WHITE,,46.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+handheld-garment-steamer,HANDHELD-GARMENT-STEAMER-BLACK,,46.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+professional-garment-steamer,PROFESSIONAL-GARMENT-STEAMER-WHITE-AND-GREY,,95,119.99,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+professional-garment-steamer,PROFESSIONAL-GARMENT-STEAMER-BLACK,,95,119.99,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+steam-iron,STEAM-IRON-BLUE-AND-WHITE,,54.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+steam-iron,STEAM-IRON-GREY-AND-WHITE,,54.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+cordless-stick-vacuum-18v,CORDLESS-STICK-VACUUM-18V-GREY,,229.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+cordless-stick-vacuum-18v,CORDLESS-STICK-VACUUM-18V-WHITE,,229.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+cordless-stick-vacuum-25v,CORDLESS-STICK-VACUUM-25V-GRAPHITE,,419.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+cordless-stick-vacuum-25v,CORDLESS-STICK-VACUUM-25V-WHITE,,419.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+cordless-stick-vacuum-25v,CORDLESS-STICK-VACUUM-25V-BLUE,,419.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+bagless-upright-vacuum,BAGLESS-UPRIGHT-VACUUM-BLACK-AND-BLUE,,140,189.99,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+bagless-upright-vacuum,BAGLESS-UPRIGHT-VACUUM-BLACK-AND-RED,,140,189.99,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+robot-vacuum,ROBOT-VACUUM-BLACK,,329.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+robot-vacuum,ROBOT-VACUUM-WHITE,,329.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+robot-vacuum-pro,ROBOT-VACUUM-PRO-BLACK,,559.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+robot-vacuum-pro,ROBOT-VACUUM-PRO-WHITE,,559.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+ionic-hair-dryer,IONIC-HAIR-DRYER-WHITE,,64.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+ionic-hair-dryer,IONIC-HAIR-DRYER-BLACK,,64.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+ionic-hair-dryer,IONIC-HAIR-DRYER-ROSE-GOLD,,64.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+travel-hair-dryer,TRAVEL-HAIR-DRYER-BLACK,,32.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+travel-hair-dryer,TRAVEL-HAIR-DRYER-PINK,,32.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+ceramic-hair-straightener,CERAMIC-HAIR-STRAIGHTENER-BLACK,,74.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+ceramic-hair-straightener,CERAMIC-HAIR-STRAIGHTENER-WHITE,,74.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+ceramic-hair-straightener,CERAMIC-HAIR-STRAIGHTENER-ROSE-GOLD,,74.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+beard-trimmer-3000,BEARD-TRIMMER-3000-BLACK,,46.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+beard-trimmer-3000,BEARD-TRIMMER-3000-DARK-GREY,,46.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+beard-trimmer-7000,BEARD-TRIMMER-7000-GUNMETAL,,109.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+beard-trimmer-7000,BEARD-TRIMMER-7000-BLACK,,109.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+beard-trimmer-7000,BEARD-TRIMMER-7000-SILVER,,109.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+multigroom-kit,MULTIGROOM-KIT-BLACK,,74.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+multigroom-kit,MULTIGROOM-KIT-GREY,,74.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+rotary-shaver-5000,ROTARY-SHAVER-5000-BLACK,,119.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+rotary-shaver-5000,ROTARY-SHAVER-5000-DARK-BLUE,,119.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+rotary-shaver-9000,ROTARY-SHAVER-9000-CHROME,,279.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+rotary-shaver-9000,ROTARY-SHAVER-9000-MATTE-BLACK,,279.99,,EUR,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,diff --git a/spree/core/spec/models/spree/product_spec.rb b/spree/core/spec/models/spree/product_spec.rbindex b107c9a01d..6ce8f965a5 100644--- a/spree/core/spec/models/spree/product_spec.rb+++ b/spree/core/spec/models/spree/product_spec.rb@@ -1222,6 +1222,74 @@ describe Spree::Product, type: :model doexpect(product.to_csv).to be_presentendend++ context 'when store has multiple currencies' do+ let!(:variant1) { create(:variant, product: product) }++ before do+ variant1.set_price('EUR', 52.99, 62.99)+ product.master.set_price('EUR', 10.99)+ allow(store).to receive(:supported_currencies_list).and_return(+ [Money::Currency.find('USD'), Money::Currency.find('EUR')]+ )+ end++ it 'appends price-only rows for additional currencies' do+ csv_lines = product.reload.to_csv(store)++ # 2 default currency rows (master + variant) + 2 EUR price-only rows+ expect(csv_lines.size).to eq(4)++ # First 2 rows are normal USD rows+ expect(csv_lines[0]).to include(product.name)+ expect(csv_lines[1]).to include(variant1.sku)++ # Last 2 rows are EUR price-only rows+ eur_master = csv_lines[2]+ eur_variant = csv_lines[3]++ slug_idx = Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('slug')+ sku_idx = Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('sku')+ price_idx = Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('price')+ compare_idx = Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('compare_at_price')+ currency_idx = Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('currency')+ name_idx = Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('name')++ expect(eur_master[slug_idx]).to eq product.slug+ expect(eur_master[sku_idx]).to eq product.master.sku+ expect(eur_master[price_idx]).to eq 10.99+ expect(eur_master[currency_idx]).to eq 'EUR'+ expect(eur_master[name_idx]).to be_nil++ expect(eur_variant[slug_idx]).to eq product.slug+ expect(eur_variant[sku_idx]).to eq variant1.sku+ expect(eur_variant[price_idx]).to eq 52.99+ expect(eur_variant[compare_idx]).to eq 62.99+ expect(eur_variant[currency_idx]).to eq 'EUR'+ expect(eur_variant[name_idx]).to be_nil+ end++ it 'skips variants without a price in the additional currency' do+ # variant1 has EUR price (from before block), master has EUR price too+ # We verify that only variants with EUR prices get EUR rows+ csv_lines = product.reload.to_csv(store)++ eur_lines = csv_lines.select { |row| row[Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('currency')] == 'EUR' }+ usd_lines = csv_lines.select { |row| row[Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('currency')] == 'USD' }++ expect(usd_lines.size).to eq(2) # master + variant1+ expect(eur_lines.size).to eq(2) # master + variant1 (both have EUR prices)++ # Now remove the EUR price from master+ product.master.prices.base_prices.find_by(currency: 'EUR')&.destroy++ csv_lines = product.reload.to_csv(store)+ eur_lines = csv_lines.select { |row| row[Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('currency')] == 'EUR' }++ expect(eur_lines.size).to eq(1) # only variant1+ expect(eur_lines[0][Spree::CSV::ProductVariantPresenter::CSV_HEADERS.index('sku')]).to eq variant1.sku+ end+ endenddescribe '#on_sale?' dodiff --git a/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb b/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rbindex 881b517538..e648585b93 100644--- a/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb+++ b/spree/core/spec/presenters/spree/csv/product_variant_presenter_spec.rb@@ -169,6 +169,40 @@ RSpec.describe Spree::CSV::ProductVariantPresenter doendend+ describe 'price_only mode (additional currency)' do+ let(:variant) { create(:variant, product: product) }+ let(:presenter) { described_class.new(product, variant, 1, [], [], store, [], 'EUR') }++ before do+ variant.set_price('EUR', 58.99, 69.99)+ end++ it 'returns only slug, sku, price, compare_at_price, and currency' do+ result = presenter.call++ # Price fields populated+ expect(result[described_class::CSV_HEADERS.index('slug')]).to eq product.slug+ expect(result[described_class::CSV_HEADERS.index('sku')]).to eq variant.sku+ expect(result[described_class::CSV_HEADERS.index('price')]).to eq 58.99+ expect(result[described_class::CSV_HEADERS.index('compare_at_price')]).to eq 69.99+ expect(result[described_class::CSV_HEADERS.index('currency')]).to eq 'EUR'++ # Everything else nil+ expect(result[described_class::CSV_HEADERS.index('name')]).to be_nil+ expect(result[described_class::CSV_HEADERS.index('status')]).to be_nil+ expect(result[described_class::CSV_HEADERS.index('description')]).to be_nil+ expect(result[described_class::CSV_HEADERS.index('width')]).to be_nil+ expect(result[described_class::CSV_HEADERS.index('image1_src')]).to be_nil+ expect(result[described_class::CSV_HEADERS.index('option1_name')]).to be_nil+ expect(result[described_class::CSV_HEADERS.index('category1')]).to be_nil+ end++ it 'has the same number of columns as CSV_HEADERS' do+ result = presenter.call+ expect(result.size).to eq described_class::CSV_HEADERS.size+ end+ end+describe 'shipping_category' docontext 'when product has shipping category' dolet(:shipping_category) { create(:shipping_category, name: 'Digital') }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.rbindex 231bf9c52d..847236e4ba 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@@ -159,6 +159,110 @@ RSpec.describe Spree::Imports::RowProcessors::ProductVariant, type: :service doendend+ context 'when importing price-only rows in a different currency' do+ let(:color_option_type) { create(:option_type, name: 'color', presentation: 'Color') }+ let(:blue_option_value) { create(:option_value, name: 'Blue', presentation: 'Blue', option_type: color_option_type) }++ let!(:product) do+ p = create(:product, slug: 'denim-shirt', name: 'Denim Shirt', stores: [store])+ p.option_types << color_option_type+ p+ end++ let!(:existing_variant) do+ create(:variant, product: product, sku: 'DENIM-SHIRT-BLUE', price: 62.99, option_values: [blue_option_value])+ end++ let(:row_data) do+ csv_row_hash(+ 'slug' => 'denim-shirt',+ 'sku' => 'DENIM-SHIRT-BLUE',+ 'price' => '58.99',+ 'currency' => 'EUR'+ )+ end++ it 'adds the new currency price to the existing variant' do+ result = subject.process!++ expect(result).to eq existing_variant+ expect(result.prices.base_prices.count).to eq 2+ expect(result.price_in('USD').amount.to_f).to eq 62.99+ expect(result.price_in('EUR').amount.to_f).to eq 58.99+ end++ it 'does not create a new variant' do+ expect { subject.process! }.not_to change { product.variants.count }+ end++ it 'preserves option values on the variant' do+ subject.process!+ expect(existing_variant.reload.option_values.map(&:presentation)).to eq ['Blue']+ end++ it 'preserves product taxons' do+ men_taxonomy = store.taxonomies.find_by(name: 'Men') || create(:taxonomy, name: 'Men', store: store)+ clothing_taxon = create(:taxon, name: 'Clothing', taxonomy: men_taxonomy, parent: men_taxonomy.root)+ product.update!(taxons: [clothing_taxon])++ subject.process!+ expect(product.reload.taxons).to eq [clothing_taxon]+ end++ it 'preserves product metafields' do+ create(:metafield_definition, namespace: 'custom', key: 'brand', name: 'Brand',+ resource_type: 'Spree::Product', metafield_type: 'Spree::Metafields::ShortText')+ product.set_metafield('custom.brand', 'Awesome Brand')+ expect(product.reload.metafields.count).to eq 1++ subject.process!++ product.reload+ expect(product.metafields.count).to eq 1+ expect(product.get_metafield('custom.brand').value).to eq 'Awesome Brand'+ end++ context 'with compare_at_price' do+ let(:row_data) do+ csv_row_hash(+ 'slug' => 'denim-shirt',+ 'sku' => 'DENIM-SHIRT-BLUE',+ 'price' => '49.99',+ 'compare_at_price' => '58.99',+ 'currency' => 'EUR'+ )+ end++ it 'sets compare_at_amount for the new currency' do+ subject.process!++ eur_price = existing_variant.price_in('EUR')+ expect(eur_price.amount.to_f).to eq 49.99+ expect(eur_price.compare_at_amount.to_f).to eq 58.99+ end+ end++ context 'when updating an existing currency price' do+ before do+ existing_variant.set_price('EUR', 55.99)+ end++ let(:row_data) do+ csv_row_hash(+ 'slug' => 'denim-shirt',+ 'sku' => 'DENIM-SHIRT-BLUE',+ 'price' => '58.99',+ 'currency' => 'EUR'+ )+ end++ it 'updates the existing price' do+ expect { subject.process! }.not_to change { existing_variant.prices.base_prices.count }+ expect(existing_variant.price_in('EUR').amount.to_f).to eq 58.99+ end+ end+ end+context 'when importing a variant row with a new option type/value' dolet!(:product) docreate(:product, slug: 'denim-shirt', name: 'Denim Shirt', stores: [store])@@ -273,6 +377,7 @@ RSpec.describe Spree::Imports::RowProcessors::ProductVariant, type: :service dolet(:row_data) docsv_row_hash('slug' => 'denim-shirt',+ 'name' => 'Denim Shirt','category1' => '','category2' => nil)