createOffersWorkflow when you list products for a store outside the Vendor panel, for example in a custom route, a seed script, or an import job.
Before you begin
You need these records in place:- A store: its
seller_idand the id of a member to record ascreated_by - A master variant: the
variant_idthe store will sell - A shipping profile: one that belongs to the store
- A stock location: where the starting stock is held
Create the offer
1
Add a route that runs the workflow
Create an API route that runs The workflow returns the created
createOffersWorkflow with one offer.src/api/admin/custom/offers/route.ts
Offer rows. The one inventory_items entry becomes a new inventory item with 50 units at the location.2
Know what the run wires up
One run does more than insert the row:
- Inventory: creates an
InventoryItemper entry, links it to the offer with itsrequired_quantity, and links it to the store - Prices: adds each price to the variant’s price set with an
offer_idrule and links it to the offer - Barcodes: copies
eanandupcfrom the variant when you leave them out - Shipping: links the master product to the shipping profile if the product has none
- Event: emits
offer.createdwith{ id, product_id }
3
Read the offer back with its links
Query the offer with its prices and stock to confirm the result.
prices reads the offer’s own rows on the shared price set. inventory_item_link returns the pivot rows, so you get required_quantity with each item.Set selling terms and a condition
The offer accepts optional fields beyond the required ones. Add them to the same entry:condition_id must point at an active offer condition. manage_inventory defaults to true, allow_backorder to false, and leadtime_to_ship to null.
Attach custom data with additional_data
Passadditional_data to the run to hand extra values to the offersCreated hook. Use it to store data from your own module next to the offer.
src/workflows/hooks/offers-created.ts
prices loaded. Run the workflow with additional_data: { source: "erp" } to see the value in the handler.
Handle a failed run
The workflow validates the whole input and rolls back on failure. Compensation removes the inventory items, prices, and links it already created. A run fails when:- A variant doesn’t exist:
Variant with id … was not found - An offer has no inventory items:
Offer must have at least one inventory item - A condition is unknown or inactive:
Offer condition … is not activeor not found - A SKU is taken in the store: the
(seller_id, sku)unique index rejects the insert