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.

Only require sample fields the products actually carry

Damian Legawiec002c1d1d1935
diff --git a/docs/plans/6.0-product-types.md b/docs/plans/6.0-product-types.md
index 4ba3cc5b40..f3b7975c20 100644
--- a/docs/plans/6.0-product-types.md
+++ b/docs/plans/6.0-product-types.md
@@ -31,7 +31,7 @@ This is the Shopify-shaped behavior (category changes affect nothing retroactive
Also shipped alongside: an integration spec for the whole resource (product types were entirely absent from the API reference), the `productTypes.applyToProducts` SDK method with expanded params, a sequenced `product_type` factory name (the static name collided whenever a spec built two types in one store), and `Spree::Store#product_types` — the inverse association was missing even though ProductType is store-owned.
-**Sample data showcases the feature (2026-08-06).** `spree:load_sample_data` previously put all 37 demo products in one `Default` type, which demonstrated nothing. The CSV's `product_type` column now names six types derived from what the catalog actually contains — Kitchen Appliance, Air Treatment, Garment Care, Vacuum Cleaner, Hair Styling, Grooming — and `db/sample_data/product_types.rb` gives each its own schema: all six require wattage/voltage/warranty, Air Treatment also requires room coverage, Grooming also requires runtime, and capacity/runtime/connectivity/noise level are optional where they apply. Categories are linked afterwards by `product_type_categories.rb`, since the import is what creates them. The `Default` and `Digital` types stay — they are seeds, not sample data.
+**Sample data showcases the feature (2026-08-06).** `spree:load_sample_data` previously put all 37 demo products in one `Default` type, which demonstrated nothing. The CSV's `product_type` column now names six types derived from what the catalog actually contains — Kitchen Appliance, Air Treatment, Garment Care, Vacuum Cleaner, Hair Styling, Grooming — and `db/sample_data/product_types.rb` gives each its own schema: all six require wattage/voltage/warranty, Grooming also requires runtime (every trimmer and shaver is cordless), and capacity/room coverage/runtime/connectivity/noise level are optional where they apply. A field is required only where every product of that type actually carries it — room coverage is optional on Air Treatment because fans move air rather than treating a room. Categories are linked afterwards by `product_type_categories.rb`, since the import is what creates them. The `Default` and `Digital` types stay — they are seeds, not sample data.
**ShippingCategory is fully retired from behavior (2026-08-05).** `ProductType#fulfillment_types` is the sole delivery-eligibility input — `Stock::Package#eligible_delivery_methods` reads it and nothing consults the category for routing. The CSV `shipping_category` column was cut outright rather than bridged (see `6.0-fulfillment-and-delivery.md`); `Product#shipping_category` survives only as a deprecated association, dropping with the table in 6.1. The removal is unreleased but stays (2026-08-06 decision) — see the fulfillment plan's "named delivery groups" note for the if-needed 6.1 successor to profile-style grouping.
diff --git a/spree/core/db/sample_data/product_types.rb b/spree/core/db/sample_data/product_types.rb
index d37e47febd..9df8691338 100644
--- a/spree/core/db/sample_data/product_types.rb
+++ b/spree/core/db/sample_data/product_types.rb
@@ -28,9 +28,11 @@ product_types = [
optional_fields: %w[capacity]
},
{
+ # room_coverage is optional, not required: purifiers and humidifiers treat a
+ # room, fans just move air — so the type covers both without lying about one.
name: 'Air Treatment',
- required_fields: %w[wattage voltage warranty room_coverage],
- optional_fields: %w[capacity noise_level connectivity]
+ required_fields: %w[wattage voltage warranty],
+ optional_fields: %w[room_coverage capacity noise_level connectivity]
},
{
name: 'Garment Care',
diff --git a/spree/core/spec/services/spree/sample_data/loader_spec.rb b/spree/core/spec/services/spree/sample_data/loader_spec.rb
index 9a9e7435ab..af1f289f90 100644
--- a/spree/core/spec/services/spree/sample_data/loader_spec.rb
+++ b/spree/core/spec/services/spree/sample_data/loader_spec.rb
@@ -55,6 +55,22 @@ RSpec.describe Spree::SampleData::Loader, type: :service, without_global_store:
end
end
+ # A required field with no value in the CSV would block the merchant from
+ # re-activating that product in the dashboard.
+ it 'backs every required field with a value on every product of the type' do
+ incomplete = Spree::Product.includes(:product_type, metafields: :metafield_definition).select do |product|
+ next false if product.product_type.nil?
+
+ required_ids = product.product_type.product_type_custom_field_definitions.required.
+ map(&:custom_field_definition_id)
+ filled_ids = product.metafields.select { |metafield| metafield.value.present? }.
+ map(&:metafield_definition_id)
+ (required_ids - filled_ids).any?
+ end
+
+ expect(incomplete.map(&:name)).to be_empty
+ end
+
it 'fills the required fields on the imported products' do
product = Spree::Product.joins(:product_type).find_by(spree_product_types: { name: 'Kitchen Appliance' })