Files
product_inventory/src/productTemplate.ts
2025-07-31 21:21:20 -06:00

65 lines
1.7 KiB
TypeScript

import { newSku } from "./newSku"
import {
getCellRangeByColumnName,
getCellValueByColumnName,
toastAndLog,
vlookupByColumns,
} from "./sheetUtils"
export function productTemplate(row: number) {
//TODO: just use the columns that exist, if they match
let updateColumns = [
"function",
"type",
"category",
"product_type",
"tags",
"base_price",
"shipping",
"weight_grams",
"product_width_cm",
"product_depth_cm",
"product_height_cm",
]
let productInventorySheet =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("product_inventory")
let titleValue = getCellValueByColumnName(productInventorySheet, "title", row)
//TODO: Make this *much* faster
for (let i = 0; i < updateColumns.length; i++) {
let updateColumn = updateColumns[i]
let currentValue = getCellValueByColumnName(
productInventorySheet,
updateColumns[i],
row
)
if (currentValue != "") {
console.log(
"current value for '" + updateColumn + "' is '" + currentValue + "'"
)
continue
}
var templateValue: string = ""
templateValue = vlookupByColumns(
"product_types",
"title",
titleValue,
updateColumn
)
if (templateValue != "") {
console.log(
"template value for '" + updateColumn + "' is '" + templateValue + "'"
)
toastAndLog("updating '" + updateColumn + "' to '" + templateValue + "'")
let cell = getCellRangeByColumnName(
productInventorySheet,
updateColumn,
row
)
cell.setValue(templateValue)
}
}
console.log("updating sku...")
newSku(row)
}