From 74c4753dea450c854a6610692f7ee44f530eb59c Mon Sep 17 00:00:00 2001 From: Steve Ramage Date: Fri, 14 Feb 2025 10:11:00 -0800 Subject: [PATCH] Resolves #497 - Add support for multi-location inventory --- docs/runbook-development.md | 3 ++ external/resources/yaml/resources.yaml | 11 ++++-- .../multi-location-inventory.epcc.yml | 34 +++++++++++++++++-- external/runbooks/run-all-runbooks.sh | 15 ++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/docs/runbook-development.md b/docs/runbook-development.md index ef7f7fc..084c6f8 100644 --- a/docs/runbook-development.md +++ b/docs/runbook-development.md @@ -254,3 +254,6 @@ actions: +### Output JQ + +You will need to escape \ when using the `--output-jq` argument. diff --git a/external/resources/yaml/resources.yaml b/external/resources/yaml/resources.yaml index 9e524ee..66bfb0c 100644 --- a/external/resources/yaml/resources.yaml +++ b/external/resources/yaml/resources.yaml @@ -328,6 +328,9 @@ cart-product-items: type: STRING tax[n].rate: type: FLOAT + location: + type: RESOURCE_ID:mli-inventory-locations + alias_attribute: slug cart-custom-items: singular-name: "cart-custom-item" json-api-type: "custom_item" @@ -2833,19 +2836,21 @@ mli-inventory-stocks: json-api-format: compliant json-api-type: "stock" singular-name: "mli-inventory-stock" + alternate-json-type-for-aliases: + - pcm-products docs: "https://elasticpath.dev/docs/api/pxm/inventory_mli/inventory" get-collection: docs: "https://elasticpath.dev/docs/api/pxm/inventory_mli/list-stock" url: "/v2/inventories/" get-entity: docs: "https://elasticpath.dev/docs/api/pxm/inventory_mli/get-stock" - url: "/v2/inventories/{pcm_products}" + url: "/v2/inventories/{mli_inventory_stocks}" update-entity: docs: "https://elasticpath.dev/docs/api/pxm/inventory_mli/update-stock" - url: "/v2/inventories/{pcm_products}" + url: "/v2/inventories/{mli_inventory_stocks}" delete-entity: docs: "https://elasticpath.dev/docs/api/pxm/inventory_mli/delete-stock" - url: "/v2/inventories/{pcm_products}" + url: "/v2/inventories/{mli_inventory_stocks}" create-entity: docs: "https://elasticpath.dev/docs/api/pxm/inventory_mli/create-stock" url: "/v2/inventories" diff --git a/external/runbooks/multi-location-inventory.epcc.yml b/external/runbooks/multi-location-inventory.epcc.yml index 2456db0..f08c9c2 100644 --- a/external/runbooks/multi-location-inventory.epcc.yml +++ b/external/runbooks/multi-location-inventory.epcc.yml @@ -2,6 +2,7 @@ name: "multi-location-inventory" description: long: "Sample commands for working with Multi Location Inventory (https://elasticpath.dev/docs/api/pxm/inventory_mli/inventories-introduction)" short: "Multi Location Inventory" +actions: create-prerequisites: description: short: "Create necessary prerequisites" @@ -30,7 +31,29 @@ description: description: short: "Setup inventory" commands: - - epcc create mli-inventory-location name "Milton Keynes Warehouse" slug "milton-keynes-warehouse" description "Southern dispatch location for all inventory" geolocation.lat '51.477928' geolocation.l + - | + epcc get -s mli-inventory-stocks + epcc get -s mli-inventory-locations + - | + epcc create mli-inventory-location --if-alias-does-not-exist slug=milton-keynes-warehouse name "Milton Keynes Warehouse" slug "milton-keynes-warehouse" description "Southern dispatch location for all inventory" address[0] "Troughton Supplies" address[1] "38 Pipernel Grove" address[2] "Walnut Tree" address[3] "MK7 4UL" geolocation.lat '51.477928' geolocation.lon -- '-0.001545' + epcc create mli-inventory-location --if-alias-does-not-exist slug=manchester-warehouse name "Manchester Warehouse" slug "manchester-warehouse" description "Northern dispatch location for all inventory" address[0] "Tonge Supplies" address[1] "10 Lower Darcy St" address[2] "Bolton" address[3] "BL2 1PP" geolocation.lat '53.5707004' geolocation.lon -- '-2.4071741' + - | + epcc create mli-inventory-stock --if-alias-does-not-exist BestEverRangeStock --save-as-alias BestEverRangeStock id name=BestEver_Electric_Range locations.milton-keynes-warehouse.available 1 locations.manchester-warehouse.available 2 + epcc create mli-inventory-stock --if-alias-does-not-exist GasRangeStock --save-as-alias GasRangeStock id name=BestEver_Gas_Range locations.milton-keynes-warehouse.available 0 locations.manchester-warehouse.available 1 + reset-inventory: + description: + short: "Reset inventory" + commands: + - | + epcc get -s mli-inventory-stocks + epcc get -s mli-inventory-locations + - | + epcc delete mli-inventory-stock BestEverRangeStock --if-alias-exists BestEverRangeStock + epcc delete mli-inventory-stock GasRangeStock --if-alias-exists GasRangeStock + - | + epcc delete mli-inventory-location slug=milton-keynes-warehouse --if-alias-exists slug=milton-keynes-warehouse + epcc delete mli-inventory-location slug=manchester-warehouse --if-alias-exists slug=manchester-warehouse + create-order: description: @@ -38,9 +61,16 @@ description: commands: - epcc delete cart sample_cart - epcc create cart name sample_cart id sample_cart description sample_cart - - epcc create cart-product-item id=sample_cart quantity 1 id sku=BE-Gas-Range-2b2b + - epcc create cart-product-item id=sample_cart quantity 1 id sku=BE-Gas-Range-2b2b location manchester-warehouse - epcc create cart-checkout sample_cart customer.name Billy customer.email "billy@billy.com" billing_address.first_name Jack billing_address.last_name Macdowall billing_address.company_name Macdowalls billing_address.line_1 "1225 Invention Avenue" billing_address.line_2 Birmingham billing_address.postcode "B21 9AF" billing_address.county "West midlands" billing_address.country "UK" shipping_address.first_name Otis shipping_address.last_name Sedmak shipping_address.company_name "Sedmak & Co." shipping_address.line_1 "1251, Rexmere Ave" shipping_address.line_2 "Farmingville, Suffolk" shipping_address.postcode '"11738"' shipping_address.county "New York" shipping_address.country US shipping_address.instructions "Leave in porch" - epcc get order last_read=entity + check-inventory: + description: + short: "Friendly printout of inventory" + commands: + - | + epcc get mli-inventory-stocks --output-jq '.data[] | . as $root | "ID: \\\($root.id), Global: \\\($root.attributes.available), " + ($root.attributes.locations | to_entries | map("\\\(.key): \\\(.value.available)") | join(", "))' + authorize-payment: description: short: "Authorize a payment" diff --git a/external/runbooks/run-all-runbooks.sh b/external/runbooks/run-all-runbooks.sh index 8852fed..920ac57 100755 --- a/external/runbooks/run-all-runbooks.sh +++ b/external/runbooks/run-all-runbooks.sh @@ -13,6 +13,21 @@ set -x #Let's test that epcc command works after an embarrassing bug that caused it to panic :( epcc +echo "Starting Multi Location Inventory Runbook" +epcc reset-store .+ +epcc headers set ep-inventories-multi-location true +epcc runbooks run multi-location-inventory create-prerequisites +epcc runbooks run multi-location-inventory setup-inventory +epcc runbooks run multi-location-inventory check-inventory +epcc runbooks run multi-location-inventory create-order +epcc runbooks run multi-location-inventory check-inventory +epcc runbooks run multi-location-inventory authorize-payment +epcc runbooks run multi-location-inventory capture-payment +epcc runbooks run multi-location-inventory reset-inventory +epcc runbooks run multi-location-inventory reset-cart +epcc runbooks run multi-location-inventory reset +epcc headers delete ep-inventories-multi-location + echo "Starting Commerce Extensions Runbook" epcc reset-store .+