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.

Added endpoints that move one product's status through its workflow (V-3779) (#15092)

Damian Legawiec54d32275ed22
diff --git a/.changeset/admin-sdk-product-status.md b/.changeset/admin-sdk-product-status.md
new file mode 100644
index 0000000000..9f0836f481
--- /dev/null
+++ b/.changeset/admin-sdk-product-status.md
@@ -0,0 +1,5 @@
+---
+"@spree/admin-sdk": patch
+---
+
+Added `client.products.activate`, `archive` and `draft`, which move one product to that status through its workflow, so the status event fires. Unlike `bulkStatusUpdate`, they refuse a product awaiting review.
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yaml
index 92dbf7b418..3d6b83f7ae 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -27180,6 +27180,380 @@ paths:
schema:
"$ref": "#/components/schemas/ProductRejectParams"
required: true
+ "/api/v3/admin/products/{id}/activate":
+ parameters:
+ - name: id
+ in: path
+ required: true
+ description: Product ID
+ schema:
+ type: string
+ patch:
+ summary: Activate a product
+ tags:
+ - Products
+ x-codeSamples:
+ - lang: javascript
+ label: Spree Admin SDK
+ source: |-
+ import { createAdminClient } from '@spree/admin-sdk'
+
+ const client = createAdminClient({
+ baseUrl: 'https://your-store.com',
+ secretKey: 'sk_xxx',
+ })
+
+ const product = await client.products.activate('prod_UkLWZg9DAJ')
+ - lang: bash
+ label: Spree CLI
+ source: spree api patch /products/{id}/activate -d '{ ... }'
+ security:
+ - api_key: []
+ bearer_auth: []
+ description: |-
+ Puts one product on sale. Runs the activation workflow, so its hooks and the `product.activated` event fire, which `bulk_status_update` does not. A product awaiting review is refused: approve or reject it instead.
+
+
+ **Required scope:** `write_products` (for API-key authentication).
+ parameters:
+ - name: x-spree-api-key
+ in: header
+ required: true
+ schema:
+ type: string
+ - name: Authorization
+ in: header
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: product active
+ content:
+ application/json:
+ example:
+ id: prod_gbHJdmfrXB
+ name: Product 1604119
+ slug: product-1604119
+ meta_title:
+ meta_description:
+ meta_keywords:
+ variant_count: 1
+ available_on:
+ preorder_ships_at:
+ purchasable: true
+ preorder: false
+ in_stock: false
+ backorderable: true
+ available: true
+ description: Tempora doloribus sit consectetur cumque omnis. Quod
+ fugit dicta ullam omnis. Hic dolorem asperiores nemo est sed nihil
+ quia deleniti. Saepe aperiam eos nulla quia porro minima officiis
+ cum. Eius dignissimos laudantium sequi incidunt. Sed nihil voluptate
+ aliquid nisi. Veritatis tenetur quos aspernatur modi perspiciatis
+ quaerat. Voluptas harum neque labore fuga reprehenderit unde quasi.
+ Omnis quam autem in ipsam aspernatur architecto alias recusandae.
+ Repudiandae ratione vel expedita corporis et pariatur rem sapiente.
+ Velit laboriosam nulla quibusdam fugit minus itaque ut repellat.
+ Incidunt est fugiat totam ipsa quod deserunt. Natus sequi numquam
+ laudantium non similique saepe ipsam quos. Ad impedit necessitatibus
+ quo nesciunt blanditiis id similique recusandae. Ut occaecati debitis
+ aliquam accusantium sed distinctio neque. Labore quos quam optio
+ aperiam dolores aspernatur vitae odio. Eius nam adipisci corrupti
+ incidunt quod sapiente tempora dicta.
+ description_html: |-
+ Tempora doloribus sit consectetur cumque omnis. Quod fugit dicta ullam omnis. Hic dolorem asperiores nemo est sed nihil quia deleniti.
+ Saepe aperiam eos nulla quia porro minima officiis cum. Eius dignissimos laudantium sequi incidunt. Sed nihil voluptate aliquid nisi.
+ Veritatis tenetur quos aspernatur modi perspiciatis quaerat. Voluptas harum neque labore fuga reprehenderit unde quasi. Omnis quam autem in ipsam aspernatur architecto alias recusandae. Repudiandae ratione vel expedita corporis et pariatur rem sapiente.
+ Velit laboriosam nulla quibusdam fugit minus itaque ut repellat. Incidunt est fugiat totam ipsa quod deserunt. Natus sequi numquam laudantium non similique saepe ipsam quos. Ad impedit necessitatibus quo nesciunt blanditiis id similique recusandae.
+ Ut occaecati debitis aliquam accusantium sed distinctio neque. Labore quos quam optio aperiam dolores aspernatur vitae odio. Eius nam adipisci corrupti incidunt quod sapiente tempora dicta.
+ default_variant_id: variant_gbHJdmfrXB
+ buy_box_variant_id: variant_gbHJdmfrXB
+ thumbnail_url:
+ tags: []
+ price:
+ id: price_gbHJdmfrXB
+ currency: USD
+ amount: '19.99'
+ compare_at_amount:
+ price_list_id:
+ min_quantity: 1
+ variant_id: variant_gbHJdmfrXB
+ created_at: '2026-01-15T12:00:00.000Z'
+ updated_at: '2026-01-15T12:00:00.000Z'
+ original_price:
+ seller_id:
+ external_references: {}
+ status: active
+ metadata: {}
+ deleted_at:
+ created_at: '2026-01-15T12:00:00.000Z'
+ updated_at: '2026-01-15T12:00:00.000Z'
+ delivery_profile_id: fp_UkLWZg9DAJ
+ seller_name:
+ product_type_id:
+ tax_category_id: taxcat_UkLWZg9DAJ
+ schema:
+ "$ref": "#/components/schemas/Product"
+ '422':
+ description: the product is awaiting review
+ content:
+ application/json:
+ example:
+ error:
+ code: product_in_review
+ message: A product awaiting review is approved or rejected, not
+ moved to another status
+ schema:
+ "$ref": "#/components/schemas/ErrorResponse"
+ "/api/v3/admin/products/{id}/archive":
+ parameters:
+ - name: id
+ in: path
+ required: true
+ description: Product ID
+ schema:
+ type: string
+ patch:
+ summary: Archive a product
+ tags:
+ - Products
+ x-codeSamples:
+ - lang: javascript
+ label: Spree Admin SDK
+ source: |-
+ import { createAdminClient } from '@spree/admin-sdk'
+
+ const client = createAdminClient({
+ baseUrl: 'https://your-store.com',
+ secretKey: 'sk_xxx',
+ })
+
+ const product = await client.products.archive('prod_UkLWZg9DAJ')
+ - lang: bash
+ label: Spree CLI
+ source: spree api patch /products/{id}/archive -d '{ ... }'
+ security:
+ - api_key: []
+ bearer_auth: []
+ description: |-
+ Takes one product off sale and archives it; activating it puts it back on sale. Runs the archive workflow, so its hooks and its event fire. A product awaiting review is refused: approve or reject it instead.
+
+
+ **Required scope:** `write_products` (for API-key authentication).
+ parameters:
+ - name: x-spree-api-key
+ in: header
+ required: true
+ schema:
+ type: string
+ - name: Authorization
+ in: header
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: product archived
+ content:
+ application/json:
+ example:
+ id: prod_gbHJdmfrXB
+ name: Product 1644768
+ slug: product-1644768
+ meta_title:
+ meta_description:
+ meta_keywords:
+ variant_count: 1
+ available_on:
+ preorder_ships_at:
+ purchasable: true
+ preorder: false
+ in_stock: false
+ backorderable: true
+ available: false
+ description: In exercitationem nobis illo accusamus non quibusdam.
+ Minus corporis commodi magni maxime cumque beatae. Exercitationem
+ provident tempore est corrupti eius at dolor. Rerum delectus id
+ aspernatur consequuntur quod enim. Quis omnis amet inventore alias
+ minima praesentium. Quaerat reprehenderit deleniti atque inventore.
+ Nemo quas nam qui architecto eligendi vel pariatur. Veritatis accusantium
+ molestias deleniti omnis autem modi. Officiis optio quidem iste
+ nihil delectus commodi. Aperiam amet omnis eum praesentium natus
+ recusandae suscipit.
+ description_html: |-
+ In exercitationem nobis illo accusamus non quibusdam. Minus corporis commodi magni maxime cumque beatae. Exercitationem provident tempore est corrupti eius at dolor. Rerum delectus id aspernatur consequuntur quod enim.
+ Quis omnis amet inventore alias minima praesentium. Quaerat reprehenderit deleniti atque inventore. Nemo quas nam qui architecto eligendi vel pariatur.
+ Veritatis accusantium molestias deleniti omnis autem modi. Officiis optio quidem iste nihil delectus commodi. Aperiam amet omnis eum praesentium natus recusandae suscipit.
+ default_variant_id: variant_gbHJdmfrXB
+ buy_box_variant_id: variant_gbHJdmfrXB
+ thumbnail_url:
+ tags: []
+ price:
+ id: price_gbHJdmfrXB
+ currency: USD
+ amount: '19.99'
+ compare_at_amount:
+ price_list_id:
+ min_quantity: 1
+ variant_id: variant_gbHJdmfrXB
+ created_at: '2026-01-15T12:00:00.000Z'
+ updated_at: '2026-01-15T12:00:00.000Z'
+ original_price:
+ seller_id:
+ external_references: {}
+ status: archived
+ metadata: {}
+ deleted_at:
+ created_at: '2026-01-15T12:00:00.000Z'
+ updated_at: '2026-01-15T12:00:00.000Z'
+ delivery_profile_id: fp_UkLWZg9DAJ
+ seller_name:
+ product_type_id:
+ tax_category_id: taxcat_UkLWZg9DAJ
+ schema:
+ "$ref": "#/components/schemas/Product"
+ '422':
+ description: the product is awaiting review
+ content:
+ application/json:
+ example:
+ error:
+ code: product_in_review
+ message: A product awaiting review is approved or rejected, not
+ moved to another status
+ schema:
+ "$ref": "#/components/schemas/ErrorResponse"
+ "/api/v3/admin/products/{id}/draft":
+ parameters:
+ - name: id
+ in: path
+ required: true
+ description: Product ID
+ schema:
+ type: string
+ patch:
+ summary: Move a product back to draft
+ tags:
+ - Products
+ x-codeSamples:
+ - lang: javascript
+ label: Spree Admin SDK
+ source: |-
+ import { createAdminClient } from '@spree/admin-sdk'
+
+ const client = createAdminClient({
+ baseUrl: 'https://your-store.com',
+ secretKey: 'sk_xxx',
+ })
+
+ const product = await client.products.draft('prod_UkLWZg9DAJ')
+ - lang: bash
+ label: Spree CLI
+ source: spree api patch /products/{id}/draft -d '{ ... }'
+ security:
+ - api_key: []
+ bearer_auth: []
+ description: |-
+ Takes one product off sale, back to a draft. Runs the draft workflow, so its hooks and its event fire. A product awaiting review is refused: approve or reject it instead.
+
+
+ **Required scope:** `write_products` (for API-key authentication).
+ parameters:
+ - name: x-spree-api-key
+ in: header
+ required: true
+ schema:
+ type: string
+ - name: Authorization
+ in: header
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: product draft
+ content:
+ application/json:
+ example:
+ id: prod_gbHJdmfrXB
+ name: Product 1682527
+ slug: product-1682527
+ meta_title:
+ meta_description:
+ meta_keywords:
+ variant_count: 1
+ available_on:
+ preorder_ships_at:
+ purchasable: true
+ preorder: false
+ in_stock: false
+ backorderable: true
+ available: false
+ description: Temporibus fugiat ducimus quae voluptas error. Iure repellat
+ labore aperiam harum magni. Fuga ullam possimus ad repudiandae atque.
+ Excepturi quidem est expedita molestiae delectus. Optio tempora
+ sed minus voluptatum doloremque. Laborum esse voluptate nostrum
+ nesciunt. Ipsum ducimus a dolor nostrum quis corrupti quae illum.
+ Fuga provident deleniti minima ea vel. Cupiditate architecto omnis
+ reprehenderit iusto suscipit corrupti quia cumque. Voluptatem nisi
+ dignissimos aut nostrum distinctio quo explicabo fugiat. Unde minima
+ ratione enim minus officia rerum odio reiciendis. Fugiat perferendis
+ nulla voluptates voluptatum alias. Voluptatem cumque voluptatibus
+ in sint assumenda ad neque. Inventore error consequuntur exercitationem
+ officia consequatur earum iure autem. Odit iure porro reiciendis
+ placeat. Animi minus vel asperiores maiores error tempora. Dolorum
+ esse sapiente voluptatem iste culpa suscipit. Nulla sapiente sit
+ deserunt iste totam dolores. Tempora magni eveniet natus nemo optio.
+ Aliquid quis ullam illo minus. Atque distinctio sapiente voluptatibus
+ adipisci consectetur repellendus culpa dolor. Dolor pariatur tempora
+ ab repellat unde aliquam sequi. Necessitatibus aliquid fugit molestias
+ facilis ratione.
+ description_html: |-
+ Temporibus fugiat ducimus quae voluptas error. Iure repellat labore aperiam harum magni. Fuga ullam possimus ad repudiandae atque. Excepturi quidem est expedita molestiae delectus. Optio tempora sed minus voluptatum doloremque.
+ Laborum esse voluptate nostrum nesciunt. Ipsum ducimus a dolor nostrum quis corrupti quae illum. Fuga provident deleniti minima ea vel. Cupiditate architecto omnis reprehenderit iusto suscipit corrupti quia cumque. Voluptatem nisi dignissimos aut nostrum distinctio quo explicabo fugiat.
+ Unde minima ratione enim minus officia rerum odio reiciendis. Fugiat perferendis nulla voluptates voluptatum alias. Voluptatem cumque voluptatibus in sint assumenda ad neque. Inventore error consequuntur exercitationem officia consequatur earum iure autem.
+ Odit iure porro reiciendis placeat. Animi minus vel asperiores maiores error tempora. Dolorum esse sapiente voluptatem iste culpa suscipit. Nulla sapiente sit deserunt iste totam dolores.
+ Tempora magni eveniet natus nemo optio. Aliquid quis ullam illo minus. Atque distinctio sapiente voluptatibus adipisci consectetur repellendus culpa dolor. Dolor pariatur tempora ab repellat unde aliquam sequi. Necessitatibus aliquid fugit molestias facilis ratione.
+ default_variant_id: variant_gbHJdmfrXB
+ buy_box_variant_id: variant_gbHJdmfrXB
+ thumbnail_url:
+ tags: []
+ price:
+ id: price_gbHJdmfrXB
+ currency: USD
+ amount: '19.99'
+ compare_at_amount:
+ price_list_id:
+ min_quantity: 1
+ variant_id: variant_gbHJdmfrXB
+ created_at: '2026-01-15T12:00:00.000Z'
+ updated_at: '2026-01-15T12:00:00.000Z'
+ original_price:
+ seller_id:
+ external_references: {}
+ status: draft
+ metadata: {}
+ deleted_at:
+ created_at: '2026-01-15T12:00:00.000Z'
+ updated_at: '2026-01-15T12:00:00.000Z'
+ delivery_profile_id: fp_UkLWZg9DAJ
+ seller_name:
+ product_type_id:
+ tax_category_id: taxcat_UkLWZg9DAJ
+ schema:
+ "$ref": "#/components/schemas/Product"
+ '422':
+ description: the product is awaiting review
+ content:
+ application/json:
+ example:
+ error:
+ code: product_in_review
+ message: A product awaiting review is approved or rejected, not
+ moved to another status
+ schema:
+ "$ref": "#/components/schemas/ErrorResponse"
"/api/v3/admin/translations":
get:
summary: Translation coverage for a resource type
diff --git a/packages/admin-sdk/examples/products/activate.ts b/packages/admin-sdk/examples/products/activate.ts
new file mode 100644
index 0000000000..3a6b544c00
--- /dev/null
+++ b/packages/admin-sdk/examples/products/activate.ts
@@ -0,0 +1,13 @@
+import { createAdminClient } from '@spree/admin-sdk'
+
+const client = createAdminClient({
+ baseUrl: 'https://your-store.com',
+ secretKey: 'sk_xxx',
+})
+
+// region:example
+const product = await client.products.activate('prod_UkLWZg9DAJ')
+
+// endregion:example
+
+export { product }
diff --git a/packages/admin-sdk/examples/products/archive.ts b/packages/admin-sdk/examples/products/archive.ts
new file mode 100644
index 0000000000..b711e22128
--- /dev/null
+++ b/packages/admin-sdk/examples/products/archive.ts
@@ -0,0 +1,13 @@
+import { createAdminClient } from '@spree/admin-sdk'
+
+const client = createAdminClient({
+ baseUrl: 'https://your-store.com',
+ secretKey: 'sk_xxx',
+})
+
+// region:example
+const product = await client.products.archive('prod_UkLWZg9DAJ')
+
+// endregion:example
+
+export { product }
diff --git a/packages/admin-sdk/examples/products/draft.ts b/packages/admin-sdk/examples/products/draft.ts
new file mode 100644
index 0000000000..d5cd259e9f
--- /dev/null
+++ b/packages/admin-sdk/examples/products/draft.ts
@@ -0,0 +1,13 @@
+import { createAdminClient } from '@spree/admin-sdk'
+
+const client = createAdminClient({
+ baseUrl: 'https://your-store.com',
+ secretKey: 'sk_xxx',
+})
+
+// region:example
+const product = await client.products.draft('prod_UkLWZg9DAJ')
+
+// endregion:example
+
+export { product }
diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.ts
index 4502d01e11..bd9bfd6876 100644
--- a/packages/admin-sdk/src/admin-client.ts
+++ b/packages/admin-sdk/src/admin-client.ts
@@ -1377,6 +1377,22 @@ export class AdminClient {
): Promise<Product> =>
this.request<Product>('PATCH', `/products/${id}/reject`, { ...options, body: params }),
+ /**
+ * Put one product on sale, running its status workflow so the
+ * `product.activated` event fires. Refuses a product awaiting review,
+ * which is approved or rejected instead.
+ */
+ activate: (id: string, options?: RequestOptions): Promise<Product> =>
+ this.request<Product>('PATCH', `/products/${id}/activate`, options),
+
+ /** Archive one product, taking it off sale. Refuses a product awaiting review. */
+ archive: (id: string, options?: RequestOptions): Promise<Product> =>
+ this.request<Product>('PATCH', `/products/${id}/archive`, options),
+
+ /** Take one product off sale, back to a draft. Refuses a product awaiting review. */
+ draft: (id: string, options?: RequestOptions): Promise<Product> =>
+ this.request<Product>('PATCH', `/products/${id}/draft`, options),
+
/**
* Bulk-set `status` on a list of products. The server validates `status`
* against the product status enum and reindexes affected products.
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.rb
index eab1ceaaa6..33749f08ce 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
@@ -156,6 +156,28 @@ module Spree
run_review_workflow(Spree.product_reject_workflow, reason: params[:reason])
end
+ # PATCH /api/v3/admin/products/:id/activate
+ #
+ # Puts one product on sale.
+ def activate
+ run_status_workflow(Spree.product_activate_workflow, 'active')
+ end
+
+ # PATCH /api/v3/admin/products/:id/archive
+ #
+ # Takes one product off sale, archived; activating it again puts it
+ # back on sale.
+ def archive
+ run_status_workflow(Spree.product_archive_workflow, 'archived')
+ end
+
+ # PATCH /api/v3/admin/products/:id/draft
+ #
+ # Takes one product off sale, back to a draft.
+ def draft
+ run_status_workflow(Spree.product_draft_workflow, 'draft')
+ end
+
# POST /api/v3/admin/products/bulk_status_update
# Body: { ids: [...], status: 'draft' | 'active' | 'archived' }
def bulk_status_update
@@ -363,6 +385,40 @@ module Spree
private
+ # Unlike bulk_status_update, which writes the column, these run the
+ # status workflow, so its hooks and its event fire. A product in
+ # review is refused: its next status is a decision, made through
+ # approve or reject (docs/plans/6.0-seller-product-submission.md).
+ #
+ # A product already in that status is answered as it is: running the
+ # workflow again would publish its event again, and every webhook
+ # subscriber would see the move twice.
+ def run_status_workflow(workflow, status)
+ @resource = find_resource
+ authorize!(:update, @resource)
+
+ return render json: serialize_resource(@resource) if @resource.status == status
+
+ if @resource.in_review?
+ return render_error(
+ code: 'product_in_review',
+ message: I18n.t('spree.errors.messages.product_in_review'),
+ status: :unprocessable_content
+ )
+ end
+
+ # Not under a row lock taken here: that would wrap the workflow in
+ # a transaction, and it publishes its event once its own
+ # transaction is done, which an outer one would no longer be.
+ result = workflow.call(product: @resource)
+
+ if result.success?
+ render json: serialize_resource(@resource.reload)
+ else
+ render_service_error(@resource.errors.presence || result.error)
+ end
+ end
+
# Approving and rejecting are edits to the catalog, so they answer to
# the same key as any other product write.
def run_review_workflow(workflow, **arguments)
diff --git a/spree/api/config/routes.rb b/spree/api/config/routes.rb
index c45bdecacd..4eabd3e0fa 100644
--- a/spree/api/config/routes.rb
+++ b/spree/api/config/routes.rb
@@ -366,6 +366,11 @@ Spree::Core::Engine.add_routes do
# (docs/plans/6.0-seller-product-submission.md).
patch :approve
patch :reject
+ # One product's status, through the workflow that publishes its
+ # event; bulk_status_update writes the column for many at once.
+ patch :activate
+ patch :archive
+ patch :draft
end
collection do
post :bulk_status_update
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
index fb8b5756a5..f4f4940093 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb
@@ -1540,6 +1540,40 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
end
end
+ # One product's status, moved through its workflow so its event fires.
+ describe 'moving one product\'s status' do
+ before { request.headers.merge!(headers) }
+
+ it 'activates a draft and publishes the event' do
+ draft = create(:product, store: store, status: 'draft')
+ expect_any_instance_of(Spree::Product).to receive(:publish_event).with('product.activated')
+
+ patch :activate, params: { id: draft.prefixed_id }, as: :json
+
+ expect(response).to have_http_status(:ok)
+ expect(draft.reload).to be_active
+ end
+
+ # A retried request must not tell every webhook subscriber twice.
+ it 'answers a product already in that status without publishing again' do
+ active = create(:product, store: store, status: 'active')
+ expect_any_instance_of(Spree::Product).not_to receive(:publish_event)
+
+ patch :activate, params: { id: active.prefixed_id }, as: :json
+
+ expect(response).to have_http_status(:ok)
+ end
+
+ it 'refuses a product awaiting review' do
+ submitted = create(:product, store: store, status: 'proposed')
+
+ patch :archive, params: { id: submitted.prefixed_id }, as: :json
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(submitted.reload.status).to eq('proposed')
+ end
+ end
+
# `proposed` and `rejected` are review outcomes, reached through the
# approve/reject workflows. A status naming one in an ordinary update is
# dropped rather than written, so a product cannot be pushed into or out of
diff --git a/spree/api/spec/integration/spree/api/v3/admin/products_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/products_spec.rb
index f09e31e3a8..f105f6cf63 100644
--- a/spree/api/spec/integration/spree/api/v3/admin/products_spec.rb
+++ b/spree/api/spec/integration/spree/api/v3/admin/products_spec.rb
@@ -690,4 +690,124 @@ RSpec.describe 'Admin Products API', type: :request, swagger_doc: 'api-reference
end
end
end
+
+ path '/api/v3/admin/products/{id}/activate' do
+ parameter name: :id, in: :path, type: :string, required: true, description: 'Product ID'
+
+ patch 'Activate a product' do
+ tags 'Products'
+ admin_sdk_example 'products/activate'
+ produces 'application/json'
+ security [api_key: [], bearer_auth: []]
+ description <<~DESC
+ Puts one product on sale. Runs the activation workflow, so its hooks and the `product.activated` event fire, which `bulk_status_update` does not. A product awaiting review is refused: approve or reject it instead.
+ DESC
+ admin_scope :write, :products
+
+ parameter name: 'x-spree-api-key', in: :header, type: :string, required: true
+ parameter name: :Authorization, in: :header, type: :string, required: true
+
+ response '200', 'product active' do
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+ let(:id) { create(:product, store: store, status: 'draft').prefixed_id }
+
+ schema '$ref' => '#/components/schemas/Product'
+
+ run_test! do |response|
+ expect(JSON.parse(response.body)['status']).to eq('active')
+ end
+ end
+
+ response '422', 'the product is awaiting review' do
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+ let(:id) { create(:product, store: store, status: 'proposed').prefixed_id }
+
+ schema '$ref' => '#/components/schemas/ErrorResponse'
+
+ run_test! do |response|
+ expect(JSON.parse(response.body).dig('error', 'code')).to eq('product_in_review')
+ end
+ end
+ end
+ end
+
+ path '/api/v3/admin/products/{id}/archive' do
+ parameter name: :id, in: :path, type: :string, required: true, description: 'Product ID'
+
+ patch 'Archive a product' do
+ tags 'Products'
+ admin_sdk_example 'products/archive'
+ produces 'application/json'
+ security [api_key: [], bearer_auth: []]
+ description <<~DESC
+ Takes one product off sale and archives it; activating it puts it back on sale. Runs the archive workflow, so its hooks and its event fire. A product awaiting review is refused: approve or reject it instead.
+ DESC
+ admin_scope :write, :products
+
+ parameter name: 'x-spree-api-key', in: :header, type: :string, required: true
+ parameter name: :Authorization, in: :header, type: :string, required: true
+
+ response '200', 'product archived' do
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+ let(:id) { create(:product, store: store, status: 'active').prefixed_id }
+
+ schema '$ref' => '#/components/schemas/Product'
+
+ run_test! do |response|
+ expect(JSON.parse(response.body)['status']).to eq('archived')
+ end
+ end
+
+ response '422', 'the product is awaiting review' do
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+ let(:id) { create(:product, store: store, status: 'proposed').prefixed_id }
+
+ schema '$ref' => '#/components/schemas/ErrorResponse'
+
+ run_test! do |response|
+ expect(JSON.parse(response.body).dig('error', 'code')).to eq('product_in_review')
+ end
+ end
+ end
+ end
+
+ path '/api/v3/admin/products/{id}/draft' do
+ parameter name: :id, in: :path, type: :string, required: true, description: 'Product ID'
+
+ patch 'Move a product back to draft' do
+ tags 'Products'
+ admin_sdk_example 'products/draft'
+ produces 'application/json'
+ security [api_key: [], bearer_auth: []]
+ description <<~DESC
+ Takes one product off sale, back to a draft. Runs the draft workflow, so its hooks and its event fire. A product awaiting review is refused: approve or reject it instead.
+ DESC
+ admin_scope :write, :products
+
+ parameter name: 'x-spree-api-key', in: :header, type: :string, required: true
+ parameter name: :Authorization, in: :header, type: :string, required: true
+
+ response '200', 'product draft' do
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+ let(:id) { create(:product, store: store, status: 'active').prefixed_id }
+
+ schema '$ref' => '#/components/schemas/Product'
+
+ run_test! do |response|
+ expect(JSON.parse(response.body)['status']).to eq('draft')
+ end
+ end
+
+ response '422', 'the product is awaiting review' do
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+ let(:id) { create(:product, store: store, status: 'proposed').prefixed_id }
+
+ schema '$ref' => '#/components/schemas/ErrorResponse'
+
+ run_test! do |response|
+ expect(JSON.parse(response.body).dig('error', 'code')).to eq('product_in_review')
+ end
+ end
+ end
+ end
end
diff --git a/spree/api/spec/lib/spree/api/agent_tools_contract_spec.rb b/spree/api/spec/lib/spree/api/agent_tools_contract_spec.rb
index 1ef137c2cf..5597828d7e 100644
--- a/spree/api/spec/lib/spree/api/agent_tools_contract_spec.rb
+++ b/spree/api/spec/lib/spree/api/agent_tools_contract_spec.rb
@@ -76,11 +76,7 @@ RSpec.describe 'agent tool contract' do
it 'exposes nothing an admin controller does not invoke' do
# A workflow no controller reaches has no reference wiring: nothing says
# how a request becomes its keywords, or which permission gates it.
- stray = catalog::WORKFLOWS.keys - workflows_invoked_by_admin_controllers -
- # The products status workflows are reached through the products
- # controller's own status actions, which call them by a
- # dynamically built key rather than a literal.
- %i[product_activate_workflow product_draft_workflow product_archive_workflow]
+ stray = catalog::WORKFLOWS.keys - workflows_invoked_by_admin_controllers
expect(stray).to be_empty
end
diff --git a/spree/api/spec/tools/spree/agent_tools/workflow_tool_arguments_spec.rb b/spree/api/spec/tools/spree/agent_tools/workflow_tool_arguments_spec.rb
index 5ba77879a5..4af4d44afe 100644
--- a/spree/api/spec/tools/spree/agent_tools/workflow_tool_arguments_spec.rb
+++ b/spree/api/spec/tools/spree/agent_tools/workflow_tool_arguments_spec.rb
@@ -157,12 +157,7 @@ RSpec.describe 'agent workflow tool arguments' do
Spree::AgentTools::WorkflowEndpoints.find(key)
end
- # Only the product status moves, which the Admin API does not expose:
- # `PATCH` writes the column and the bulk action uses `update_all`, so
- # neither publishes the event nor withdraws an open submission.
- expect(in_process.keys).to contain_exactly(
- :product_activate_workflow, :product_draft_workflow, :product_archive_workflow
- )
+ expect(in_process.keys).to be_empty
end
it 'fills a parent segment from the record the caller named' do
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index 5490deaa95..ca44995015 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -910,6 +910,7 @@ en:
oidc_missing_code: The identity provider did not return an authorization code.
oidc_requires_redirect: This provider requires signing in through its own login page.
pickup_point_not_found: pickup point could not be found with this provider
+ product_in_review: A product awaiting review is approved or rejected, not moved to another status
product_not_in_store: must all belong to this store
profile_does_not_accept_provider: "%{provider} deliveries cannot join the %{profile} profile"
promotion_discount_not_editable: promotion discounts are managed by recalculation and cannot be edited
diff --git a/spree/core/lib/spree/agent_tools/default_catalog.rb b/spree/core/lib/spree/agent_tools/default_catalog.rb
index f1eef7ff69..f5d050cf3b 100644
--- a/spree/core/lib/spree/agent_tools/default_catalog.rb
+++ b/spree/core/lib/spree/agent_tools/default_catalog.rb
@@ -36,12 +36,6 @@ module Spree
# Workflow key => permission, or => {permission:, except:, summary:}.
WORKFLOWS = {
# Catalog
- #
- # The three status moves below run in this process rather than through
- # an endpoint, because the Admin API has none for them: `PATCH` writes
- # the column and the bulk action uses `update_all`, so neither
- # publishes the status event nor withdraws an open seller submission.
- # They dispatch as soon as an admin status endpoint exists.
product_activate_workflow: 'write_products',
product_draft_workflow: 'write_products',
product_archive_workflow: 'write_products',