a little bit farther
This commit is contained in:
@ -552,10 +552,13 @@ export class Shop {
|
||||
var url = this.buildURL(endpoint)
|
||||
console.log(UrlFetchApp.getRequest(url, options))
|
||||
var resp = UrlFetchApp.fetch(url, options)
|
||||
console.log(resp.getContentText())
|
||||
let content = resp.getContentText()
|
||||
console.log(content)
|
||||
let content_json = JSON.parse(content)
|
||||
console.log(JSON.stringify(content_json, null, 2))
|
||||
|
||||
return {
|
||||
content: JSON.parse(resp.getContentText()),
|
||||
content: content_json,
|
||||
headers: resp.getHeaders(),
|
||||
}
|
||||
}
|
||||
@ -614,7 +617,7 @@ export class ShopifyProduct {
|
||||
body_html: string
|
||||
created_at: Date
|
||||
handle: string
|
||||
id: number
|
||||
id: string
|
||||
images: ProductImage[]
|
||||
options: ProductOption[]
|
||||
product_type: string
|
||||
@ -625,10 +628,14 @@ export class ShopifyProduct {
|
||||
template_suffix: string
|
||||
title: string
|
||||
updated_at: Date
|
||||
variants: ShopifyProductVariant[]
|
||||
variants: ShopifyVariantNodes
|
||||
vendor: string
|
||||
}
|
||||
|
||||
export class ShopifyVariantNodes {
|
||||
nodes: ShopifyProductVariant[]
|
||||
}
|
||||
|
||||
class ProductImage {
|
||||
id: number
|
||||
product_id: number
|
||||
@ -642,11 +649,25 @@ class ProductImage {
|
||||
}
|
||||
|
||||
class ProductOption {
|
||||
id: number
|
||||
id: string
|
||||
product_id: number
|
||||
name: string
|
||||
position: number
|
||||
values: string[]
|
||||
optionValues?: ShopifyProductOptionValues
|
||||
}
|
||||
|
||||
export class ShopifyProductOptionValues {
|
||||
id?: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
export class ShopifyVariantOptionValueInput {
|
||||
id?: string
|
||||
linkedMetafieldValue?: string
|
||||
name?: string
|
||||
optionId?: string
|
||||
optionName?: string
|
||||
}
|
||||
|
||||
export class ShopifyProductVariant {
|
||||
@ -657,7 +678,7 @@ export class ShopifyProductVariant {
|
||||
grams: number
|
||||
weight: number
|
||||
weight_unit: string
|
||||
id: number
|
||||
id: string
|
||||
inventory_item_id: number
|
||||
inventory_management: string
|
||||
inventory_policy: string
|
||||
@ -680,9 +701,39 @@ class Products {
|
||||
|
||||
class ProductEdge {
|
||||
node: ShopifyProduct
|
||||
variants?: ShopifyVariants
|
||||
options?: ShopifyProductOption[]
|
||||
cursor: string
|
||||
}
|
||||
|
||||
export class ShopifyProductOption {
|
||||
id?: string
|
||||
name?: string
|
||||
optionValues?: ShopifyProductOptionValue[]
|
||||
values?: ShopifyProductOptionValue[]
|
||||
}
|
||||
|
||||
export class ShopifyProductOptionValue {
|
||||
id?: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
export class ShopifyVariants {
|
||||
nodes?: ShopifyVariant[]
|
||||
node?: ShopifyVariant
|
||||
}
|
||||
|
||||
export class ShopifyVariant {
|
||||
id?: string
|
||||
sku?: string
|
||||
price?: number
|
||||
compareAtPrice?: number
|
||||
barcode?: string
|
||||
position?: number
|
||||
nodes?: ShopifyProductVariant[]
|
||||
optionValues?: VariantOptionValueInput[]
|
||||
}
|
||||
|
||||
class PageInfo {
|
||||
hasNextPage: boolean
|
||||
hasPreviousPage: boolean
|
||||
@ -714,7 +765,22 @@ export class ShopifyProductsQuery {
|
||||
this.GQL = `{
|
||||
products(first: ${pageSize}${cursorText}${queryText}) {
|
||||
edges {
|
||||
node { ${fields.join(" ")} }
|
||||
node {
|
||||
${fields.join(" ")}
|
||||
variants(first:1) {
|
||||
nodes {
|
||||
id
|
||||
}
|
||||
}
|
||||
options {
|
||||
id
|
||||
name
|
||||
optionValues {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
@ -736,38 +802,35 @@ export class ShopifyProductsResponse {
|
||||
}
|
||||
|
||||
export class ShopifyProductSetQuery {
|
||||
GQL: string
|
||||
JSON: JSON
|
||||
constructor(
|
||||
query: string = "",
|
||||
fields: string[] = ["id", "title", "handle"],
|
||||
cursor: string = "",
|
||||
pageSize: number = 10
|
||||
) {
|
||||
let cursorText: string
|
||||
if (cursor == "") {
|
||||
cursorText = ""
|
||||
} else {
|
||||
cursorText = `, after: "${cursor}"`
|
||||
GQL: string = `mutation setProduct($productSet: ProductSetInput!) {
|
||||
productSet(input: $productSet) {
|
||||
product {
|
||||
id
|
||||
}
|
||||
let queryText: string
|
||||
if (query == "") {
|
||||
queryText = ""
|
||||
} else {
|
||||
queryText = `, query: "${query}"`
|
||||
productSetOperation {
|
||||
id
|
||||
status
|
||||
userErrors {
|
||||
code
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
this.GQL = `{
|
||||
products(first: ${pageSize}${cursorText}${queryText}) {
|
||||
edges {
|
||||
node { ${fields.join(" ")} }
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
userErrors {
|
||||
code
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`
|
||||
let j = `{"query": ${formatGqlForJSON(this.GQL)}}`
|
||||
JSON: JSON
|
||||
constructor(product: ShopifyProductSetInput, synchronous: boolean = true) {
|
||||
let j = `{
|
||||
"query": ${formatGqlForJSON(this.GQL)},
|
||||
"variables": {
|
||||
"productSet": ${JSON.stringify(product)}
|
||||
}
|
||||
}`
|
||||
console.log(j)
|
||||
this.JSON = JSON.parse(j)
|
||||
}
|
||||
@ -782,8 +845,30 @@ export class ShopifyProductSetInput {
|
||||
status: string = "DRAFT"
|
||||
tags: string
|
||||
title: string
|
||||
variants: ShopifyProductVariant[]
|
||||
vendor: string
|
||||
variants: ShopifyVariant[]
|
||||
productOptions: ShopifyProductOption[]
|
||||
}
|
||||
|
||||
export class ProductVariantSetInput {
|
||||
barcode: string
|
||||
compareAtPrice: number
|
||||
id: string
|
||||
optionValues: VariantOptionValueInput[] = []
|
||||
position?: number
|
||||
price?: number
|
||||
requiresComponents?: boolean
|
||||
sku?: string
|
||||
taxable?: boolean
|
||||
taxCode?: string
|
||||
}
|
||||
|
||||
export class VariantOptionValueInput {
|
||||
id?: string
|
||||
linkedMetafieldValue?: string
|
||||
name?: string
|
||||
optionId?: string
|
||||
optionName?: string
|
||||
}
|
||||
|
||||
function formatGqlForJSON(gql: string) {
|
||||
|
||||
Reference in New Issue
Block a user