0

Supplier Orders

Lightweight solution for small business owners to create orders with their suppliers in an automated way.

TypescriptNode.jsGCP

The Problem

A friend who runs a small business turned to me for some support. They run an e-commerce, meat delivery service, in our local area. They manage around 30 - 50 orders a week. They came to me and explained that they need to generate a supplier list for the orders they plan to deliver, they need to send this to the supplier the night before the delivery day. They work with two suppliers, with certain products coming from particular suppliers.

They looked for some existing solutions, but they didn't exactly meet their requirements for the supplier order format and the restrictions around delivery (cut-off times) and crucially - automation.

The final thing, "I don't want to do anything!"

The Solution

The solution, started off simple but quickly I found the edge-cases and quirks of various products and seasonal peaks.

At it's core it's a simple node.js endpoint that gets hit once a day, just after the delivery cut off (9pm the day before)

Functionality

  1. Get all orders for the next day direct from Wordpress via the WooCommerce REST API. There's some logic here to retry this fetch as this API can be down from time to time.
    • If this fails we retry on a delayed interval
    • If this fails completely we send an error email to the owner
  2. If we don't get any orders and the following day is an expected delivery day (the business only delivery twice a week) we send an email confirming no orders were found
    • There is the odd occasion when there aren't any orders for a delivery day, although rare, it's good to have an email in place of the expected supplier orders to confirm that the system is working and no orders were found. It also flags any potential issues on the eve of a delivery day if we were expecting orders.
  3. Valid orders have been found, we now generate the PDF output
  4. For each order we:
    • Extract name and address
    • Extract product details (including the supplier of the product)
    • If the product is a bundle (a WooCommerce concept of one product containing multiple individual items) we then do some further processing to get these individual items
    • We then build an array of individual unique items, tracking quantity from each order we process
    • Once all orders have been processed we create a PDF document for each supplier along with their related products and quantities
    • All supplier orders are then emailed to the owner along with a status email which contains: total orders and total individual items
  5. Earlier, we extracted the name sand addresses for each order. These details are stored in a CSV and sent with the status email above. This CSV can then be imported into a routing app - completely automating the route planning with optimisation for the following day.
  6. After successful processing we then update each order's status in WooCommerce from Processing to Ready for Delivery
  7. Where errors occur, we send status emails.