combine metafields update

This commit is contained in:
Ben Miller
2025-09-29 22:51:21 -06:00
parent 5b6db0eece
commit 66c711916e

View File

@ -11,11 +11,14 @@ import {
VariantOptionValueInput, VariantOptionValueInput,
formatGqlForJSON, formatGqlForJSON,
} from "./shopifyApi" } from "./shopifyApi"
import * as shopify from 'shopify-admin-api-typings' import * as shopify from "shopify-admin-api-typings"
import { getCellRangeByColumnName, getRowByColumnValue, vlookupByColumns } from "./sheetUtils" import {
getCellRangeByColumnName,
getRowByColumnValue,
vlookupByColumns,
} from "./sheetUtils"
import { Config } from "./config" import { Config } from "./config"
export class Product { export class Product {
shopify_id: string = "" shopify_id: string = ""
title: string = "" title: string = ""
@ -116,11 +119,21 @@ export class Product {
} }
ShopifyCategory(): string { ShopifyCategory(): string {
return vlookupByColumns("values", "product_type", this.product_type, "shopify_category") return vlookupByColumns(
"values",
"product_type",
this.product_type,
"shopify_category"
)
} }
EbayCategory(): string { EbayCategory(): string {
return vlookupByColumns("values", "product_type", this.product_type, "ebay_category_id") return vlookupByColumns(
"values",
"product_type",
this.product_type,
"ebay_category_id"
)
} }
ToShopifyProductSet() { ToShopifyProductSet() {
@ -191,7 +204,12 @@ export class Product {
shop.SetInventoryItemDefaults(item, config) shop.SetInventoryItemDefaults(item, config)
if (this.weight_grams > 0) { if (this.weight_grams > 0) {
console.log("UpdateShopifyProduct: setting weight on inventory item") console.log("UpdateShopifyProduct: setting weight on inventory item")
shop.SetInventoryItemWeight(item, config, this.weight_grams, shopify.WeightUnit.GRAMS) shop.SetInventoryItemWeight(
item,
config,
this.weight_grams,
shopify.WeightUnit.GRAMS
)
} }
if (newProduct) { if (newProduct) {
console.log("UpdateShopifyProduct: setting defaults on new product") console.log("UpdateShopifyProduct: setting defaults on new product")
@ -199,9 +217,8 @@ export class Product {
shop.UpdateInventoryItemQuantity(item, 1, config) shop.UpdateInventoryItemQuantity(item, 1, config)
console.log(JSON.stringify(response, null, 2)) console.log(JSON.stringify(response, null, 2))
} }
// update dimension metafields // update all metafields
this.UpdateDimensionMetafields(shop) this.UpdateAllMetafields(shop)
this.UpdateEbayCategoryMetafield(shop)
} }
UpdateEbayCategoryMetafield(shop: Shop) { UpdateEbayCategoryMetafield(shop: Shop) {