diff --git a/src/OnEditHandler.ts b/src/OnEditHandler.ts index 01e8751..f8a273f 100644 --- a/src/OnEditHandler.ts +++ b/src/OnEditHandler.ts @@ -4,6 +4,7 @@ import { getCellRangeByColumnName } from "./sheetUtils" import { matchProductToShopify } from "./match" export function onEditHandler(e: GoogleAppsScript.Events.SheetsOnEdit) { + //TODO: process each edited row newSkuHandler(e) matchProductToShopifyOnEditHandler(e) } diff --git a/src/Product.ts b/src/Product.ts index 4e8fb09..218bc7d 100644 --- a/src/Product.ts +++ b/src/Product.ts @@ -63,6 +63,11 @@ export class Product { console.log("productValues:" + productValues) for (let i = 0; i < headers.length; i++) { if (this.hasOwnProperty(headers[i])) { + if (productValues[i] == "?") { + console.log("skipping '" + headers[i] + "'") + this[headers[i]] = "" + continue + } console.log( "setting value for '" + headers[i] + "' to '" + productValues[i] + "'" ) @@ -138,6 +143,12 @@ export class Product { let response = shop.shopifyGraphQLAPI(query.JSON) let product = response.content.data.productSet.product this.shopify_id = product.id + let productInventorySheet = + SpreadsheetApp.getActiveSpreadsheet().getSheetByName("product_inventory") + let row = getRowByColumnValue("product_inventory", "sku", this.sku) + getCellRangeByColumnName(productInventorySheet, "shopify_id", row).setValue( + this.shopify_id + ) if (newProduct) { console.log("UpdateShopifyProduct: setting defaults on new product") let item: shopify.InventoryItem @@ -153,9 +164,6 @@ export class Product { shop.UpdateInventoryItemQuantity(item, 1, config) console.log(JSON.stringify(response, null, 2)) } - // Update to include new changes - console.log("UpdateShopifyProduct: updating inventory match") - this.MatchToShopifyProduct(shop) } PublishToShopifyOnlineStore(shop: Shop) { diff --git a/src/match.ts b/src/match.ts index de3d7d2..0182658 100644 --- a/src/match.ts +++ b/src/match.ts @@ -1,5 +1,7 @@ import { Shop } from "./shopifyApi" import { Product } from "./Product" +import { toastAndLog } from "./sheetUtils" +import { getCellRangeByColumnName } from "./sheetUtils" export function matchProductToShopify(row: number) { console.log("row: " + row) @@ -18,7 +20,14 @@ export function updateProductToShopify(row: number) { console.log(product) product.ImportFromInventory(row) console.log(product) - product.MatchToShopifyProduct(shop) - console.log(product) + if (product.sku == "") { + toastAndLog("No SKU defined for the product on row " + row + "!") + let productInventorySheet = + SpreadsheetApp.getActiveSpreadsheet().getSheetByName("product_inventory") + getCellRangeByColumnName(productInventorySheet, "shopify_id", row).setValue( + "" + ) + return + } product.UpdateShopifyProduct(shop) } \ No newline at end of file diff --git a/src/triggers.ts b/src/triggers.ts index a718a6c..d973f25 100644 --- a/src/triggers.ts +++ b/src/triggers.ts @@ -6,5 +6,8 @@ export function reinstallTriggers() { let ss = SpreadsheetApp.getActive() ScriptApp.newTrigger("newSkuHandler").forSpreadsheet(ss).onEdit().create() - ScriptApp.newTrigger("matchProductToShopifyHandler").forSpreadsheet(ss).onEdit().create() + ScriptApp.newTrigger("matchProductToShopifyOnEditHandler") + .forSpreadsheet(ss) + .onEdit() + .create() } \ No newline at end of file