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
Record that product-scoped writes may set collection membership
Damian Legawiec1b07664ed158
diff --git a/docs/plans/6.0-replace-taxons-with-categories.md b/docs/plans/6.0-replace-taxons-with-categories.mdindex 7f2d5c9920..fb4582acfa 100644--- a/docs/plans/6.0-replace-taxons-with-categories.md+++ b/docs/plans/6.0-replace-taxons-with-categories.md@@ -414,7 +414,7 @@ POST /api/v3/admin/products/bulk_add_to_collections # { ids: [...], collPOST /api/v3/admin/products/bulk_remove_from_collections # { ids: [...], collection_ids: [...] }```-Unlike categories (a nested set that needs an explicit `reposition` with a target parent + index), collections are a flat `acts_as_list`, so the collection's own order is reordered by sending `position` on `PATCH /collections/:id` — matching the SPA `<ResourceTable reorder>` convention and the sibling flat resource (`payment_methods`). Only the **nested** membership (`ProductCollection.position`) keeps a dedicated `reposition`. Admin collection endpoints require the new `read_collections` / `write_collections` API-key scopes (JWT admins use CanCanCan as usual).+Unlike categories (a nested set that needs an explicit `reposition` with a target parent + index), collections are a flat `acts_as_list`, so the collection's own order is reordered by sending `position` on `PATCH /collections/:id` — matching the SPA `<ResourceTable reorder>` convention and the sibling flat resource (`payment_methods`). Only the **nested** membership (`ProductCollection.position`) keeps a dedicated `reposition`. Admin collection endpoints require the new `read_collections` / `write_collections` API-key scopes (JWT admins use CanCanCan as usual). **Membership is deliberately not gated behind `write_collections`:** `collection_ids` on a product write and the `/products/bulk_*_collections` endpoints are reachable with `write_products`, because filing a product into its groupings is part of maintaining the product — the same rule `category_ids` has always followed. Creating or configuring a collection (its rules, sort order, name) still requires `write_collections`.Nested `rules` are written through a model-level **sync setter** (`Spree::Collection#rules=`), mirroring `Spree::OptionType#option_values=`: the client sends the full desired rule set under `rules` (prefixed `crule_` ids update, id-less entries create, omitted rules are destroyed), decoded and applied in the parent's save transaction. `normalize_params` is deliberately not called on this controller so `rules` reaches the setter rather than being rewritten to `rules_attributes`.diff --git a/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/products_controller.rbindex b8e0d7ee86..ef36aa4ee7 100644--- a/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb@@ -184,6 +184,13 @@ module Spree# Manual collection membership only — the model setter ignores# incoming automatic collections and preserves the product's# existing ones, since those are materialized from their rules.+ #+ # Deliberately reachable with `write_products` rather than+ # `write_collections`: filing a product into its groupings is part+ # of maintaining the product, which is why `category_ids` and the+ # bulk membership endpoints have always worked this way too.+ # Creating or configuring a collection still needs+ # `write_collections`.collection_ids: [],metadata: {},prices: [:amount, :compare_at_amount, :currency],