|
1 | 1 | import shopify from "../../shopify_developer_app.app.mjs"; |
2 | 2 | import common from "../common/metafield-actions.mjs"; |
3 | | -import utils from "@pipedream/shopify/common/utils.mjs"; |
4 | 3 |
|
5 | 4 | export default { |
6 | 5 | ...common, |
@@ -58,12 +57,6 @@ export default { |
58 | 57 | description: "A list of URLs of images to associate with the new product", |
59 | 58 | optional: true, |
60 | 59 | }, |
61 | | - options: { |
62 | | - type: "string[]", |
63 | | - label: "Options", |
64 | | - description: "The custom product properties. For example, Size, Color, and Material. Each product can have up to 3 options and each option value can be up to 255 characters. Product variants are made of up combinations of option values. Options cannot be created without values. To create new options, a variant with an associated option value also needs to be created. Example: `[{\"name\":\"Color\",\"values\":[{\"name\": \"Blue\"},{\"name\": \"Black\"}]},{\"name\":\"Size\",\"values\":[{\"name\": \"155\"},{\"name\": \"159\"}]}]`", |
65 | | - optional: true, |
66 | | - }, |
67 | 60 | tags: { |
68 | 61 | propDefinition: [ |
69 | 62 | shopify, |
@@ -99,23 +92,40 @@ export default { |
99 | 92 | async run({ $ }) { |
100 | 93 | const metafields = await this.createMetafieldsArray(this.metafields, this.productId, "product"); |
101 | 94 |
|
102 | | - const response = await this.shopify.updateProduct({ |
| 95 | + const args = { |
103 | 96 | input: { |
104 | 97 | id: this.productId, |
105 | 98 | title: this.title, |
106 | 99 | descriptionHtml: this.productDescription, |
107 | 100 | vendor: this.vendor, |
108 | 101 | productType: this.productType, |
109 | 102 | status: this.status, |
110 | | - images: utils.parseJson(this.images), |
111 | | - options: utils.parseJson(this.options), |
112 | 103 | tags: this.tags, |
113 | 104 | metafields, |
114 | | - metafields_global_title_tag: this.seoTitle, |
115 | | - metafields_global_description_tag: this.seoDescription, |
116 | 105 | handle: this.handle, |
117 | 106 | }, |
118 | | - }); |
| 107 | + }; |
| 108 | + |
| 109 | + if (this.seoTitle) { |
| 110 | + args.input.seo = { |
| 111 | + title: this.seoTitle, |
| 112 | + }; |
| 113 | + } |
| 114 | + if (this.seoDescription) { |
| 115 | + args.input.seo = { |
| 116 | + ...args.product?.seo, |
| 117 | + description: this.seoDescription, |
| 118 | + }; |
| 119 | + } |
| 120 | + |
| 121 | + if (this.images?.length) { |
| 122 | + args.media = this.images.map((originalSource) => ({ |
| 123 | + originalSource, |
| 124 | + mediaContentType: "IMAGE", |
| 125 | + })); |
| 126 | + } |
| 127 | + |
| 128 | + const response = await this.shopify.updateProduct(args); |
119 | 129 | if (response.productUpdate.userErrors.length > 0) { |
120 | 130 | throw new Error(response.productUpdate.userErrors[0].message); |
121 | 131 | } |
|
0 commit comments