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.

docs(plans): reconcile Collection admin API into taxons plan

Łukasz Adamczyk18f6eb370592
diff --git a/docs/plans/6.0-replace-taxons-with-categories.md b/docs/plans/6.0-replace-taxons-with-categories.md
index 35c523792b..6cce70544a 100644
--- a/docs/plans/6.0-replace-taxons-with-categories.md
+++ b/docs/plans/6.0-replace-taxons-with-categories.md
@@ -214,9 +214,12 @@ class Spree::Collection < Spree.base_class
has_many :product_collections, class_name: 'Spree::ProductCollection', dependent: :destroy_async
has_many :products, through: :product_collections
- # Automatic rules
- has_many :collection_rules, class_name: 'Spree::CollectionRule', dependent: :destroy
- accepts_nested_attributes_for :collection_rules, allow_destroy: true,
+ # Automatic rules. The association is named `rules` (not `collection_rules`) so the
+ # Admin API's write key equals the serializer's read key: ParamsNormalizer derives the
+ # flat nested-attributes key from the association name (`rules` → `rules_attributes`),
+ # so a `rules: [...]` payload routes correctly (read/write symmetry — see CLAUDE.md).
+ has_many :rules, class_name: 'Spree::CollectionRule', dependent: :destroy
+ accepts_nested_attributes_for :rules, allow_destroy: true,
reject_if: proc { |attrs| attrs['value'].blank? }
# Attachments
@@ -248,7 +251,7 @@ class Spree::Collection < Spree.base_class
end
def products_matching_rules(opts = {})
- return Spree::Product.none unless automatic? && collection_rules.any?
+ return Spree::Product.none unless automatic? && rules.any?
# Same logic as current Taxon#products_matching_rules
end
end
@@ -292,7 +295,7 @@ class Spree::CollectionRule < Spree.base_class
MATCH_POLICIES = %w[is_equal_to is_not_equal_to contains does_not_contain].freeze
- belongs_to :collection, class_name: 'Spree::Collection', inverse_of: :collection_rules, touch: true
+ belongs_to :collection, class_name: 'Spree::Collection', inverse_of: :rules, touch: true
validates :collection, :type, :value, presence: true
validates :match_policy, inclusion: { in: MATCH_POLICIES }, presence: true
@@ -393,10 +396,19 @@ PATCH /api/v3/admin/categories/:id/products/:product_id/reposition
# Admin API — collections PENDING (6.0)
GET /api/v3/admin/collections
POST /api/v3/admin/collections
-PATCH /api/v3/admin/collections/:id
+PATCH /api/v3/admin/collections/:id # reorder via `position` (acts_as_list reorders on save) — no separate reposition action
DELETE /api/v3/admin/collections/:id
+GET /api/v3/admin/collections/:id/products
+POST /api/v3/admin/collections/:id/products
+DELETE /api/v3/admin/collections/:id/products/:product_id
+PATCH /api/v3/admin/collections/:id/products/:product_id/reposition
+# (+ nested custom_fields and translations via concerns)
```
+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).
+
+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`.
+
Collection response (**Admin** — the Store serializer omits the merchandising config `automatic`, `rules_match_policy`, and `rules`; that's back-office state, not customer-facing):
```json
{
@@ -507,7 +519,7 @@ end
- `Spree::Collection`, `Spree::ProductCollection`, `Spree::CollectionRule` + STI `CollectionRules::{Tag,AvailableOn,Sale}`, all registered in `config.spree.collection_rules` (**mirrors the existing `config.spree.taxon_rules`**, `engine.rb`). `AvailableOn` ships with the interim legacy-column `apply`; channel-aware reimplementation is Phase 5
- `Spree::Collections::RegenerateProducts`; `AutoMatchCollections` (+ job) for event-driven regeneration on product save; `RegenerateTimeBasedJob` + `time_based_collection_rules = [AvailableOn]` registry (**net-new — no `taxon_rules` equivalent; taxons ship no scheduled refresh**) for time-relative rules — all on the `collections` queue (see Design Details → Automatic collection regeneration)
- Product: `in_collection` scope (+ ransack whitelist), `collections`/`collections_count`, `primary_category`
-- Store + Admin Collection API: `collections` controllers + serializers; dedicated `collections/:id/products`; admin nested curation + `reposition`; `/products/filters` `collection_id` param + `FiltersAggregator` `sort_order:` change (see API → Collection product listing)
+- Store + Admin Collection API: `collections` controllers + serializers; dedicated `collections/:id/products`; admin nested curation + nested `reposition` (the collection's own order reorders via `position` on update, no top-level reposition action); `read_collections`/`write_collections` API-key scopes; `/products/filters` `collection_id` param + `FiltersAggregator` `sort_order:` change (see API → Collection product listing)
- Meilisearch: index `collection_ids` + filterable/facet attrs + `build_filter_condition` + reindex
**Not in scope of this phase (or plan):**