misc fixes
* updateShopifyProductHandler acts on all selected rows * updateProductToShopify checks SKU more quickly * defaults are always set products
This commit is contained in:
@ -85,6 +85,7 @@ export class Product {
|
||||
}
|
||||
|
||||
MatchToShopifyProduct(shop: Shop): shopify.Product {
|
||||
// TODO: Look for and match based on known gid before SKU lookup
|
||||
let product = shop.GetProductBySku(this.sku)
|
||||
if (product == undefined || product.id == undefined || product.id == "") {
|
||||
console.log("MatchToShopifyProduct: no product matched")
|
||||
@ -171,10 +172,10 @@ export class Product {
|
||||
} while (item.id == "")
|
||||
console.log("UpdateShopifyProduct: publishing to online store")
|
||||
response = this.PublishToShopifyOnlineStore(shop)
|
||||
if (newProduct) {
|
||||
console.log("UpdateShopifyProduct: setting defaults on new product")
|
||||
console.log("UpdateShopifyProduct: setting defaults on inventory item")
|
||||
shop.SetInventoryItemDefaults(item, config)
|
||||
if (newProduct) {
|
||||
console.log("UpdateShopifyProduct: setting defaults on new product")
|
||||
console.log("UpdateShopifyProduct: adjusting inventory item quantity")
|
||||
shop.UpdateInventoryItemQuantity(item, 1, config)
|
||||
console.log(JSON.stringify(response, null, 2))
|
||||
|
||||
@ -3,6 +3,7 @@ import { fillProductFromTemplate } from "./fillProductFromTemplate"
|
||||
import { createMissingPhotoFolders } from "./createMissingPhotoFolders"
|
||||
import { matchProductToShopify, updateProductToShopify } from "./match"
|
||||
import { reinstallTriggers } from "./triggers"
|
||||
import { toastAndLog } from "./sheetUtils"
|
||||
|
||||
export function initMenu() {
|
||||
let ui = SpreadsheetApp.getUi()
|
||||
@ -48,9 +49,20 @@ export function updateShopifyProductHandler() {
|
||||
console.log("skipping edit on sheet " + sheet.getName())
|
||||
return
|
||||
}
|
||||
let row = SpreadsheetApp.getCurrentCell().getRow()
|
||||
let selectedRanges = SpreadsheetApp.getActiveRangeList().getRanges()
|
||||
if (selectedRanges == null || selectedRanges.length == 0) {
|
||||
toastAndLog("Select ranges to be updated")
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < selectedRanges.length; i++) {
|
||||
let range = selectedRanges[i]
|
||||
let firstRow = range.getRow()
|
||||
let lastRow = range.getLastRow()
|
||||
for (let row = firstRow; row <= lastRow; row++) {
|
||||
updateProductToShopify(row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function reauthorizeScript() {
|
||||
ScriptApp.invalidateAuth()
|
||||
|
||||
20
src/match.ts
20
src/match.ts
@ -1,6 +1,6 @@
|
||||
import { Shop } from "./shopifyApi"
|
||||
import { Product } from "./Product"
|
||||
import { toastAndLog } from "./sheetUtils"
|
||||
import { getCellValueByColumnName, toastAndLog } from "./sheetUtils"
|
||||
import { getCellRangeByColumnName } from "./sheetUtils"
|
||||
|
||||
export function matchProductToShopify(row: number) {
|
||||
@ -15,19 +15,19 @@ export function matchProductToShopify(row: number) {
|
||||
|
||||
export function updateProductToShopify(row: number) {
|
||||
console.log("row: " + row)
|
||||
let product = new Product()
|
||||
let shop = new Shop()
|
||||
console.log(product)
|
||||
product.ImportFromInventory(row)
|
||||
console.log(product)
|
||||
if (product.sku == "") {
|
||||
let sheet = SpreadsheetApp.getActive().getSheetByName("product_inventory")
|
||||
let sku = getCellValueByColumnName(sheet, "sku", row)
|
||||
console.log("sku: " + sku)
|
||||
if (sku == "" || sku.match(`\\?`)) {
|
||||
toastAndLog("No SKU defined for the product on row " + row + "!")
|
||||
let productInventorySheet =
|
||||
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("product_inventory")
|
||||
getCellRangeByColumnName(productInventorySheet, "shopify_id", row).setValue(
|
||||
getCellRangeByColumnName(sheet, "shopify_id", row).setValue(
|
||||
""
|
||||
)
|
||||
return
|
||||
}
|
||||
let product = new Product()
|
||||
product.ImportFromInventory(row)
|
||||
console.log(product)
|
||||
let shop = new Shop()
|
||||
product.UpdateShopifyProduct(shop)
|
||||
}
|
||||
Reference in New Issue
Block a user