working version checkin

*  add config class
*  add vlookup
*  add menu
*  add photo folder creation
*  add prep for product templates
This commit is contained in:
Ben Miller
2024-11-04 20:44:19 -07:00
parent b6b75e426c
commit 20a5e738f7
7 changed files with 142 additions and 0 deletions

View File

@ -0,0 +1,49 @@
function createMissingPhotoFolders() {
let ss = SpreadsheetApp.getActive()
let s = ss.getSheetByName("product_inventory")
let config = new Config()
let photoParent = DriveApp.getFolderById(config.productPhotosFolderId)
let skus = getColumnValuesByName(s, "sku")
let photoLinks = getColumnValuesByName(s, "photos")
let created: string[] = []
let folderItr = photoParent.getFolders()
let folderNames: string[] = []
console.log("getting list of existing folders...")
while (folderItr.hasNext()) {
let folder = folderItr.next()
folderNames.push(folder.getName())
}
console.log("existing folders: " + folderNames.join(", "))
for (let i = 0; i < skus.length; i++) {
let sku = String(skus[i][0])
let updateLink: boolean = false
if (null == sku || sku == "") {
continue
}
if (folderNames.includes(sku)) {
console.log("folder '" + sku + "' already exists")
} else {
console.log("creating folder '" + skus[i] + "'")
photoParent.createFolder(sku)
created.push(sku)
updateLink = true
}
// Update photos cell
if (photoLinks[i][0] != "" && !updateLink) {
continue
}
console.log("updating photos cell for '" + sku + "'")
let photosCell = getCellRangeByColumnName(s, "photos", i + 2)
let folder = photoParent.getFoldersByName(sku).next()
let url = folder.getUrl()
let linkValue = SpreadsheetApp.newRichTextValue()
.setText(sku)
.setLinkUrl(url)
.build()
photosCell.setRichTextValue(linkValue)
}
toastAndLog("created " + created.length + " folders: " + created.join(", "))
}