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
Mark the product types plan as delivered
Damian Legawiecfb8b7ce1ae08
diff --git a/CLAUDE.md b/CLAUDE.mdindex bfd00d670a..c046f258f6 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -16,7 +16,7 @@ Active plans (6.0 target, work pending):- `6.0-cart-order-split.md` — Cart/Order model separation, dual-FK owner everywhere (`cart_id`/`order_id` exactly-one, `#owner` as method — NOT polymorphic), idempotent copy-on-completion (`Order#cart_id` unique, order-before-payment), Order state machine removed (Checkout::Requirements for steps; payment/fulfillment statuses derived-then-persisted via one recompute service). **Shipped to 6-0-dev (feature/6-0-core-rewrite Waves 1+5):** Cart owns checkout end to end, machine + `spree_orders.state` gone, `Carts::Complete` three-phase pipeline live, `Orders::UpdateStatuses` sole status writer; only Wave 7 data migration (incomplete orders → carts) remains- `6.0-admin-api.md` — Admin REST API conventions, auth, endpoint list (~300 endpoints)- `6.0-admin-spa.md` — React admin architecture, extension points, table registry, i18n + server-error mapping-- `6.0-product-types.md` — Prototype → ProductType rename, custom-field schema enforcement. **Creation-time template (2026-08-06):** type edits never mutate existing products (custom-field form/validation + `fulfillment_types` are live by reference; option types/categories seed additively at attach; explicit previewed `ApplyToProducts` job is the only bulk path); per-product type detach/reassign allowed (non-destructive), required fields validate at activation only, no Store API exposure. **Shipped:** Phases 1+3, most of 4; Phase 2 (rescoped) is the delivery checklist in the plan+- `6.0-product-types.md` — Prototype → ProductType rename, custom-field schema enforcement. **Creation-time template (2026-08-06):** type edits never mutate existing products (custom-field form/validation + `fulfillment_types` are live by reference; option types/categories seed additively at attach; explicit previewed `ApplyToProducts` job is the only bulk path); per-product type detach/reassign allowed (non-destructive), required fields validate at activation only, no Store API exposure. **Fully shipped** (all phases, Phase 2 rescoped + delivered 2026-08-06)- `6.0-remove-master-variant.md` — Eliminate is_master, add default_variant_id FK on Product. **Shipped to 6-0-dev (PR #14265):** is_master removed from all models, default_variant_id + `spree:remove_master_variant` data-migration rake landed; only the physical is_master column drop remains (6.1 cleanup).- `6.0-typed-stock-movements.md` — Replace generic StockMovement with typed kinds + concrete FKs- `6.0-normalize-state-to-status.md` — Rename state → status on Payment, Shipment, InventoryUnit, ReturnAuthorization, GiftCarddiff --git a/docs/plans/6.0-product-types.md b/docs/plans/6.0-product-types.mdindex 40de3537d9..4fab3a0e04 100644--- a/docs/plans/6.0-product-types.md+++ b/docs/plans/6.0-product-types.md@@ -1,6 +1,6 @@# ProductType (Prototype → ProductType)-**Status:** Phases 1 and 3 shipped, Phase 4 partly; Phase 2 (rescoped 2026-08-06) pending — see "Implementation status"+**Status:** All phases shipped (Phase 2 rescoped and completed 2026-08-06) — see "Implementation status"**Target:** Spree 6.0**Depends on:** Custom Fields system (Metafields, shipped 5.4; 6.0 vocabulary per `5.4-6.0-custom-fields-rename.md`), `6.0-store-scoped-custom-field-definitions.md` (definitions become store-owned — the joins here validate same-store). Coordinates with: `6.0-replace-taxons-with-categories.md` (this plan ships **before** the Taxon→Category table rename; the `class_name` flip happens in that plan's wave). Consumed by: `6.0-fulfillment-and-delivery.md` (`fulfillment_types` replaces ShippingCategory — that plan cannot ship before this one).**Author:** Damian + Claude@@ -19,15 +19,17 @@ This is the Shopify-shaped behavior (category changes affect nothing retroactive**Shipped:** Phase 1 (the `Spree::ProductType` model, both join models, `fulfillment_types` with registry-backed validation, `Product#product_type` + `#fulfillment_types` + `#digital?`), Phase 3 (admin API controller, Store + Admin serializers — the base `V3::ProductTypeSerializer` exists only as the admin serializer's parent class per house convention; it is not wired to any store endpoint), and most of Phase 4 (dashboard settings page, product-types table, `product_type_id` on the product form).-**Pending — the delivery checklist (Phase 2 as rescoped):**+**Phase 2 as rescoped — shipped 2026-08-06:**-1. **Fix the seeding trigger (shipped-code gap).** `sync_associations_from_product_type` runs only `after_create` (`product.rb:162`) — assigning a type to an existing typeless product, or reassigning, silently skips the option-type/category seeding. Move to `after_save, if: :saved_change_to_product_type_id?` (covers create, later assignment, and reassignment; guard on `product_type` presence).-2. **`ProductTypeCustomFieldDefinition` join** — migration + model (unchanged from the original Phase 2 design; no `level` column, see Key Decisions).-3. **Required-field validation at activation only** — validate the type's required custom fields when a product transitions into `active`, never on ordinary saves of an already-active product.-4. **`Apply to existing products`** — `POST /api/v3/admin/product_types/:id/apply_to_products`, additive-only service + background job, dashboard confirm dialog showing `products_count`.-5. **Admin controller write surface** — permit `option_type_ids`, `category_ids`, and the nested `custom_field_definitions` payload (today only `name` + `fulfillment_types` are permitted). Replace-set writes on the type are safe: they edit the template only and never touch products.-6. **Dashboard** — type-driven custom-field form on the product page (rendered from the type's definition list, `sort_order`, required indicators), the apply-action confirm, and "type edits affect new products only" messaging on the type edit page.-7. **No immutability guard to remove** — the model-level type-change block from the superseded 2026-07-27 decision was never shipped; do not add it. Add specs covering detach/reassign being additive and non-destructive instead.+1. **Seeding trigger fixed** — `sync_associations_from_product_type` now also runs `after_update, if: :saved_change_to_product_type_id?`, so assigning a type to an existing product and reassigning both seed (detach is a no-op). Presence guards query the join tables rather than the cached associations, which are stale when pending variants insert option-type joins in the same save.+2. **`ProductTypeCustomFieldDefinition`** — table + model with `required`/`sort_order`, `required`/`ordered` scopes, per-type uniqueness, and a validation that the definition's `resource_type` is `Spree::Product`. **No `Spree::CustomFieldDefinition` constant exists in Ruby** (the 5.5 alias this plan assumed is API-layer only), so the association carries custom-field vocabulary while `class_name` points at `Spree::MetafieldDefinition`.+3. **Required-field validation at activation only** — `becoming_active?` (`active? && (new_record? || status_changed?)`) gates it, so a type gaining a required field never breaks saves of already-active products.+4. **`ProductTypes::ApplyToProducts`** + `ApplyToProductsJob` + `POST /api/v3/admin/product_types/:id/apply_to_products` (202 with `products_count`). Batched, additive, idempotent; the category half delegates to `Categories::AddProducts`, which owns the counter-cache/position/search-index bookkeeping a raw `insert_all` would skip.+5. **Admin write surface** — `option_type_ids`, `category_ids` and the nested `custom_field_definitions` replace-set are permitted; the serializer returns association ids as prefixed ids (read/write symmetry). Category ids are re-scoped to `current_store` before assignment (OptionType is global — nothing to scope there).+6. **Dashboard** — the type sheet edits option types, categories and the dnd-kit-sortable custom-field list with per-row `required` toggles, carries the "changes apply to new products" note, and offers the confirmed apply action. The product form renders custom fields from its type via a new `definitionIds` prop on `FormBackedCustomFieldsProvider` (omitted ⇒ all definitions, so typeless products are unchanged). Keys added to all six locales.+7. **No immutability guard** — the superseded 2026-07-27 model-level block was never shipped and was not added; specs cover detach/reassign being additive and non-destructive.++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, and a sequenced `product_type` factory name (the static name collided whenever a spec built two types in one store).**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.@@ -117,18 +119,18 @@ ProductType must also be registered in `Spree.metafields.enabled_resources` (its# New join: which custom field definitions does this type require?class Spree::ProductTypeCustomFieldDefinition < Spree.base_classbelongs_to :product_type, class_name: 'Spree::ProductType'- belongs_to :custom_field_definition, class_name: 'Spree::CustomFieldDefinition'+ # Vocabulary is custom-field; the class is still MetafieldDefinition — no+ # Spree::CustomFieldDefinition constant exists until the rename wave.+ belongs_to :custom_field_definition, class_name: 'Spree::MetafieldDefinition'validates :product_type, :custom_field_definition, presence: truevalidates :custom_field_definition_id, uniqueness: { scope: :product_type_id }- validate :same_store # definition.store_id must match product_type.store_id- # (once 6.0-store-scoped-custom-field-definitions.md lands)-- attribute :required, :boolean, default: false # defaults are model-level, not DB- attribute :sort_order, :integer, default: 0+ validate :custom_field_definition_applies_to_products # resource_type must be Spree::Product+ # TODO: same_store once 6.0-store-scoped-custom-field-definitions.md lands+ # (definitions are still global today)scope :required, -> { where(required: true) }- scope :ordered, -> { order(:sort_order) }+ scope :ordered, -> { order(:sort_order, :id) }end```@@ -168,7 +170,8 @@ class Spree::Product < Spree.base_class# Seeds fire on create AND on any later assignment or reassignment —# detach (nil) is a no-op, reassign seeds the new type additively.- after_save :sync_associations_from_product_type, if: :saved_change_to_product_type_id?+ after_create :sync_associations_from_product_type+ after_update :sync_associations_from_product_type, if: :saved_change_to_product_type_id?# Activation-only: never fails an ordinary save of an already-active productvalidate :required_custom_fields_present, if: :becoming_active?@@ -178,15 +181,21 @@ class Spree::Product < Spree.base_class# ADDITIVE — deliberately unlike the legacy prototype callback, which REPLACED# option_types/taxons by assignment. Never removes anything; a product that# already has the option type or category is untouched.+ # Presence guards hit the join tables, not the cached associations — those go+ # stale when pending variants insert option-type joins in the same save.def sync_associations_from_product_typereturn unless product_type- product_type.option_types.each { |ot| option_types << ot unless option_types.include?(ot) }- product_type.categories.each { |cat| categories << cat unless categories.include?(cat) }+ product_type.option_types.each do |ot|+ option_types << ot unless product_option_types.exists?(option_type_id: ot.id)+ end+ product_type.categories.each do |cat|+ categories << cat unless product_categories.exists?(category_id: cat.id)+ endenddef becoming_active?- active? && status_changed?+ active? && (new_record? || status_changed?)enddef required_custom_fields_present@@ -205,21 +214,9 @@ There is **no** `type_option_types_present` validation, no `type_option_type?`/`### Apply to existing products-```ruby-# app/services — Tier 1 per 6.0-service-workflows.md. The ONLY path by which a-# type edit reaches existing products. Additive and idempotent: safe to re-run,-# never removes anything, never touches variants or option values.-class Spree::ProductTypes::ApplyToProducts- def call(product_type:)- product_type.products.find_each do |product|- (product_type.option_types - product.option_types).each { |ot| product.option_types << ot }- (product_type.categories - product.categories).each { |cat| product.categories << cat }- end- end-end-```+`Spree::ProductTypes::ApplyToProducts` (Tier 1 service per `6.0-service-workflows.md`) is the ONLY path by which a type edit reaches existing products. Additive and idempotent: safe to re-run, never removes anything, never touches variants or option values. It batches with `find_in_batches`, bulk-inserts the missing option-type joins (continuing each product's own `acts_as_list` position sequence), and delegates the category half to `Categories::AddProducts` — that service owns the counter-cache, position and search-index bookkeeping that a raw `insert_all` would silently skip. Returns the count of products changed.-Invoked from the Admin API via a background job (`ProductTypes::ApplyToProductsJob`); the dashboard confirms with the type's `products_count` before enqueueing. Adding an option type to a product is safe by construction: existing variants simply have no values for it yet — no validation starts failing.+Invoked from the Admin API via a background job (`ProductTypes::ApplyToProductsJob`, `Spree.queues.products`); the dashboard confirms with the type's `products_count` before enqueueing. Adding an option type to a product is safe by construction: existing variants simply have no values for it yet — no validation starts failing.### Admin API@@ -339,9 +336,9 @@ Code changes:- Registries: add `Spree::ProductType` to `Spree.metafields.enabled_resources` and `Spree.translatable_resources`.- Locale keys (core `en.yml` prototype keys → product_type; the dead `new_prototype` key in the legacy admin dies with `spree/admin`), factories (`prototype_factory` → `product_type_factory` with one-release aliases — `testing_support` is public API), specs (`prototype_spec`, `product_spec.rb:444-493` callback tests).-### Phase 2: Schema enforcement (rescoped 2026-08-06)+### Phase 2: Schema enforcement (rescoped and shipped 2026-08-06)-The custom-field-definition join, plus the seeding/validation/apply work from the delivery checklist (Implementation status items 1–7):+The custom-field-definition join, plus the seeding/validation/apply work (Implementation status items 1–7). The shipped migration carries DB defaults on `required`/`sort_order` — both are `null: false`, and the house rule is that boolean and integer columns keep defaults so raw inserts can't produce nulls:```rubyclass CreateSpreeProductTypeCustomFieldDefinitions < ActiveRecord::Migration[7.2]@@ -349,8 +346,8 @@ class CreateSpreeProductTypeCustomFieldDefinitions < ActiveRecord::Migration[7.2create_table :spree_product_type_custom_field_definitions do |t|t.references :product_type, null: falset.references :custom_field_definition, null: false- t.boolean :required, null: false # defaults live on the model, not the DB- t.integer :sort_order, null: false+ t.boolean :required, null: false, default: false+ t.integer :sort_order, null: false, default: 0t.timestampsend