allow multiple rows for template
This commit is contained in:
@ -1,6 +1,23 @@
|
||||
import { productTemplate } from "./productTemplate"
|
||||
import { toastAndLog } from "./sheetUtils"
|
||||
|
||||
export function fillProductFromTemplate() {
|
||||
let row = SpreadsheetApp.getCurrentCell().getRow()
|
||||
productTemplate(row)
|
||||
var sheet = SpreadsheetApp.getActive().getActiveSheet()
|
||||
if (sheet.getName() !== "product_inventory") {
|
||||
console.log("skipping edit on sheet " + sheet.getName())
|
||||
return
|
||||
}
|
||||
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++) {
|
||||
productTemplate(row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,13 +7,14 @@ import {
|
||||
} 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",
|
||||
"price",
|
||||
"base_price",
|
||||
"shipping",
|
||||
"weight (grams)",
|
||||
]
|
||||
@ -21,6 +22,7 @@ export function productTemplate(row: number) {
|
||||
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(
|
||||
@ -43,14 +45,14 @@ export function productTemplate(row: number) {
|
||||
)
|
||||
if (templateValue != "") {
|
||||
console.log(
|
||||
"template value for '" +
|
||||
updateColumn +
|
||||
"' is '" +
|
||||
templateValue +
|
||||
"'"
|
||||
"template value for '" + updateColumn + "' is '" + templateValue + "'"
|
||||
)
|
||||
toastAndLog("updating '" + updateColumn + "' to '" + templateValue + "'")
|
||||
let cell = getCellRangeByColumnName(productInventorySheet, updateColumn, row)
|
||||
let cell = getCellRangeByColumnName(
|
||||
productInventorySheet,
|
||||
updateColumn,
|
||||
row
|
||||
)
|
||||
cell.setValue(templateValue)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user