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 {
|
MatchToShopifyProduct(shop: Shop): shopify.Product {
|
||||||
|
// TODO: Look for and match based on known gid before SKU lookup
|
||||||
let product = shop.GetProductBySku(this.sku)
|
let product = shop.GetProductBySku(this.sku)
|
||||||
if (product == undefined || product.id == undefined || product.id == "") {
|
if (product == undefined || product.id == undefined || product.id == "") {
|
||||||
console.log("MatchToShopifyProduct: no product matched")
|
console.log("MatchToShopifyProduct: no product matched")
|
||||||
@ -171,10 +172,10 @@ export class Product {
|
|||||||
} while (item.id == "")
|
} while (item.id == "")
|
||||||
console.log("UpdateShopifyProduct: publishing to online store")
|
console.log("UpdateShopifyProduct: publishing to online store")
|
||||||
response = this.PublishToShopifyOnlineStore(shop)
|
response = this.PublishToShopifyOnlineStore(shop)
|
||||||
|
console.log("UpdateShopifyProduct: setting defaults on inventory item")
|
||||||
|
shop.SetInventoryItemDefaults(item, config)
|
||||||
if (newProduct) {
|
if (newProduct) {
|
||||||
console.log("UpdateShopifyProduct: setting defaults on new product")
|
console.log("UpdateShopifyProduct: setting defaults on new product")
|
||||||
console.log("UpdateShopifyProduct: setting defaults on inventory item")
|
|
||||||
shop.SetInventoryItemDefaults(item, config)
|
|
||||||
console.log("UpdateShopifyProduct: adjusting inventory item quantity")
|
console.log("UpdateShopifyProduct: adjusting inventory item quantity")
|
||||||
shop.UpdateInventoryItemQuantity(item, 1, config)
|
shop.UpdateInventoryItemQuantity(item, 1, config)
|
||||||
console.log(JSON.stringify(response, null, 2))
|
console.log(JSON.stringify(response, null, 2))
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { fillProductFromTemplate } from "./fillProductFromTemplate"
|
|||||||
import { createMissingPhotoFolders } from "./createMissingPhotoFolders"
|
import { createMissingPhotoFolders } from "./createMissingPhotoFolders"
|
||||||
import { matchProductToShopify, updateProductToShopify } from "./match"
|
import { matchProductToShopify, updateProductToShopify } from "./match"
|
||||||
import { reinstallTriggers } from "./triggers"
|
import { reinstallTriggers } from "./triggers"
|
||||||
|
import { toastAndLog } from "./sheetUtils"
|
||||||
|
|
||||||
export function initMenu() {
|
export function initMenu() {
|
||||||
let ui = SpreadsheetApp.getUi()
|
let ui = SpreadsheetApp.getUi()
|
||||||
@ -48,8 +49,19 @@ export function updateShopifyProductHandler() {
|
|||||||
console.log("skipping edit on sheet " + sheet.getName())
|
console.log("skipping edit on sheet " + sheet.getName())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let row = SpreadsheetApp.getCurrentCell().getRow()
|
let selectedRanges = SpreadsheetApp.getActiveRangeList().getRanges()
|
||||||
updateProductToShopify(row)
|
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() {
|
export function reauthorizeScript() {
|
||||||
|
|||||||
20
src/match.ts
20
src/match.ts
@ -1,6 +1,6 @@
|
|||||||
import { Shop } from "./shopifyApi"
|
import { Shop } from "./shopifyApi"
|
||||||
import { Product } from "./Product"
|
import { Product } from "./Product"
|
||||||
import { toastAndLog } from "./sheetUtils"
|
import { getCellValueByColumnName, toastAndLog } from "./sheetUtils"
|
||||||
import { getCellRangeByColumnName } from "./sheetUtils"
|
import { getCellRangeByColumnName } from "./sheetUtils"
|
||||||
|
|
||||||
export function matchProductToShopify(row: number) {
|
export function matchProductToShopify(row: number) {
|
||||||
@ -15,19 +15,19 @@ export function matchProductToShopify(row: number) {
|
|||||||
|
|
||||||
export function updateProductToShopify(row: number) {
|
export function updateProductToShopify(row: number) {
|
||||||
console.log("row: " + row)
|
console.log("row: " + row)
|
||||||
let product = new Product()
|
let sheet = SpreadsheetApp.getActive().getSheetByName("product_inventory")
|
||||||
let shop = new Shop()
|
let sku = getCellValueByColumnName(sheet, "sku", row)
|
||||||
console.log(product)
|
console.log("sku: " + sku)
|
||||||
product.ImportFromInventory(row)
|
if (sku == "" || sku.match(`\\?`)) {
|
||||||
console.log(product)
|
|
||||||
if (product.sku == "") {
|
|
||||||
toastAndLog("No SKU defined for the product on row " + row + "!")
|
toastAndLog("No SKU defined for the product on row " + row + "!")
|
||||||
let productInventorySheet =
|
getCellRangeByColumnName(sheet, "shopify_id", row).setValue(
|
||||||
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("product_inventory")
|
|
||||||
getCellRangeByColumnName(productInventorySheet, "shopify_id", row).setValue(
|
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let product = new Product()
|
||||||
|
product.ImportFromInventory(row)
|
||||||
|
console.log(product)
|
||||||
|
let shop = new Shop()
|
||||||
product.UpdateShopifyProduct(shop)
|
product.UpdateShopifyProduct(shop)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user