Skip to content

Production orders from an online store

Recipe50 minExpert

Before you start

You will build the link between an online shop and a kitchen, a workshop or a factory floor. A Shopify order arrives in Beezr as it is placed. Each line becomes a production job that knows its recipe. When a job is done, its materials come off stock. When a material falls below its reorder level, a purchase request opens before the shelf is empty. Plan on a day, and test each workflow with one order before you trust it.

  1. Shopify order
  2. Webhook
  3. Production job
  4. Materials deducted
  5. Low stock
  6. Purchase request

A webhook workflow on an Orders module receives the order. A second workflow runs when a job is finished and deducts materials. A third raises the purchase request. The shop stays where it is. Beezr does the work after the sale.

ModuleKey fieldsNotes
ProductsName, SKU, Product typeProduct type: Single, Bundle. The SKU is what the store sends
MaterialsName, Unit, Stock on hand, Reorder levelStock on hand and Reorder level are Decimal fields
Recipe LinesProduct, Material, Quantity per unitProduct and Material are relations
OrdersShopify order ID, Order number, Customer name, Total, StatusShopify order ID is Text
Production JobsOrder, Product, Quantity, StatusStatus: Planned, In production, Done
Waste LogsJob, Material, Quantity, ReasonReason is a Lookup
Purchase RequestsMaterial, Quantity needed, StatusStatus: Open, Ordered, Received

Make the relations with the Relation button on each module’s Fields page: Recipe Lines to Products and Materials, Production Jobs to Orders and Products, Waste Logs to Production Jobs and Materials, Purchase Requests to Materials. See Relations: how modules connect.

On the Production Jobs form, show the job’s order, product and quantity. On Dataviews, give Production Jobs a Kanban grouped by Status, so the floor can drag a job from Planned to In production to Done. A job without a Status never shows on the board, so set a default of Planned.

Create a workflow on Orders, name it Receive Shopify order, and under When should it run? choose From a webhook.

The Workflow settings drawer with From a webhook selected, the Require an API key switch, Send the result back and the schedule switch.
    From a webhook gives the workflow its own URL.
    Require an API key makes the caller send an api-key header.
    Send the result back is for systems that want a confirmation.

Open the workflow’s menu, choose Copy webhook URL, and register that address in Shopify as the webhook for order creation. The webhook accepts JSON. It answers 202 with a run ID when it accepts the call, 400 when the workflow is off or the address is wrong, and 401 when a key is required and missing.

If your Shopify setup can send an api-key header, turn on Require an API key. If it cannot, keep the webhook address private, like a password.

  1. Add JSON parser. Choose The data the webhook sent. Under Its shape, add id, name, total_price and a List called line_items with sku and quantity inside it. Name the result shopify_order.
  2. Add Load data. Choose Orders, with the rule Shopify order ID is the parsed id. Name the list existing.
  3. Add Decision. Pick the list existing itself and choose has no records. On No, the order is a repeat, so the workflow ends.
  4. On Yes, add Record manager: Create, Orders. Fill Shopify order ID, Order number, Total with Insert data.
  5. Add Loop. Choose Each record in a list and pick line_items.
  6. Inside the loop, add Load data: Products where SKU is the current item’s sku. Name it product.
  7. Still inside, add Record manager: Create, Production Jobs. Set Product to the product’s key, Quantity to the item’s quantity, Order to the order created, Status to Planned.

List every field you need under Its shape, because those are the fields later steps can use. Give a Number field only numbers. The parser reads one JSON object, which is what Shopify sends. A record the Record manager creates is available to later steps by its module, so step 7 can read the order from step 4.

The workflow designer with a Record manager step selected: its settings show the action, the module, which record to update and the fields to set.
    A Record manager step creates, updates or deletes records.
    What should it do? offers Create, Update, Delete, Batch create and Batch update.
    Which record? says which record an update changes.
    Fields to set lists the fields and their values.

Run Check, save, and turn the workflow on. Send a test order from Shopify, then open the workflow’s Runs to see each step. If the run stops, read A workflow didn’t run.

Shopify can retry a delivery, and nothing in Beezr knows it is the same order. That is why steps 2 and 3 exist.

Create a workflow on Production Jobs. Run it when A record is updated, After the record is saved (POST). Name it Deduct materials.

  1. Add Decision: Status is Done. A POST workflow runs on every update, so this keeps it to one moment.
  2. Add Load data: Recipe Lines where Product is the job’s product. Name it recipe.
  3. Add Loop, Each record in a list, recipe.
  4. Inside, add Load data: Materials where the key is the recipe line’s Material. Name it material.
  5. Add Record manager: Update, Materials. Use the material’s key as Record ID. Set Stock on hand with a Smart Script.
  6. Add Decision: Stock on hand (on Materials) is less than the Smart Script $cm_materials_base$.$reorder_level$. On Yes, add Record manager: Create, Purchase Requests, with Status Open.

The script in step 5 follows the number conventions: full tokens, and parseFloat around each value with no quotes.

parseFloat($material$.$stock_on_hand$) - parseFloat($recipe$.$quantity_per_unit$) * parseFloat($cm_production_jobs_base$.$quantity$);

Insert each token with Insert data, so the module table name matches yours. The Decision in step 6 reads the material that step 5 has updated, because an updated record is placed in the workflow’s data under its module.

The purchase request is the alert. Give Purchase Requests a Table and a Kanban grouped by Status, and add the module to the buyer’s menu. Add a Smart view header with the material, the quantity needed and the status. To be told, add a Send email to the buyer inside the Yes path of step 6.

Floor staff add Waste Logs records from the job’s record page, with a Quantity and a Reason from a lookup. Add the Waste Logs module as a related tab of Production Jobs. A report that groups waste by reason and sums the quantity shows where losses come from. See Build a report.

  • Bundles. For a Product type of Bundle, add a Bundle Components module and a Decision on the product type. On Yes, load the components and loop over them, creating a job for each.
  • Dispatch manifest. An Adhoc workflow with a Smart document step prints the manifest from the order. Start it from a Dispatch action button on the Orders record page. See Smart document.
  • Fulfilment back to the store. A REST API step at the end of dispatch can post the tracking number to the shop’s API.
  • Other stores. The same pattern works for any system that can send JSON to a URL. See Start a workflow from another system with a webhook.

The Solutions page follows one Shopify order to dispatch: Production and inventory.

Check yourself

Layla's store sends the same order twice. What should the first steps of the webhook workflow do?
Show the answer

Load orders with the same Shopify ID and stop if one already exists. A webhook can be delivered more than once. Loading by the Shopify ID and ending on a match keeps one order and one set of jobs.

A Custom function or Record manager step inside a Loop fails on the third round. What happens to the rounds after it?
Show the answer

The workflow stops at that round. If any round fails, the workflow stops at that round. Earlier rounds keep what they wrote.

What's next

Last checked