don't try to update if there is no SKU
This commit is contained in:
@ -4,6 +4,7 @@ import { getCellRangeByColumnName } from "./sheetUtils"
|
|||||||
import { matchProductToShopify } from "./match"
|
import { matchProductToShopify } from "./match"
|
||||||
|
|
||||||
export function onEditHandler(e: GoogleAppsScript.Events.SheetsOnEdit) {
|
export function onEditHandler(e: GoogleAppsScript.Events.SheetsOnEdit) {
|
||||||
|
//TODO: process each edited row
|
||||||
newSkuHandler(e)
|
newSkuHandler(e)
|
||||||
matchProductToShopifyOnEditHandler(e)
|
matchProductToShopifyOnEditHandler(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,6 +63,11 @@ export class Product {
|
|||||||
console.log("productValues:" + productValues)
|
console.log("productValues:" + productValues)
|
||||||
for (let i = 0; i < headers.length; i++) {
|
for (let i = 0; i < headers.length; i++) {
|
||||||
if (this.hasOwnProperty(headers[i])) {
|
if (this.hasOwnProperty(headers[i])) {
|
||||||
|
if (productValues[i] == "?") {
|
||||||
|
console.log("skipping '" + headers[i] + "'")
|
||||||
|
this[headers[i]] = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
console.log(
|
console.log(
|
||||||
"setting value for '" + headers[i] + "' to '" + productValues[i] + "'"
|
"setting value for '" + headers[i] + "' to '" + productValues[i] + "'"
|
||||||
)
|
)
|
||||||
@ -138,6 +143,12 @@ export class Product {
|
|||||||
let response = shop.shopifyGraphQLAPI(query.JSON)
|
let response = shop.shopifyGraphQLAPI(query.JSON)
|
||||||
let product = response.content.data.productSet.product
|
let product = response.content.data.productSet.product
|
||||||
this.shopify_id = product.id
|
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) {
|
if (newProduct) {
|
||||||
console.log("UpdateShopifyProduct: setting defaults on new product")
|
console.log("UpdateShopifyProduct: setting defaults on new product")
|
||||||
let item: shopify.InventoryItem
|
let item: shopify.InventoryItem
|
||||||
@ -153,9 +164,6 @@ export class Product {
|
|||||||
shop.UpdateInventoryItemQuantity(item, 1, config)
|
shop.UpdateInventoryItemQuantity(item, 1, config)
|
||||||
console.log(JSON.stringify(response, null, 2))
|
console.log(JSON.stringify(response, null, 2))
|
||||||
}
|
}
|
||||||
// Update to include new changes
|
|
||||||
console.log("UpdateShopifyProduct: updating inventory match")
|
|
||||||
this.MatchToShopifyProduct(shop)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PublishToShopifyOnlineStore(shop: Shop) {
|
PublishToShopifyOnlineStore(shop: Shop) {
|
||||||
|
|||||||
13
src/match.ts
13
src/match.ts
@ -1,5 +1,7 @@
|
|||||||
import { Shop } from "./shopifyApi"
|
import { Shop } from "./shopifyApi"
|
||||||
import { Product } from "./Product"
|
import { Product } from "./Product"
|
||||||
|
import { toastAndLog } from "./sheetUtils"
|
||||||
|
import { getCellRangeByColumnName } from "./sheetUtils"
|
||||||
|
|
||||||
export function matchProductToShopify(row: number) {
|
export function matchProductToShopify(row: number) {
|
||||||
console.log("row: " + row)
|
console.log("row: " + row)
|
||||||
@ -18,7 +20,14 @@ export function updateProductToShopify(row: number) {
|
|||||||
console.log(product)
|
console.log(product)
|
||||||
product.ImportFromInventory(row)
|
product.ImportFromInventory(row)
|
||||||
console.log(product)
|
console.log(product)
|
||||||
product.MatchToShopifyProduct(shop)
|
if (product.sku == "") {
|
||||||
console.log(product)
|
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)
|
product.UpdateShopifyProduct(shop)
|
||||||
}
|
}
|
||||||
@ -6,5 +6,8 @@ export function reinstallTriggers() {
|
|||||||
|
|
||||||
let ss = SpreadsheetApp.getActive()
|
let ss = SpreadsheetApp.getActive()
|
||||||
ScriptApp.newTrigger("newSkuHandler").forSpreadsheet(ss).onEdit().create()
|
ScriptApp.newTrigger("newSkuHandler").forSpreadsheet(ss).onEdit().create()
|
||||||
ScriptApp.newTrigger("matchProductToShopifyHandler").forSpreadsheet(ss).onEdit().create()
|
ScriptApp.newTrigger("matchProductToShopifyOnEditHandler")
|
||||||
|
.forSpreadsheet(ss)
|
||||||
|
.onEdit()
|
||||||
|
.create()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user