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.

19.7 KB
Raw Blame

Seller Product Submission and Review

Status: Implemented (2026-08-26, PR #14497) — proposed/rejected added through add_status, the Products::Propose/Approve/Reject workflows live beside the existing trio, Spree::ProductSubmission records each decision on a row the seller cannot reach, the permission catalog gained product_types and publishing, the seller branch moves status only through member actions (PATCH /seller/products/:id/submit|draft|archive, status dropped from permitted params), and the operator branch gained PATCH /admin/products/:id/approve|reject plus the review buttons. Remaining: lifting the rest of the product form cards into @spree/dashboard-ui — only status-card.tsx moved, so the seller panel still renders its own product page rather than the shared cards Target: Spree 6.0 Depends on: 6.0-multi-vendor-marketplace.md, 6.0-seller-onboarding-requirements.md, 6.0-admin-rbac.md, 6.0-product-types.md Author: Damian Legawiec Last updated: 2026-08-27

Summary

A seller can list a product but must not publish one. Today they can: the seller products endpoint permits status as a plain attribute, so a seller sends status: 'active' and their product is live in the marketplace catalog with nobody having looked at it. This plan closes that by giving products a review lifecycle — the seller submits, the operator decides — and by splitting the two capabilities that currently ride the products permission key and should not: managing product types, and publishing to sales channels.

It also gives the seller panel the same product form the operator's dashboard has, rather than the four-field placeholder it ships today. The form cards move into @spree/dashboard-ui so both dashboards render one definition and cannot drift.

Key Decisions (do not deviate without discussion)

  1. Two new statuses, proposed and rejected, added through add_status — additive by design, so core workflows guarding on core statuses keep passing. We keep our own vocabulary: active is what the marketplace reference calls published, and renaming it would churn every existing consumer for no gain. archived is untouched.

  2. The lifecycle is workflows, never a state machine. Products::Propose, Products::Approve and Products::Reject join the existing Activate / Archive / Draft trio, each with a leading validate hook. There is no transition graph — that would be a state machine by another name (see 6.0-service-workflows.md).

  3. status stops being a writable attribute on the seller branch. A seller moves a product with an explicit member action, never by sending a status in an update payload. The operator's branch keeps the plain attribute for the operator's own catalog — but not for a product in review (revised 2026-08-26): a direct status write or bulk_status_update on a proposed or rejected product refuses, because leaving review is a decision, and a decision that skips Approve/Reject records no reviewer and closes no submission row. A bulk approve, if ever needed, is a loop over the workflow, never update_all.

  4. A seller may return an active product to draft or archived, but may never reach active themselves. Taking your own listing down is not a review decision; putting it up is. This mirrors the legacy gem, which granted activate only for products already active.

  5. product_types becomes its own catalog resource, read-only for the seller audience. A seller fills in a type's custom fields; they do not define types. Per 6.0-admin-rbac.md, a new sensitive capability gets its own catalog entry rather than riding an existing key.

    Revised 2026-09-01: read-only for a seller to pick from, not merely to look at — a seller assigns a type to their own product, and a delivery profile with it. The type is the template that hands them option types and a delivery profile, and the profile is what makes their goods quotable; on 2026-08-26 both had left the branch with the Categorization card, and every seller product was landing on the store's default profile. See 6.0-multi-vendor-marketplace.md, Decision 13 and the 2026-09-01 resolved decisions.

  6. ProductPublication moves off the products key onto a publishing resource with no seller audience. Which channels carry a product is marketplace merchandising, not a seller's to set.

  7. A seller files a product into the marketplace's groupings; they do not extend them. Revised 2026-08-26 (recorded 2026-09-01): they do not file it either — categories, collections and tags all left the seller branch with the Categorization card, since filing a listing is the operator's, done at review. The two fields that came back on 2026-09-01 are the product type and the delivery profile, which are not filing. The original reasoning stays below for the record. category_ids and collection_ids are writable — filing a product is part of maintaining it, which is why the operator's own endpoint permits them under write_products rather than write_collections. The categories and collections themselves are read-only pickers.

    Tags are not writable at all. They are tenanted to the store (acts_as_taggable_tenant :store_id), so a seller typing a new one adds a term to the marketplace's shared vocabulary rather than labelling their own product. Verified against both marketplace platforms we looked at: one exposes categories, collections, tags, types and attributes to sellers as read-only, with a single endpoint for placing a seller's own products into an existing category; the other's category tree and attribute schema are operator-only imports that sellers map onto. The legacy spree_multi_vendor gem took the same line (cannot :manage_tags, taxonomy index/show only).

  8. Custom field values are seller-writable; definitions are not. Spree::CustomField stays on products; Spree::MetafieldDefinition is operator-only, and the seller panel renders the definitions it is given without the "add a definition" affordance.

  9. The product form cards live in @spree/dashboard-ui, headless and generic over the record type — data by props, no SDK import, no provider import. MediaCard's one adminClient.media.list call becomes an injected prop. This is what makes "the same as in dashboard" true by construction rather than by discipline.

  10. No JSON preview on the seller panel. It is an opt-in prop on the page shell; the seller form omits it.

  11. The review decision is a row, not a note on the product (revised 2026-08-26). Each submission and each decision on it is a Spree::ProductSubmission: who submitted, who decided, when, and the seller-visible note. The row records the trail — it never replaces the product's status, which stays the operational truth, exactly as a seller's own status lives on the seller while SellerRequirementSubmission rows carry the history. The original design put the rejection reason in product.metadata, which failed on three counts, in descending order: the seller products endpoint permits metadata: {}, so an ordinary save by the seller replaced the hash and silently erased the operator's reason (proven over HTTP — the status stayed rejected with no recoverable reason); a second rejection overwrote the first, so nobody could see a seller sent back three times for the same thing; and there was nowhere to record who decided — Approve and Reject both already accept reviewer: and the admin controller already passes the current user, which both then discarded. The rejected rationale ("a table for one string") survives none of these: the row is not one string, it is the audit trail.

  12. The name is ProductSubmission, and Spree::ProductReview stays reserved for customer ratings. Core's own Spree.permissions documentation uses SpreeReviews::Review under a reviews catalog resource as the canonical extension example, so taking the obvious name for an operator decision would displace it permanently. The row is named for the seller's act — the decision rides on it — exactly as Spree::SellerRequirementSubmission is, and the statuses read naturally against it: a submission is pending or withdrawn; a "withdrawn review" never was. Prefix prodsub, parallel to selsub.

Design Details

Status lifecycle

draft ──propose──▶ proposed ──approve──▶ active
  ▲                    │
  │                    └──reject───▶ rejected
  │                                     │
  └──────────── seller revises ─────────┘

active ──▶ draft | archived        (seller may do this)
active ──▶ proposed                (never — approval is not re-requested)
  • draft — the seller is still working. Not visible in the storefront.
  • proposed — submitted, awaiting the operator. Not visible in the storefront.
  • active — approved and on sale. Unchanged meaning.
  • rejected — the operator turned it down. Not visible in the storefront. The seller edits and submits again, which returns it to proposed.
  • archived — withdrawn. Unchanged meaning.

Only active is storefront-visible, which is already how ProductScopes works — the new statuses inherit that for free precisely because they are not active.

Auto-approval. A store preference (auto_approve_seller_products) chains Propose straight into Approve, matching how auto_approve_sellers works in 6.0-seller-onboarding-requirements.md. A marketplace that does not want to review every listing sets it once.

Rejection reason. Reject takes a reason: and records it on the submission row, so the seller sees why. (It lived briefly in product.metadata, which the seller could overwrite — Key Decision 11 records why that changed.)

The submission record

class Spree::ProductSubmission < Spree.base_class
  belongs_to :product
  belongs_to :submitted_by, class_name: Spree.admin_user_class.to_s, optional: true
  belongs_to :reviewed_by,  class_name: Spree.admin_user_class.to_s, optional: true

  has_status :pending, :approved, :rejected, :withdrawn, default: :pending
end

Columns: product_id, status, submitted_by_id, reviewed_by_id, reviewed_at, review_note (text — the operator's, seller-visible; named as on SellerRequirementSubmission, leaving note free for a future seller-side message), metadata, timestamps. No store_id: the store is derived through the product, exactly as SellerRequirementSubmission derives it through the seller. Index (product_id, created_at) — the latest row for a product is the one that counts, the ones before it are how the marketplace got there.

Append-only, and every exit from review closes the open row. Propose opens a pending row stamping submitted_by; Approve and Reject close it with reviewed_by/reviewed_at; and a seller withdrawing a submission — Draft or Archive on a proposed product — closes it withdrawn, so a pending row always means "awaiting a decision", never "abandoned". A product submitted, rejected, revised and resubmitted leaves the full sequence. Approvals are recorded as deliberately as rejections: "when did this go on sale, and who allowed it" is the question with the longest tail.

Auto-approval says so. The auto_approve_seller_products chain approves with no human in the loop, and its row records metadata: { auto_approved: true } — an approved row with a blank reviewer must mean "this store does not review listings", never "someone approved from the console and we lost their name".

One note field, seller-visible. An operator-only note is a real want (an approver recording why they allowed something borderline) but has no caller yet, and a second column is additive later — as is note for the seller's own message, per the SellerRequirementSubmission layout. The reason stays free text in 6.0 — a controlled reason vocabulary is the mature shape, and it hangs off this row whenever a real need arrives.

Core

  • Spree::Product: add_status :proposed, after: :draft and add_status :rejected, after: :proposed. STATUSES stays as-is; the class attribute is what has_status validates against.
  • New scopes fall out of has_status automatically (.proposed, .rejected).
  • Spree::Products::Propose, ::Approve, ::Reject — workflows on the Activate template, each publishing an event (product.proposed, product.approved, product.rejected).
  • Registered as Spree.product_propose_workflow and friends in Spree::Dependencies.
  • Spree::ProductSubmission + the row-writing steps in Propose, Approve, Reject, Draft and Archive (the last two only when leaving proposed).

API

Seller branch:

  • PATCH /seller/products/:id/submit → Products::Propose
  • PATCH /seller/products/:id/draft → Products::Draft (take down)
  • PATCH /seller/products/:id/archive → Products::Archive
  • status removed from permitted_params.
  • GET /seller/product_types — read-only, for the type picker.
  • GET /seller/custom_field_definitions — read-only, so the form can render the fields a seller fills in.

Admin branch:

  • PATCH /admin/products/:id/approve → Products::Approve
  • PATCH /admin/products/:id/reject → Products::Reject (takes reason)
  • A proposed filter on the products index so an operator can find the queue.
  • The admin product serializer embeds the latest submission (submission: status, review note, reviewer, timestamps); a full-trail endpoint waits for a real need. The seller serializer exposes the latest review_note only — never the reviewer's identity.

Permissions

register_scope(:product_types, group: :catalog,
                               audiences: %i[store seller], read_only_for: %i[seller],
                               resources: -> { [Spree::ProductType] })

register_scope(:publishing, group: :catalog,
                               resources: -> { [Spree::ProductPublication] })

Spree::ProductType and Spree::ProductPublication leave the products subject list. Approving and rejecting are write_products on the admin branch — an operator who may edit the catalog may decide what enters it.

Upgrade note. The seeded admin role is unaffected: it holds no explicit keys and takes full access, so it picks up new catalog resources automatically. A custom role that was granted write_products does not inherit write_product_types or write_publishing — splitting a capability means the narrower grants have to be re-issued, which is the operator's call and not something an upgrade should decide for them. Per 6.0-admin-rbac.md, roles are pure data: no code path rewrites a store's saved permission arrays.

Dashboard packages

@spree/dashboard-ui gains a products/ directory holding the form cards, each headless: no adminClient, no useStore, no locale import. The two apps supply data, mutations and translated labels by prop.

The seller panel composes: General, Media, Prices, Variants, Inventory, SEO, Categorization (product type and delivery profile only — no categories, collections or tags; revised 2026-09-01), Custom Fields, Metadata, Status (restricted), Translations. It omits Publishing (channels), Tax, and the JSON preview.

StatusCard takes the allowed transitions as a prop rather than deriving them, so the seller panel offers Submit / Take down / Archive while the operator's offers the full set.

Migration Path

  1. Core statuses + the three workflows + dependency registration.
  2. Permission catalog split (product_types, publishing), with the subjects moved off products.
  3. Seller API: member actions, status dropped from permitted params, read-only product types and custom field definitions.
  4. Admin API: approve/reject + the review queue filter.
  5. Lift the form cards into @spree/dashboard-ui; repoint the operator's dashboard at them (no visual change — the same components).
  6. Build the seller product form on the shared cards.
  7. Data: nothing to migrate. Existing products keep their status; no row is proposed or rejected until somebody submits one.
  8. The submission record (implemented 2026-08-26, on the same unreleased branch): Spree::ProductSubmission + migration, Spree::ProductSubmissions::Close as the single settling path, row writes in the five workflows, review-status refusal in Products::Update (so every caller inherits it) and skip-with-a-count in bulk_status_update, Product#rejection_reason/#latest_submission, admin + seller submission serializers embedded on the product as submission. No data task and no bridge — the metadata design never shipped, so it is rewritten in place and the rejection_reason key never reaches a release.

Constraints on Current Work

  • Never permit status as a writable attribute on the seller branch. A new seller endpoint touching products must move status through a workflow.
  • Do not add Spree::ProductType or Spree::ProductPublication back to the products permission subjects. They are their own resources now.
  • A new product-form card goes into @spree/dashboard-ui, not into @spree/dashboard — otherwise the two forms drift again, which is the thing this plan exists to prevent. It must take its data by prop and import no SDK.
  • Storefront visibility keys off active only. A new status must not be added to the published scope without a deliberate decision.
  • No Product#submitted?-style helper methods beyond what has_status generates, and no columns recording review state on the product — the product's status is its state, and the review's history is the row.
  • Never store an operator decision where the subject of the decision can write. metadata on a seller-owned record is seller-writable by construction; decisions go on the submission row.
  • Approve/Reject must persist the reviewer: they are given, and a new path that moves a product out of review must run the workflows or refuse — never write status around them.

Open Questions

  • Should a proposed product be editable by the seller, or frozen until the operator decides? Leaning editable, with an edit returning it to draft so the operator never reviews a moving target. Not blocking: the first cut leaves it editable and in place.
  • Whether the operator needs a bulk approve for a seller's first batch. Part-answered (2026-08-26): bulk_status_update must NOT cover it — it writes around the review and records no reviewer, so it refuses products in review. A bulk approve, if wanted, is a loop over Approve.
  • Whether Spree::Sellers::Reject moves onto the same shape. It stores its reason in seller.metadata['rejection_reason'] identically; the erasure is proven for products and inferred (unverified) for sellers. A seller's review already has a natural home nearby (SellerRequirementSubmission carries review_note per requirement), so the fix there may be a column on the seller's review flow rather than a new model — decide when it is taken up.

References

  • docs/plans/6.0-multi-vendor-marketplace.md — the marketplace core
  • docs/plans/6.0-seller-onboarding-requirements.md — the submit-for-review pattern this mirrors (Sellers::SubmitForReview / Approve)
  • docs/plans/6.0-admin-rbac.md — why a new capability gets its own resource
  • docs/plans/6.0-service-workflows.md — why transitions are workflows
  • The legacy spree_multi_vendor gem's PermissionSets::VendorUser, which established cannot :activate and cannot :manage, ProductPublication.