Skip to content

Commit 7723d78

Browse files
committed
fix update-product
1 parent 9d1f228 commit 7723d78

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

components/shopify_developer_app/actions/update-product/update-product.mjs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import shopify from "../../shopify_developer_app.app.mjs";
22
import common from "../common/metafield-actions.mjs";
3-
import utils from "@pipedream/shopify/common/utils.mjs";
43

54
export default {
65
...common,
@@ -58,12 +57,6 @@ export default {
5857
description: "A list of URLs of images to associate with the new product",
5958
optional: true,
6059
},
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-
},
6760
tags: {
6861
propDefinition: [
6962
shopify,
@@ -99,23 +92,40 @@ export default {
9992
async run({ $ }) {
10093
const metafields = await this.createMetafieldsArray(this.metafields, this.productId, "product");
10194

102-
const response = await this.shopify.updateProduct({
95+
const args = {
10396
input: {
10497
id: this.productId,
10598
title: this.title,
10699
descriptionHtml: this.productDescription,
107100
vendor: this.vendor,
108101
productType: this.productType,
109102
status: this.status,
110-
images: utils.parseJson(this.images),
111-
options: utils.parseJson(this.options),
112103
tags: this.tags,
113104
metafields,
114-
metafields_global_title_tag: this.seoTitle,
115-
metafields_global_description_tag: this.seoDescription,
116105
handle: this.handle,
117106
},
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);
119129
if (response.productUpdate.userErrors.length > 0) {
120130
throw new Error(response.productUpdate.userErrors[0].message);
121131
}

0 commit comments

Comments
 (0)