Stock and Prices from the ERP¶
This scenario keeps each product's and variation's price and stock level in WooCommerce in step with the ERP. The ERP owns both figures, and the integration copies them to the store on a schedule.
Read the ERP¶
Any reader that gives one row for each SKU, with its selling price and its free stock: a database reader on the ERP's tables, or the ERP's own connector. Use the stock free to sell, after the ERP's allocations, not the stock on hand.
Find Each SKU in WooCommerce¶
A Map looks each SKU up in WooCommerce. A lookup on products by SKU finds a simple product or a variation alike, and returns two values:
CustomLookup("WOOCOMMERCE", "[]/id", "products", "sku=" & %SKU, "", False)
CustomLookup("WOOCOMMERCE", "[]/parent_id", "products", "sku=" & %SKU, "", False)
- For a simple product,
idis the product's id andparent_idis0. - For a variation,
idis the variation's id andparent_idis its product's.
IMan sends one request for both calls, because the second reads the answer the first one kept.
Drop the SKUs the Store Lacks¶
The ERP usually holds items the store does not sell. Their lookup comes back empty, and the push has no record to update. A Filter keeps only the rows with an id.
Write the Prices and Stock¶
Two Filters split the rows by parent_id, each feeding a WooCommerce writer with Update Operation at Update:
| Rows | Push | Ids | Figures |
|---|---|---|---|
parent_id is 0 |
Products | Id from id |
Regular Price, Manage Stock True, Stock Quantity |
any other parent_id |
Variations | Product Id from parent_id, Variation Id from id |
Regular Price, Manage Stock True, Stock Quantity |
WooCommerce takes a price as text with a full stop for the decimal point, such as 12.50. Map Sale Price only if the ERP runs the store's promotions. Otherwise leave it unmapped, and WooCommerce keeps the sale prices set in the store.
A variable product itself has no price or stock to set. The ERP's rows for it are its variations.
Running It¶
WooCommerce reduces its own stock the moment it takes an order. The ERP reduces its stock only when the order reaches it. Run the order integration just before this one. Otherwise this integration copies the ERP's higher figure back over orders the ERP has not seen yet, and the store can sell stock it no longer has.
Each SKU costs two requests: one lookup and one write. A catalogue of 3,000 SKUs sends 6,000 requests. To send fewer, read only the items whose price or stock changed since the last run, where the ERP records that. On a host that limits requests, see Speed and the Rate Limit.