feat: implement status automation and router pattern

- Implemented modular status automation system (statusHandlers.ts).
- Added handlers for 'Published' (Active/Qty 1), 'Sold' (Active/Qty 0), and 'Drafted'.
- Refactored onEdit triggers into a central Router pattern in OnEditHandler.ts.
- Updated Product.ts to support explicit quantity setting (fixed 0 value bug).
- Updated shopifyApi.ts to implement SetInventoryItemQuantity (using ignoreCompareQuantity).
- Consolidated triggers into single onEditHandler.
- Updated project documentation.
This commit is contained in:
2025-12-24 23:55:28 -07:00
parent 2d43c07546
commit 85cdfe1443
9 changed files with 158 additions and 15 deletions

View File

@ -671,6 +671,49 @@ export class Shop {
return newItem
}
SetInventoryItemQuantity(
item: shopify.InventoryItem,
quantity: number,
config: Config
) {
console.log("SetInventoryItemQuantity(" + JSON.stringify(item) + ", " + quantity + ")")
let gql = /* GraphQL */ `
mutation inventorySetQuantities($input: InventorySetQuantitiesInput!) {
inventorySetQuantities(input: $input) {
inventoryAdjustmentGroup {
changes {
name
delta
}
}
userErrors {
field
message
}
}
}
`
let variables = {
input: {
name: "available",
reason: "correction",
ignoreCompareQuantity: true,
quantities: [
{
inventoryItemId: item.id,
locationId: config.shopifyLocationId,
quantity: quantity,
},
],
},
}
let query = buildGqlQuery(gql, variables)
let response = this.shopifyGraphQLAPI(query)
// Response structure is different for setQuantities
console.log("SetInventoryItemQuantity response:\n" + JSON.stringify(response, null, 2))
return response.content
}
SetInventoryItemDefaults(item: shopify.InventoryItem, config: Config) {
let gql = /* GraphQL */ `
mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) {