actually working dimension fields!
This commit is contained in:
@ -128,28 +128,6 @@ export class Product {
|
||||
sps.tags = this.tags
|
||||
sps.title = this.title
|
||||
sps.descriptionHtml = this.description
|
||||
sps.metafields = []
|
||||
if (this.product_height_cm > 0) {
|
||||
sps.metafields.push({
|
||||
key: "product_height_cm",
|
||||
namespace: "custom",
|
||||
value: this.product_height_cm.toString(),
|
||||
})
|
||||
}
|
||||
if (this.product_width_cm > 0) {
|
||||
sps.metafields.push({
|
||||
key: "product_width_cm",
|
||||
namespace: "custom",
|
||||
value: this.product_width_cm.toString(),
|
||||
})
|
||||
}
|
||||
if (this.product_depth_cm > 0) {
|
||||
sps.metafields.push({
|
||||
key: "product_depth_cm",
|
||||
namespace: "custom",
|
||||
value: this.product_width_cm.toString(),
|
||||
})
|
||||
}
|
||||
sps.variants = []
|
||||
let variant = new ShopifyVariant()
|
||||
//TODO: handle multiple variants
|
||||
@ -161,10 +139,6 @@ export class Product {
|
||||
if (this.compare_at_price > 0) {
|
||||
variant.compareAtPrice = this.compare_at_price
|
||||
}
|
||||
if (this.weight_grams > 0) {
|
||||
variant.inventory_item.measurement.weight.value = this.weight_grams
|
||||
variant.inventory_item.measurement.weight.unit = shopify.WeightUnit.GRAMS
|
||||
}
|
||||
sps.variants.push(variant)
|
||||
console.log("ToShopifyProductSet:\n" + JSON.stringify(sps, null, 2))
|
||||
//TODO: add initial inventory
|
||||
@ -204,6 +178,10 @@ export class Product {
|
||||
response = this.PublishToShopifyOnlineStore(shop)
|
||||
console.log("UpdateShopifyProduct: setting defaults on inventory item")
|
||||
shop.SetInventoryItemDefaults(item, config)
|
||||
if (this.weight_grams > 0) {
|
||||
console.log("UpdateShopifyProduct: setting weight on inventory item")
|
||||
shop.SetInventoryItemWeight(item, config, this.weight_grams, shopify.WeightUnit.GRAMS)
|
||||
}
|
||||
if (newProduct) {
|
||||
console.log("UpdateShopifyProduct: setting defaults on new product")
|
||||
console.log("UpdateShopifyProduct: adjusting inventory item quantity")
|
||||
@ -214,6 +192,7 @@ export class Product {
|
||||
this.UpdateDimensionMetafields(shop)
|
||||
}
|
||||
|
||||
// TODO: Make this a Product class method?
|
||||
UpdateDimensionMetafields(shop: Shop) {
|
||||
console.log("UpdateDimensionMetafields()")
|
||||
if (!this.shopify_id) {
|
||||
|
||||
@ -671,6 +671,43 @@ export class Shop {
|
||||
return newItem
|
||||
}
|
||||
|
||||
SetInventoryItemWeight(item: shopify.InventoryItem, config: Config, weight: number, weight_unit: shopify.WeightUnit) {
|
||||
let gql = /* GraphQL */ `
|
||||
mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) {
|
||||
inventoryItemUpdate(id: $id, input: $input) {
|
||||
inventoryItem {
|
||||
id
|
||||
measurement {
|
||||
weight {
|
||||
value
|
||||
unit
|
||||
}
|
||||
}
|
||||
}
|
||||
userErrors {
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
let variables = {
|
||||
id: item.id,
|
||||
input: {
|
||||
measurement: {
|
||||
weight: {
|
||||
value: weight,
|
||||
unit: weight_unit
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
let query = buildGqlQuery(gql, variables)
|
||||
let response = this.shopifyGraphQLAPI(query)
|
||||
let newItem: shopify.InventoryItem = response.content
|
||||
return newItem
|
||||
}
|
||||
|
||||
shopifyAPI(endpoint: string, query: {}, next = "") {
|
||||
var options: GoogleAppsScript.URL_Fetch.URLFetchRequestOptions = {
|
||||
method: "get",
|
||||
|
||||
Reference in New Issue
Block a user