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
Make the visibility backfill one-shot
Damian Legawiec1e8340512d25
diff --git a/docs/plans/6.0-fulfillment-and-delivery.md b/docs/plans/6.0-fulfillment-and-delivery.mdindex 2732170493..6b0abaf105 100644--- a/docs/plans/6.0-fulfillment-and-delivery.md+++ b/docs/plans/6.0-fulfillment-and-delivery.md@@ -21,7 +21,7 @@ Three changes in one:**Phases 1a, 1b, 2, 3, 4 and 5 are implemented.** Verified in code: the rename migrations (`20260728000004/5`) including every FK and the `orders` column pair; model renames with one-release deprecation shells (`Spree::Shipment`, `ShippingMethod`, `InventoryUnit`, `FulfilmentChanger` are constant aliases); `Package#eligible_delivery_methods` + `Stock::Splitter::FulfillmentType`; `ProductType#fulfillment_types` with registry-backed inclusion validation; all five providers plus `PickupPointProvider::Base`; the `Spree.fulfillment_types` / `Spree.fulfillment_providers` registries; lifecycle events with `shipment.*` dual-emit and `order.fulfilled` / `Order#fully_fulfilled?`; dual `cart_id`/`order_id` owner with exactly-one validation; `Estimator` location gating via `serves_location?`; pickup discovery endpoints and the `fulfillment_providers` discovery route; admin delivery-method and delivery-zone CRUD; `FulfillmentMailer` (with a `ShipmentMailer` shell); `return_items.fulfillment_item_id`; and both data rake tasks wired into the 5.6→6.0 upgrade manifest.-**Landed 2026-08-05** (this plan's remaining 6.0 cleanup): `storefront_visible` is now the authoritative column on DeliveryMethod — the model no longer includes `Spree::DisplayOn`, the boolean carries a `null: false, default: true` DB default, and `display_on` survives only as a deprecated reader/writer pair. The magic-integer `DISPLAY_ON_FRONT_END`/`BACK_END` rate filter became `DeliveryMethod::STOREFRONT` / `BACKOFFICE` with `#available_to?(audience)` (`#available_to_display?` kept as a deprecated bridge that still accepts the old integers). `shipping_method_categories` / `shipping_categories` are flagged `deprecated: true`; the product factory no longer auto-assigns a ShippingCategory; and the product factory no longer auto-assigns a ShippingCategory.+**Landed 2026-08-05** (this plan's remaining 6.0 cleanup): `storefront_visible` is now the authoritative column on DeliveryMethod — the model no longer includes `Spree::DisplayOn`, the boolean carries a `null: false, default: true` DB default, and `display_on` survives only as a deprecated reader/writer pair. The magic-integer `DISPLAY_ON_FRONT_END`/`BACK_END` rate filter became `DeliveryMethod::STOREFRONT` / `BACKOFFICE` with `#available_to?(audience)` (`#available_to_display?` kept as a deprecated bridge that still accepts the old integers). `shipping_method_categories` / `shipping_categories` are flagged `deprecated: true`, and the product factory no longer auto-assigns a ShippingCategory. The visibility backfill **clears `display_on` as it converts**, making the conversion one-shot — otherwise a re-run would silently revert a visibility change an admin made after the upgrade.**CSV `shipping_category` is a clean break, not a bridge (2026-08-05).** The column is gone from both the import schema and the export presenter, replaced by `product_type` (export never had it before, so import and export now agree). Rationale: ShippingCategory already had **zero** live behavior — delivery eligibility runs entirely through `ProductType#fulfillment_types` via `Package#eligible_delivery_methods`, and nothing reads the category for routing. Carrying a deprecated CSV column plus a name-matching bridge would have been maintaining a translation layer onto a model that no longer decides anything. Also removed as part of the same sweep: `shipping_category_id` from permitted product attributes (replaced by `product_type_id`, which was never permitted — a real gap), the `shipping_category` Ransack association on Product (now `product_type`), the dead `Store#default_shipping_category`/`#digital_shipping_category` helpers, `PermittedAttributes.shipping_category_attributes`, and the two dangling API serializer registrations (the admin one pointed at a class that never existed).diff --git a/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml b/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.ymlindex 73e1d743d0..6df9993fbf 100644--- a/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml+++ b/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml@@ -92,7 +92,9 @@ steps:become digital + the Digital provider) and copies the type onto existingfulfillments, assigns the Digital product type to products indigital-only shipping categories, and converts display_on into the- storefront_visible boolean. Idempotent.+ storefront_visible boolean. Idempotent — the visibility conversion+ clears display_on as it goes, so re-running never overwrites a+ visibility change made in the admin after the upgrade.BREAKING — product CSV: the 'shipping_category' column is gone from bothimport and export, replaced by 'product_type'. Update saved importdiff --git a/spree/core/lib/tasks/delivery_migration.rake b/spree/core/lib/tasks/delivery_migration.rakeindex 9bcd85c025..6e74ba50cd 100644--- a/spree/core/lib/tasks/delivery_migration.rake+++ b/spree/core/lib/tasks/delivery_migration.rake@@ -87,18 +87,24 @@ namespace :spree doend# 5. display_on → storefront_visible boolean. The new column defaults to- # true, so only back_end rows need flipping. Narrowing on the legacy- # display_on column keeps re-runs safe: nothing writes display_on after- # the upgrade, so a later admin change to storefront_visible stands.+ # true, so only back_end rows need flipping. Each converted row has its+ # legacy display_on cleared, which makes the conversion strictly one-shot:+ # a re-run finds nothing left to convert, so a later admin change to+ # storefront_visible is never undone.if Spree::DeliveryMethod.column_names.include?('display_on')+ # front_end-only had no real workflow and folds into visible — but it+ # also means staff can now see those methods, so name them explicitly+ # before the value is cleared.+ front_end_only = Spree::DeliveryMethod.unscoped.where(display_on: 'front_end').pluck(:id, :name)+count = Spree::DeliveryMethod.unscoped.- where(display_on: 'back_end', storefront_visible: true).- update_all(storefront_visible: false)+ where(display_on: 'back_end').+ update_all(storefront_visible: false, display_on: nil)say.call "spree_delivery_methods.storefront_visible: #{count} back_end rows set to false"- # front_end-only had no real workflow and folds into visible — but it- # also means staff can now see those methods, so name them explicitly.- front_end_only = Spree::DeliveryMethod.unscoped.where(display_on: 'front_end').pluck(:id, :name)+ converted = Spree::DeliveryMethod.unscoped.where.not(display_on: nil).update_all(display_on: nil)+ say.call "spree_delivery_methods.display_on: #{converted} remaining rows cleared (conversion is one-shot)"+if front_end_only.any?say.call "spree_delivery_methods: #{front_end_only.size} front_end-only rows are now visible to staff as well as customers:"front_end_only.each { |id, name| say.call " - ##{id} #{name}" }diff --git a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rbindex 932abe7707..745f71d914 100644--- a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb+++ b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb@@ -63,6 +63,22 @@ describe '6.0 data migration tasks' doexpect(digital_method.read_attribute(:storefront_visible)).to be(false)end+ # The conversion is one-shot: it clears display_on as it goes, so a later+ # re-run cannot undo a visibility change an admin made in the meantime.+ it 'does not revert a later admin visibility change on re-run' do+ method = create(:shipping_method)+ method.update_columns(storefront_visible: true, display_on: 'back_end')++ run_task('spree:migrate_shipping_to_delivery')+ expect(method.reload.read_attribute(:storefront_visible)).to be(false)+ expect(method.read_attribute(:display_on)).to be_nil++ method.update_columns(storefront_visible: true)+ run_task('spree:migrate_shipping_to_delivery')++ expect(method.reload.read_attribute(:storefront_visible)).to be(true)+ end+it 'is idempotent' dofulfillment.update_columns(status: 'shipped')run_task('spree:migrate_shipping_to_delivery')