Skip to content

Commit 2f746a5

Browse files
committed
actions updates
1 parent 8230734 commit 2f746a5

File tree

74 files changed

+2947
-2192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2947
-2192
lines changed
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import shopify from "../../shopify.app.mjs";
2-
import common from "./common.mjs";
32

43
export default {
5-
...common,
64
key: "shopify-add-product-to-custom-collection",
7-
name: "Add Products to Custom Collections",
8-
description: "Adds a product or products to a custom collection or collections. [See the documentation](https://shopify.dev/docs/api/admin-rest/2023-01/resources/collect#post-collects)",
9-
version: "0.0.6",
5+
name: "Add Products to Custom Collection",
6+
description: "Adds a product or products to a custom collection. [See the documentation](https://shopify.dev/docs/api/admin-graphql/latest/mutations/collectionAddProductsV2)",
7+
version: "0.0.7",
108
type: "action",
119
props: {
1210
shopify,
@@ -18,15 +16,23 @@ export default {
1816
type: "string[]",
1917
label: "Product IDs",
2018
},
21-
collectionIds: {
19+
collectionId: {
2220
propDefinition: [
2321
shopify,
2422
"collectionId",
2523
],
26-
type: "string[]",
27-
label: "Collection IDs",
28-
description: "IDs of the collections that the product will be added to",
2924
optional: false,
3025
},
3126
},
27+
async run({ $ }) {
28+
const response = await this.shopify.addProductsToCollection({
29+
id: this.collectionId,
30+
productIds: this.productIds,
31+
});
32+
if (response.collectionAddProductsV2.userErrors.length > 0) {
33+
throw new Error(response.collectionAddProductsV2.userErrors[0].message);
34+
}
35+
$.export("$summary", `Added product(s) \`${this.productIds}\` to collection \`${this.collectionId}\``);
36+
return response;
37+
},
3238
};

components/shopify/actions/add-product-to-custom-collection/common.mjs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,72 @@
11
import shopify from "../../shopify.app.mjs";
2-
import common from "./common.mjs";
32

43
export default {
5-
...common,
6-
name: "Add Tags",
7-
version: "0.0.12",
84
key: "shopify-add-tags",
9-
description: "Add tags. [See the documentation](https://shopify.dev/api/admin-graphql/2022-07/mutations/tagsadd)",
5+
name: "Add Tags",
6+
description: "Add tags. [See the documentation](https://shopify.dev/docs/api/admin-graphql/latest/mutations/tagsAdd)",
7+
version: "0.0.13",
108
type: "action",
119
props: {
1210
shopify,
13-
...common.props,
11+
resource: {
12+
type: "string",
13+
label: "Resource Type",
14+
description: "The Shopify Admin API resource type.",
15+
options: [
16+
"Product",
17+
"Customer",
18+
"Order",
19+
"DraftOrder",
20+
"Article",
21+
],
22+
reloadProps: true,
23+
},
24+
gid: {
25+
type: "string",
26+
label: "Resource ID",
27+
description: "The Shopify Admin Resource ID. For example, the ID of a Product, Customer, Order, DraftOrder, or OnlineStoreArticle. Can be found at the end of the URL in Shopify Admin.",
28+
},
29+
tags: {
30+
propDefinition: [
31+
shopify,
32+
"tags",
33+
],
34+
},
35+
},
36+
async additionalProps(existingProps) {
37+
const props = {};
38+
if (!this.resource) {
39+
return props;
40+
}
41+
if (this.resource === "Product") {
42+
props.gid = {
43+
...existingProps.gid,
44+
options: async ({ prevContext }) => {
45+
try {
46+
return await this.shopify.getPropOptions({
47+
resourceFn: this.shopify.listProducts,
48+
resourceKeys: [
49+
"products",
50+
],
51+
prevContext,
52+
});
53+
} catch {
54+
console.log("Unable to fetch product options");
55+
}
56+
},
57+
};
58+
}
59+
return props;
60+
},
61+
async run({ $ }) {
62+
const response = await this.shopify.addTags({
63+
gid: this.gid,
64+
tags: this.tags,
65+
});
66+
if (response.tagsAdd.userErrors.length > 0) {
67+
throw new Error(response.tagsAdd.userErrors[0].message);
68+
}
69+
$.export("$summary", `Added tag(s) \`${this.tags}\` with id \`${response.tagsAdd.node.id}\``);
70+
return response;
1471
},
1572
};

components/shopify/actions/add-tags/common.mjs

Lines changed: 0 additions & 46 deletions
This file was deleted.

components/shopify/actions/common/common.mjs

Lines changed: 0 additions & 22 deletions
This file was deleted.

components/shopify/actions/common/consts.mjs renamed to components/shopify/actions/common/constants.mjs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ const RESOURCE_TYPES = [
77
label: "Collection",
88
value: "collection",
99
},
10-
{
11-
label: "Customer",
12-
value: "customer",
13-
},
14-
{
15-
label: "Draft Order",
16-
value: "draft_order",
17-
},
1810
{
1911
label: "Page",
2012
value: "page",
@@ -23,10 +15,6 @@ const RESOURCE_TYPES = [
2315
label: "Product",
2416
value: "product",
2517
},
26-
{
27-
label: "Product Image",
28-
value: "product_image",
29-
},
3018
{
3119
label: "Product Variant",
3220
value: "variants",
@@ -35,10 +23,6 @@ const RESOURCE_TYPES = [
3523
label: "Article",
3624
value: "article",
3725
},
38-
{
39-
label: "Order",
40-
value: "order",
41-
},
4226
];
4327

4428
const METAFIELD_TYPES = {

0 commit comments

Comments
 (0)