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.

Update plans

Damian Legawiecc738b2a2752a
diff --git a/CLAUDE.md b/CLAUDE.md
index c96e3f9d6c..6ab3deb591 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -33,6 +33,7 @@ Current plans:
- `5.4-disjunctive-option-faceting.md` — Per-option-type filter params with disjunctive facet counts (OR within option type, AND across)
+- `5.5-option-type-enhancements.md` — Add `kind` (dropdown/color_swatch/buttons) to OptionType, `color_code` + `image` to OptionValue for swatch support
Completed plans:
- `5.4-store-api-bridges.md` — Bridge 6.0 naming into 5.4 Store API (implemented, PR #13782)
diff --git a/docs/plans/5.5-option-type-enhancements.md b/docs/plans/5.5-option-type-enhancements.md
new file mode 100644
index 0000000000..2b82a132a6
--- /dev/null
+++ b/docs/plans/5.5-option-type-enhancements.md
@@ -0,0 +1,278 @@
+# Option Type Enhancements
+
+**Status:** Draft
+**Target:** Spree 5.5
+**Depends on:** `5.4-store-api-naming-standardization.md` (`presentation` → `label` bridge)
+**Author:** Damian + Claude
+**Last updated:** 2026-03-26
+
+## Summary
+
+Spree's OptionType and OptionValue models are structurally sound — global, shared, M2M with products, proper disjunctive faceting — but lack **presentation metadata**. A storefront receiving an option type has no API-level signal for how to render it (dropdown vs. color swatches vs. size buttons) or any visual data on option values (hex color, swatch image). Every Spree frontend must invent its own convention or rely on the hardcoded `color?` name check.
+
+This plan adds a `kind` column to OptionType (rendering hint) and `color_code` + `image` to OptionValue (visual metadata), closing the last significant gap vs. Shopify and Saleor without overcomplicating the model.
+
+## Problem
+
+1. **No rendering hint on OptionType.** The filters endpoint returns `type: "option"` for every option type. The frontend cannot distinguish Color (should render as swatches) from Size (should render as buttons) from Material (should render as dropdown) without hardcoding option type names.
+
+2. **No visual metadata on OptionValue.** Shopify has `ProductOptionValueSwatch` (hex color + image). Saleor has `AttributeValue.value` (hex) + `file_url` (image). Spree has nothing — the only visual hint is a hardcoded `color?` method checking if the option type name is "color" or "colour".
+
+3. **Metafields are not the answer.** While metafields could theoretically store color codes, there's no API contract — frontends don't know which metafield key to look for, and the filters endpoint doesn't include metafield data on option values.
+
+## Key Decisions (do not deviate without discussion)
+
+- **`kind` is a rendering hint, not a behavioral change.** It tells the frontend how to display the option. The underlying data model (OptionType → OptionValue → Variant) is unchanged. All kinds use the same predefined value pool.
+- **Only kinds that make sense for variant axes.** No `text_input`, `file`, `rich_text`, etc. — those are not variant-defining (see MetafieldDefinition for typed attributes, `line_item.metadata` for customer input at purchase time).
+- **Three kinds: `dropdown`, `color_swatch`, `buttons`.** Covers all standard e-commerce option rendering patterns. `dropdown` is the default for backward compatibility.
+- **`color_code` and `image` on OptionValue are optional.** They are presentation-only fields. An option value without a color code or image renders normally (by label). Having a `color_code` without `kind: color_swatch` on the parent type is allowed (no coupling).
+- **Exposed in both the filters endpoint and product serializers.** Frontends get the rendering hint everywhere options appear.
+- **`color?` method kept but deprecated.** Replaced by `kind == 'color_swatch'` check. Remove `color?` in 6.0.
+- **Image uses Active Storage attachment**, consistent with how Spree handles images elsewhere (product images, category icons). Not a URL string column.
+
+## Design Details
+
+### Schema Changes
+
+```ruby
+class AddKindToSpreeOptionTypes < ActiveRecord::Migration[7.2]
+ def change
+ add_column :spree_option_types, :kind, :string, null: false, default: 'dropdown'
+ add_index :spree_option_types, :kind
+
+ # Backfill: option types named 'color'/'colour' get kind 'color_swatch'
+ reversible do |dir|
+ dir.up do
+ execute "UPDATE spree_option_types SET kind = 'color_swatch' WHERE name IN ('color', 'colour')"
+ end
+ end
+ end
+end
+```
+
+```ruby
+class AddVisualMetadataToSpreeOptionValues < ActiveRecord::Migration[7.2]
+ def change
+ add_column :spree_option_values, :color_code, :string # e.g. "#FF0000", nullable
+ end
+end
+```
+
+### Model Changes
+
+```ruby
+class Spree::OptionType < Spree.base_class
+ KINDS = %w[dropdown color_swatch buttons].freeze
+
+ validates :kind, presence: true, inclusion: { in: KINDS }
+
+ scope :color_swatches, -> { where(kind: 'color_swatch') }
+
+ def color_swatch?
+ kind == 'color_swatch'
+ end
+
+ # Deprecate old method
+ def color?
+ Spree::Deprecation.warn(
+ 'Spree::OptionType#color? is deprecated. Use #color_swatch? instead. Will be removed in Spree 6.0.'
+ )
+ color_swatch?
+ end
+end
+```
+
+```ruby
+class Spree::OptionValue < Spree.base_class
+ has_one_attached :image
+
+ # Validates hex color format when present
+ validates :color_code, format: { with: /\A#[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?\z/, message: 'must be a valid hex color (e.g. #FF0000)' },
+ allow_blank: true
+end
+```
+
+### Serializer Changes
+
+```ruby
+# Store API
+module Spree::Api::V3
+ class OptionTypeSerializer < BaseSerializer
+ typelize name: :string, label: :string, position: :number, kind: :string
+
+ attributes :name, :label, :position, :kind
+ end
+end
+```
+
+```ruby
+module Spree::Api::V3
+ class OptionValueSerializer < BaseSerializer
+ typelize name: :string, label: :string, position: :number, option_type_id: :string,
+ option_type_name: :string, option_type_label: :string,
+ color_code: 'string | null', image_url: 'string | null'
+
+ attribute :option_type_id do |option_value|
+ option_value.option_type&.prefixed_id
+ end
+
+ attributes :name, :label, :position, :color_code
+
+ attribute :option_type_name do |option_value|
+ option_value.option_type.name
+ end
+
+ attribute :option_type_label do |option_value|
+ option_value.option_type.label
+ end
+
+ attribute :image_url do |option_value|
+ option_value.image.attached? ? Rails.application.routes.url_helpers.url_for(option_value.image) : nil
+ end
+ end
+end
+```
+
+### Filters Endpoint Changes
+
+The `FiltersAggregator` option type filter response gains `kind`, and each option value gains `color_code` and `image_url`:
+
+```ruby
+# In FiltersAggregator#option_type_filters
+{
+ id: option_type.prefixed_id,
+ type: 'option',
+ name: option_type.name,
+ label: option_type.label,
+ kind: option_type.kind, # NEW
+ options: values.map { |ov| option_value_data(count_ids, ov) }
+}
+
+# In FiltersAggregator#option_value_data
+{
+ id: option_value.prefixed_id,
+ name: option_value.name,
+ label: option_value.label,
+ position: option_value.position,
+ color_code: option_value.color_code, # NEW
+ image_url: option_value.image.attached? ? url_for(option_value.image) : nil, # NEW
+ count: count
+}
+```
+
+### Filter Response Example
+
+```json
+{
+ "id": "opt_k5nR8x",
+ "type": "option",
+ "name": "color",
+ "label": "Color",
+ "kind": "color_swatch",
+ "options": [
+ { "id": "optval_red", "name": "red", "label": "Red", "position": 1, "color_code": "#FF0000", "image_url": null, "count": 42 },
+ { "id": "optval_blue", "name": "blue", "label": "Blue", "position": 2, "color_code": "#0000FF", "image_url": null, "count": 38 },
+ { "id": "optval_floral", "name": "floral", "label": "Floral", "position": 3, "color_code": null, "image_url": "https://cdn.example.com/swatches/floral.jpg", "count": 15 }
+ ]
+}
+```
+
+### Admin API
+
+Admin serializers extend Store serializers as usual, gaining `kind`, `color_code`, and `image_url` automatically.
+
+`PermittedAttributes` additions:
+
+```ruby
+@@option_type_attributes = [
+ :name, :presentation, :position, :filterable, :kind, # kind added
+ option_values_attributes: [:id, :name, :presentation, :position, :color_code, :image, :_destroy] # color_code, image added
+]
+```
+
+### Search Provider Integration
+
+**Meilisearch:** Index `kind` on option types for potential facet-aware rendering. No change to how option values are indexed — `color_code` and `image_url` are presentation-only, not filterable.
+
+**Database:** No search index changes. `kind` is returned via FiltersAggregator only.
+
+### SDK Type Changes
+
+After running the typelizer pipeline:
+
+```typescript
+interface OptionType {
+ id: string
+ name: string
+ label: string
+ position: number
+ kind: string // 'dropdown' | 'color_swatch' | 'buttons'
+}
+
+interface OptionValue {
+ id: string
+ name: string
+ label: string
+ position: number
+ option_type_id: string
+ option_type_name: string
+ option_type_label: string
+ color_code: string | null
+ image_url: string | null
+}
+```
+
+## Migration Path
+
+### Phase 1: Schema + models
+
+1. Add `kind` column to `spree_option_types` (default `'dropdown'`, backfill `'color_swatch'` for color/colour)
+2. Add `color_code` column to `spree_option_values`
+3. Add `image` Active Storage attachment to `OptionValue`
+4. Model validations + deprecate `color?`
+
+### Phase 2: Serializers + API
+
+1. Update Store and Admin `OptionTypeSerializer` — add `kind`
+2. Update Store and Admin `OptionValueSerializer` — add `color_code`, `image_url`
+3. Update `FiltersAggregator` — include `kind`, `color_code`, `image_url` in filter response
+4. Update `PermittedAttributes` — allow `kind`, `color_code`, `image` in params
+
+### Phase 3: SDK + types
+
+1. Run typelizer pipeline
+2. Regenerate Zod schemas
+3. Update SDK tests
+4. Changeset for `@spree/sdk`
+
+### Phase 4: Admin UI
+
+1. OptionType form: `kind` selector (dropdown/color_swatch/buttons)
+2. OptionValue form: `color_code` picker + `image` uploader (shown when parent type's kind is `color_swatch`, but not restricted to it)
+3. Product variant option display respects `kind` for rendering
+
+## Constraints on Current Work
+
+- **Do not add more hardcoded option type name checks** (like `color?`). Use `kind` once it ships.
+- **Do not store presentation metadata in metafields on option values.** It will have dedicated columns.
+- **Do not couple `kind` to behavioral logic.** It is a rendering hint only — all kinds use the same OptionType → OptionValue → Variant data model.
+
+## Open Questions
+
+1. **Should `kind` be extensible?** The initial set is `dropdown`, `color_swatch`, `buttons`. Should merchants/extensions be able to register custom kinds (e.g., `image_swatch`, `radio`, `slider`)? For now, a fixed set is simpler — custom rendering can always be done frontend-side by checking `kind` and falling back. Revisit if demand arises.
+
+2. **Should `image` on OptionValue support variants (thumbnails)?** Active Storage supports variants for resizing. Swatches are typically small (32×32 to 64×64). We could auto-generate a `swatch` variant. Defer until we see real usage patterns.
+
+3. **Dual swatch mode: color_code vs. image.** When both are present on an option value, which takes precedence? Suggestion: frontend decides — the API returns both, the storefront picks whichever it prefers (image > color_code is the Shopify convention).
+
+## References
+
+- Shopify `ProductOptionValueSwatch`: hex color + media image on option values
+- Saleor `AttributeValue`: `value` field (hex for swatches) + `file_url` (swatch images)
+- Current `color?` method: `spree/core/app/models/spree/option_type.rb:76`
+- Filters endpoint: `spree/api/app/controllers/spree/api/v3/store/products/filters_controller.rb`
+- FiltersAggregator: `spree/api/app/services/spree/api/v3/filters_aggregator.rb`
+- Naming standardization plan: `5.4-store-api-naming-standardization.md` (presentation → label)
+- ProductType plan: `6.0-product-types.md` (option types as live template)
+- Disjunctive faceting plan: `5.4-disjunctive-option-faceting.md`
+- Competitive analysis: Spree vs. Shopify/Saleor/Medusa/Vendure option systems (2026-03-26)
diff --git a/docs/plans/6.0-fulfillment-and-delivery.md b/docs/plans/6.0-fulfillment-and-delivery.md
index 143a247d75..d45e9b3b58 100644
--- a/docs/plans/6.0-fulfillment-and-delivery.md
+++ b/docs/plans/6.0-fulfillment-and-delivery.md
@@ -4,7 +4,7 @@
**Target:** Spree 6.0
**Depends on:** ProductType (6.0-product-types.md), Normalize state→status (6.0-normalize-state-to-status.md), Typed Stock Movements (6.0-typed-stock-movements.md)
**Author:** Damian + Claude
-**Last updated:** 2026-03-16
+**Last updated:** 2026-03-26
## Summary
@@ -56,7 +56,7 @@ ProductType gains a `fulfillment_types` array column:
class Spree::ProductType < Spree.base_class
# Array of allowed fulfillment types for products of this type
# Default: ['shipping']
- # Examples: ['shipping', 'pickup'], ['digital'], ['shipping', 'pickup', 'local_delivery']
+ # Examples: ['shipping', 'pickup'], ['digital'], ['shipping', 'pickup', 'pickup_point', 'local_delivery']
attribute :fulfillment_types, default: ['shipping']
validates :fulfillment_types, presence: true
@@ -83,7 +83,7 @@ For mixed carts (physical + digital), separate fulfillments are created automati
```ruby
class Spree::DeliveryMethod < Spree.base_class
# Built-in types
- FULFILLMENT_TYPES = %w[shipping pickup digital local_delivery].freeze
+ FULFILLMENT_TYPES = %w[shipping pickup pickup_point digital local_delivery].freeze
# Open string — developers can register custom types
validates :fulfillment_type, presence: true
@@ -93,6 +93,12 @@ class Spree::DeliveryMethod < Spree.base_class
end
```
+- `shipping` — carrier delivery to customer's address
+- `pickup` — customer collects from merchant's own location (store, warehouse)
+- `pickup_point` — carrier delivers to third-party point (InPost locker, DHL ServicePoint, UPS Access Point), customer collects there
+- `digital` — digital download, no physical delivery
+- `local_delivery` — merchant delivers within a local radius
+
### FulfillmentProvider is a strategy (not a DB model)
```ruby
@@ -128,7 +134,8 @@ end
Built-in providers:
- `Spree::FulfillmentProvider::Manual` — admin manually marks as shipped (default, current behavior)
- `Spree::FulfillmentProvider::Digital` — auto-generates DigitalLink on order completion
-- `Spree::FulfillmentProvider::Pickup` — marks ready-for-pickup at location
+- `Spree::FulfillmentProvider::Pickup` — marks ready-for-pickup at merchant location
+- `Spree::FulfillmentProvider::PickupPoint` — marks ready-for-pickup at third-party point (carrier handles routing)
3rd-party examples:
- `SpreeEasyPost::FulfillmentProvider` — creates EasyPost shipments, returns labels
@@ -154,6 +161,157 @@ Spree.fulfillment_types << 'same_day_courier'
Spree.fulfillment_providers << MyApp::FulfillmentProvider::SameDayCourier
```
+### Pickup & Pickup Point architecture
+
+Industry consensus (Shopify, Medusa, Saleor): merchant pickup locations are stock locations with a flag, not a separate model. Spree follows this.
+
+**Two distinct pickup scenarios:**
+
+| Scenario | `fulfillment_type` | Location source | Address stored on Fulfillment |
+|---|---|---|---|
+| **Merchant pickup** (collect from store) | `pickup` | `StockLocation` with `pickup_enabled: true` | None — `stock_location_id` already has the address |
+| **Third-party pickup point** (InPost, DHL locker) | `pickup_point` | Provider API → ephemeral results | `pickup_point_data` JSON — frozen snapshot of selected point |
+
+#### StockLocation changes (merchant pickup)
+
+```ruby
+class Spree::StockLocation < Spree.base_class
+ KINDS = %w[warehouse store fulfillment_center].freeze
+
+ attribute :kind, :string, default: 'warehouse'
+ attribute :pickup_enabled, :boolean, default: false
+ attribute :pickup_stock_policy, :string, default: 'local' # 'local' or 'any'
+ attribute :pickup_ready_in_minutes, :integer # e.g., 120 (2 hours)
+ attribute :pickup_instructions, :text
+
+ scope :pickup_enabled, -> { where(pickup_enabled: true) }
+end
+```
+
+- `kind` — categorizes the location (warehouse, store, fulfillment_center). Open string, extensible.
+- `pickup_enabled` — whether customers can collect from this location.
+- `pickup_stock_policy` — `'local'` means only items physically in stock at this location can be picked up. `'any'` means items can be transferred from other locations (ship-to-store).
+- `pickup_ready_in_minutes` — estimated lead time shown to customer.
+- `pickup_instructions` — displayed after order placement ("Enter through the back door").
+
+#### PickupPointProvider interface (third-party pickup points)
+
+Third-party pickup points (InPost, DHL ServicePoint, UPS Access Point) are **not** stored in the database. There are 20,000+ InPost lockers in Poland alone — these are fetched from carrier APIs at checkout time and returned as ephemeral value objects.
+
+```ruby
+# Value object — not persisted
+Spree::PickupPointOption = Struct.new(
+ :external_id, # "inpost-PL-WAW-42"
+ :name, # "InPost Locker PL-WAW-42"
+ :provider, # "inpost"
+ :address, # { street:, city:, postal_code:, country_code:, lat:, lng: }
+ :opening_hours, # optional
+ :kind, # "locker", "servicepoint", "store"
+ :metadata, # provider-specific data
+ keyword_init: true
+)
+```
+
+```ruby
+module Spree
+ module PickupPointProvider
+ class Base
+ attr_reader :delivery_method
+
+ def initialize(delivery_method)
+ @delivery_method = delivery_method
+ end
+
+ # Returns nearby pickup points for a given address
+ # @param address [Spree::Address] customer's address (or lat/lng)
+ # @param limit [Integer] max results
+ # @return [Array<PickupPointOption>]
+ def find_nearby(address:, limit: 10)
+ raise NotImplementedError
+ end
+
+ # Validates a selected point is still available
+ # @param external_id [String]
+ # @return [PickupPointOption, nil]
+ def find_by_external_id(external_id)
+ raise NotImplementedError
+ end
+ end
+ end
+end
+```
+
+DeliveryMethod stores the pickup point provider class (only for `pickup_point` type):
+
+```ruby
+class Spree::DeliveryMethod < Spree.base_class
+ attribute :pickup_point_provider, :string # 'SpreeInpost::PickupPointProvider', nil for non-pickup-point methods
+
+ def pickup_point_provider_instance
+ return nil unless pickup_point_provider.present?
+ pickup_point_provider.constantize.new(self)
+ end
+end
+```
+
+#### How the selected pickup point is stored
+
+When the customer selects a third-party pickup point, its data is frozen as JSON on the Fulfillment. No FK — the data is ephemeral from the provider:
+
+```ruby
+class Spree::Fulfillment < Spree.base_class
+ # For pickup_point fulfillments — stores the selected point snapshot
+ attribute :pickup_point_data, :json
+ # {
+ # external_id: "inpost-PL-WAW-42",
+ # name: "InPost Locker PL-WAW-42",
+ # provider: "inpost",
+ # address: { street: "ul. Marszałkowska 1", city: "Warsaw", postal_code: "00-001", country_code: "PL" }
+ # }
+end
+```
+
+#### Store API: pickup point selection flow
+
+```
+1. GET /delivery_methods?fulfillment_type=pickup_point
+ → Returns delivery methods that use pickup point providers
+
+2. GET /delivery_methods/:id/pickup_points?latitude=52.23&longitude=21.01
+ → Calls the method's PickupPointProvider.find_nearby
+ → Returns list of PickupPointOption objects
+
+3. POST /checkout/select_delivery_method
+ { delivery_method_id: "dm_xxx", pickup_point_external_id: "inpost-PL-WAW-42" }
+ → Validates point via provider.find_by_external_id
+ → Stores pickup_point_data on Fulfillment
+```
+
+#### Store API: merchant pickup flow
+
+```
+1. GET /delivery_methods?fulfillment_type=pickup
+ → Returns delivery methods for merchant pickup
+
+2. GET /delivery_methods/:id/pickup_locations
+ → Returns StockLocations with pickup_enabled that have stock for cart items
+
+3. POST /checkout/select_delivery_method
+ { delivery_method_id: "dm_xxx", stock_location_id: "sl_abc" }
+ → Sets fulfillment.stock_location_id
+```
+
+#### Summary table
+
+| | **Merchant pickup** | **Third-party pickup point** |
+|---|---|---|
+| `fulfillment_type` | `pickup` | `pickup_point` |
+| Location model | `StockLocation` (with `pickup_enabled`) | None — ephemeral from provider API |
+| Provider interface | N/A (built-in) | `PickupPointProvider::Base` |
+| Stored on Fulfillment | `stock_location_id` (existing FK) | `pickup_point_data` (JSON) |
+| Stock validation | Yes (`pickup_stock_policy: 'local'` or `'any'`) | No (carrier handles routing) |
+| Address for customer | `stock_location.address` | `pickup_point_data['address']` |
+
## Design Details
### DeliveryMethod model
@@ -189,10 +347,12 @@ class Spree::DeliveryMethod < Spree.base_class
# Fulfillment type: open string
attribute :fulfillment_type, :string, default: 'shipping'
attribute :fulfillment_provider, :string, default: 'Spree::FulfillmentProvider::Manual'
+ attribute :pickup_point_provider, :string # only for pickup_point type, e.g. 'SpreeInpost::PickupPointProvider'
scope :by_fulfillment_type, ->(type) { where(fulfillment_type: type) }
scope :shipping, -> { by_fulfillment_type('shipping') }
scope :pickup, -> { by_fulfillment_type('pickup') }
+ scope :pickup_point, -> { by_fulfillment_type('pickup_point') }
scope :digital, -> { by_fulfillment_type('digital') }
scope :local_delivery, -> { by_fulfillment_type('local_delivery') }
@@ -212,10 +372,19 @@ class Spree::DeliveryMethod < Spree.base_class
fulfillment_type == 'pickup'
end
+ def pickup_point?
+ fulfillment_type == 'pickup_point'
+ end
+
def requires_address?
!digital? && !pickup?
end
+ def pickup_point_provider_instance
+ return nil unless pickup_point_provider.present?
+ pickup_point_provider.constantize.new(self)
+ end
+
def provider
@provider ||= fulfillment_provider.constantize.new
end
@@ -232,6 +401,9 @@ class Spree::Fulfillment < Spree.base_class
belongs_to :address, class_name: 'Spree::Address', optional: true # nil for pickup/digital
belongs_to :stock_location, -> { with_deleted }, class_name: 'Spree::StockLocation'
+ # For pickup_point fulfillments — frozen snapshot of selected third-party point
+ attribute :pickup_point_data, :json
+
has_many :fulfillment_items, class_name: 'Spree::FulfillmentItem', dependent: :delete_all
has_many :variants, through: :fulfillment_items
has_many :delivery_rates, -> { order(:cost) }, class_name: 'Spree::DeliveryRate', dependent: :delete_all
@@ -270,6 +442,7 @@ class Spree::Fulfillment < Spree.base_class
scope :by_fulfillment_type, ->(type) { where(fulfillment_type: type) }
scope :digital, -> { by_fulfillment_type('digital') }
scope :pickup, -> { by_fulfillment_type('pickup') }
+ scope :pickup_point, -> { by_fulfillment_type('pickup_point') }
scope :shipping, -> { by_fulfillment_type('shipping') }
def digital?
@@ -280,6 +453,10 @@ class Spree::Fulfillment < Spree.base_class
fulfillment_type == 'pickup'
end
+ def pickup_point?
+ fulfillment_type == 'pickup_point'
+ end
+
def delivery_method
selected_delivery_rate&.delivery_method
end
@@ -426,9 +603,15 @@ class RenamShippingToDeliveryAndFulfillment < ActiveRecord::Migration[7.2]
add_column :spree_delivery_methods, :fulfillment_provider, :string, null: false, default: 'Spree::FulfillmentProvider::Manual'
add_index :spree_delivery_methods, :fulfillment_type
+ # Pickup point provider on delivery methods (only for pickup_point type)
+ add_column :spree_delivery_methods, :pickup_point_provider, :string
+
# Add fulfillment_type to fulfillments (copied from selected delivery method)
add_column :spree_fulfillments, :fulfillment_type, :string
+ # Pickup point data on fulfillments (frozen snapshot of selected third-party point)
+ add_column :spree_fulfillments, :pickup_point_data, :json
+
# Add fulfillment_types to product_types (from product-types plan)
add_column :spree_product_types, :fulfillment_types, :string, null: false, default: 'shipping'
# Stored as comma-separated or JSON array depending on DB
@@ -443,6 +626,14 @@ class RenamShippingToDeliveryAndFulfillment < ActiveRecord::Migration[7.2]
[:delivery_method_id, :stock_location_id],
unique: true, name: 'idx_dm_stock_locations_unique'
+ # StockLocation: pickup capabilities
+ add_column :spree_stock_locations, :kind, :string, null: false, default: 'warehouse'
+ add_column :spree_stock_locations, :pickup_enabled, :boolean, null: false, default: false
+ add_column :spree_stock_locations, :pickup_stock_policy, :string, null: false, default: 'local'
+ add_column :spree_stock_locations, :pickup_ready_in_minutes, :integer
+ add_column :spree_stock_locations, :pickup_instructions, :text
+ add_index :spree_stock_locations, :pickup_enabled
+
# Fulfillment: rename shipped_at → fulfilled_at
rename_column :spree_fulfillments, :shipped_at, :fulfilled_at
@@ -497,15 +688,18 @@ rake spree:migrate_shipping_to_delivery
### Phase 4: FulfillmentProvider interface
-- Create `Spree::FulfillmentProvider::Base`, `::Manual`, `::Digital`, `::Pickup`
+- Create `Spree::FulfillmentProvider::Base`, `::Manual`, `::Digital`, `::Pickup`, `::PickupPoint`
+- Create `Spree::PickupPointProvider::Base` and `Spree::PickupPointOption` struct
- Wire providers into Fulfillment state machine transitions
- Update `Spree.fulfillment_providers` registry
### Phase 5: API + serializer updates
- All API endpoints renamed: `/shipments` → `/fulfillments`, `/shipping_methods` → `/delivery_methods`, `/shipping_rates` → `/delivery_rates`
-- New fields: `fulfillment_type`, `pickup_locations` on delivery methods
-- New endpoint: `GET /delivery_methods/:id/pickup_locations`
+- New fields: `fulfillment_type`, `pickup_locations`, `pickup_point_provider` on delivery methods
+- New fields: `pickup_point_data` on fulfillments
+- New endpoint: `GET /delivery_methods/:id/pickup_locations` (merchant pickup — returns StockLocations)
+- New endpoint: `GET /delivery_methods/:id/pickup_points?latitude=X&longitude=Y` (third-party — calls PickupPointProvider)
- Run typelizer pipeline
### Phase 6: Cleanup (6.1)
diff --git a/docs/plans/6.0-product-types.md b/docs/plans/6.0-product-types.md
index 775873608b..862f30dbb7 100644
--- a/docs/plans/6.0-product-types.md
+++ b/docs/plans/6.0-product-types.md
@@ -4,11 +4,13 @@
**Target:** Spree 6.0
**Depends on:** Metafields system (shipped in 5.4), Taxon → Category rename (6.0)
**Author:** Damian + Claude
-**Last updated:** 2026-03-16
+**Last updated:** 2026-03-26
## Summary
-Rename and extend the existing `Spree::Prototype` model into `Spree::ProductType` — a persistent, schema-defining association on Product. Today Prototype is a fire-and-forget creation template (copies option types and taxons, then has no ongoing relationship with the product). ProductType becomes the long-lived type that defines what option types, categories, and metafield definitions a product has, driving admin UI form generation and enabling type-aware filtering.
+Rename and extend the existing `Spree::Prototype` model into `Spree::ProductType` — a persistent, schema-defining association on Product. Today Prototype is a fire-and-forget creation template (copies option types and taxons, then has no ongoing relationship with the product). ProductType becomes a **live template** that defines what option types, categories, and metafield definitions a product has, driving admin UI form generation and enabling type-aware filtering.
+
+ProductType acts as an **authoritative template** for option types: changes to a type's option types propagate to all products of that type. Products may add extra option types beyond what the type provides, but cannot remove type-defined ones. This ensures catalog consistency (all "T-Shirts" share Color and Size) while allowing per-product flexibility (one T-shirt can add "Sleeve Length").
This closes Spree's biggest functional gap in catalog modeling, while building on existing infrastructure rather than starting from scratch.
@@ -27,6 +29,7 @@ This closes Spree's biggest functional gap in catalog modeling, while building o
- **Rename only, no new table.** `Spree::Prototype` → `Spree::ProductType`, `spree_prototypes` → `spree_product_types`. Existing join tables renamed accordingly. No data loss.
- **Persistent `belongs_to`.** Product gets `product_type_id` FK (nullable — existing products don't require a type). The current `attr_accessor :prototype_id` + fire-and-forget callback is replaced by a real association.
- **ProductType defines OptionTypes, Categories, and MetafieldDefinitions.** Three M2M associations on ProductType, all carried over or added via join tables.
+- **ProductType is a live template for option types.** Option types defined on a ProductType propagate to all products of that type. Adding an option type to the type adds it to all its products; removing one removes it from products (with safety checks). Products can add extra option types beyond the type's set but cannot remove type-defined ones. This is "additive override" — the type is the floor, not the ceiling.
- **MetafieldDefinition association carries `required` and `sort_order`.** The join table `spree_product_type_metafield_definitions` determines which metafield definitions a product type uses, whether they're required, and their display order. This is the schema enforcement layer.
- **Prefix ID: `pt_`.** Replaces `proto_`.
- **No shared value pools in this phase.** Metafield values remain per-resource strings (no shared AttributeValue rows). Faceted filtering via shared pools is a future enhancement tracked in Open Questions.
@@ -90,6 +93,31 @@ class Spree::OptionTypeProductType < Spree.base_class
validates :product_type, :option_type, presence: true
validates :product_type_id, uniqueness: { scope: :option_type_id }
+
+ # Live template: propagate to all products of this type
+ after_create :add_option_type_to_products
+ after_destroy :remove_option_type_from_products
+
+ private
+
+ # Add option type to all products of this type that don't already have it
+ def add_option_type_to_products
+ product_type.products.find_each do |product|
+ product.option_types << option_type unless product.option_types.include?(option_type)
+ end
+ end
+
+ # Remove option type from products — only if no variants use values from it
+ def remove_option_type_from_products
+ product_type.products.find_each do |product|
+ has_variants_using = product.variants.joins(:option_values)
+ .where(spree_option_values: { option_type_id: option_type.id })
+ .exists?
+ next if has_variants_using
+
+ product.option_types.delete(option_type)
+ end
+ end
end
```
@@ -111,19 +139,48 @@ class Spree::Product < Spree.base_class
belongs_to :product_type, class_name: 'Spree::ProductType', optional: true
# Remove: attr_accessor :prototype_id
- # Keep creation-time behavior: copy option_types + categories from type
- after_create :add_associations_from_product_type
+ # On creation, sync option_types + categories from type
+ after_create :sync_associations_from_product_type
# New: validate required metafields on completion/activation
validate :required_metafields_present, if: :active?
+ # Prevent removing option types that come from the product type
+ validate :type_option_types_present, if: :product_type
+
+ # Check if an option type is inherited from the product type (cannot be removed)
+ def type_option_type?(option_type)
+ product_type&.option_types&.include?(option_type)
+ end
+
+ # Returns option types added beyond what the product type provides
+ def extra_option_types
+ return option_types unless product_type
+
+ option_types - product_type.option_types
+ end
+
private
- def add_associations_from_product_type
+ def sync_associations_from_product_type
return unless product_type
- self.option_types = product_type.option_types if option_types.empty?
- self.taxons = product_type.categories if taxons.empty?
+ # Add type's option types (additive — keeps any already assigned)
+ product_type.option_types.each do |ot|
+ option_types << ot unless option_types.include?(ot)
+ end
+
+ # Add type's categories (additive)
+ product_type.categories.each do |cat|
+ taxons << cat unless taxons.include?(cat)
+ end
+ end
+
+ def type_option_types_present
+ missing = product_type.option_types - option_types
+ missing.each do |ot|
+ errors.add(:option_types, "cannot remove type-defined option type: #{ot.name}")
+ end
end
def required_metafields_present
@@ -184,16 +241,22 @@ GET /api/v3/store/products/:id?expand=product_type
### Admin UI (React SPA)
When editing a product with a ProductType:
-1. Query ProductType's `metafield_definitions` (with `required` and `sort_order`)
-2. Render metafield form fields in `sort_order`, grouped by namespace
-3. Show required indicators on required fields
-4. Validate required metafields before allowing product activation
+1. Query ProductType's `option_types` and `metafield_definitions` (with `required` and `sort_order`)
+2. Show type-defined option types as locked (cannot remove), extra option types as removable
+3. Render metafield form fields in `sort_order`, grouped by namespace
+4. Show required indicators on required fields
+5. Validate required metafields before allowing product activation
When creating a product:
1. Optional ProductType selector
-2. Selecting a type pre-fills option types and categories
+2. Selecting a type adds the type's option types and categories (live — not just a copy)
3. Shows the metafield form immediately
+When editing a ProductType:
+1. Adding an option type propagates to all products of that type
+2. Removing an option type removes it from products (blocked if variants use values from it)
+3. UI shows affected product count before confirming destructive changes
+
## Migration Path
### Phase 1: Rename (non-breaking)
@@ -276,6 +339,7 @@ This is advisory, not automatic — product_type_id stays nullable.
- **Do not add `prototype_id` as a persisted column.** The rename migration will add `product_type_id` instead.
- **New MetafieldDefinitions should be resource_type-aware.** When creating definitions intended for products, use `resource_type: 'Spree::Product'` — this will matter when ProductType filters which definitions are available.
- **Don't create a separate Attribute/Property system.** Everything builds on existing Metafields. No new EAV tables.
+- **Don't build new Product ↔ OptionType management that bypasses ProductType.** New admin UI for managing a product's option types should be type-aware: type-defined option types are locked, only extra option types can be freely added/removed.
## Open Questions
@@ -287,6 +351,8 @@ This is advisory, not automatic — product_type_id stays nullable.
4. **Store API filtering by ProductType.** Should `GET /api/v3/store/products?filter[product_type_id]=pt_xxx` be a first-class filter? Useful for storefronts that want to show type-specific browse pages.
+5. **Option type removal safety.** When removing an option type from a ProductType, the current design skips products whose variants use values from that option type. Should the admin API return a list of blocked products so the admin can resolve them, or should it hard-block the removal entirely until all variants are cleaned up?
+
## References
- Current Prototype model: `spree/core/app/models/spree/prototype.rb`