Skip to content

Commit 840adc2

Browse files
authored
Merge pull request #129 from gadget-inc/wishlist-media
Wishlist template media update
2 parents a14ef5e + 808a0c3 commit 840adc2

File tree

26 files changed

+195
-169
lines changed

26 files changed

+195
-169
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
filter ($session: Session) on ShopifyFile [
2+
where shopId == $session.shopId
3+
]

shopify/wishlist-template/accessControl/filters/shopify/shopifyProductImage.gelly

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
filter ($session: Session) on ShopifyProductMedia [
2+
where shopId == $session.shopId
3+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
filter ($session: Session) on ShopifyFile [
2+
where shopId == $session.shopId
3+
]

shopify/wishlist-template/accessControl/filters/shopifyProductImage/storefront-customer/tenancy.gelly

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
filter ($session: Session) on ShopifyProductMedia [
2+
where shopId == $session.shopId
3+
]

shopify/wishlist-template/accessControl/permissions.gadget.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export const permissions: GadgetPermissions = {
1818
"accessControl/filters/shopify/shopifyCustomer.gelly",
1919
},
2020
},
21+
shopifyFile: {
22+
read: {
23+
filter: "accessControl/filters/shopify/shopifyFile.gelly",
24+
},
25+
},
2126
shopifyGdprRequest: {
2227
read: {
2328
filter:
@@ -34,10 +39,10 @@ export const permissions: GadgetPermissions = {
3439
"accessControl/filters/shopify/shopifyProduct.gelly",
3540
},
3641
},
37-
shopifyProductImage: {
42+
shopifyProductMedia: {
3843
read: {
3944
filter:
40-
"accessControl/filters/shopify/shopifyProductImage.gelly",
45+
"accessControl/filters/shopify/shopifyProductMedia.gelly",
4146
},
4247
},
4348
shopifyProductVariant: {
@@ -97,16 +102,21 @@ export const permissions: GadgetPermissions = {
97102
"accessControl/filters/shopify/storefront-customers/shopifyCustomer.gelly",
98103
},
99104
},
105+
shopifyFile: {
106+
read: {
107+
filter: "accessControl/filters/shopifyFile/tenancy.gelly",
108+
},
109+
},
100110
shopifyProduct: {
101111
read: {
102112
filter:
103113
"accessControl/filters/shopifyProduct/storefront-customers/tenancy.gelly",
104114
},
105115
},
106-
shopifyProductImage: {
116+
shopifyProductMedia: {
107117
read: {
108118
filter:
109-
"accessControl/filters/shopifyProductImage/storefront-customer/tenancy.gelly",
119+
"accessControl/filters/shopifyProductMedia/tenancy.gelly",
110120
},
111121
},
112122
shopifyProductVariant: {
@@ -127,7 +137,7 @@ export const permissions: GadgetPermissions = {
127137
},
128138
actions: {
129139
create: true,
130-
delete: true,
140+
update: true,
131141
},
132142
},
133143
wishlistItem: {
@@ -137,6 +147,7 @@ export const permissions: GadgetPermissions = {
137147
},
138148
actions: {
139149
delete: true,
150+
update: true,
140151
},
141152
},
142153
},

shopify/wishlist-template/api/actions/sendWishlistEmail.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import type { Changes } from "../utilities/types";
33
import { renderEmail } from "../utilities";
44
import type { Customer } from "./startCustomerUpdates";
55

6+
type ImageField = {
7+
id: string;
8+
width: number;
9+
height: number;
10+
originalSrc: string;
11+
};
12+
613
export const run: ActionRun = async ({
714
params,
815
logger,
@@ -42,10 +49,10 @@ export const run: ActionRun = async ({
4249
price: true,
4350
product: {
4451
title: true,
45-
images: {
52+
media: {
4653
edges: {
4754
node: {
48-
source: true,
55+
image: true,
4956
alt: true,
5057
},
5158
},
@@ -79,9 +86,14 @@ export const run: ActionRun = async ({
7986
)
8087
continue;
8188

82-
const image = variant.product?.images?.edges?.[0]?.node;
89+
const imageNode = variant.product?.media?.edges?.[0]?.node;
8390

84-
if (!image || !image?.alt || !image?.source) continue;
91+
if (
92+
!imageNode ||
93+
!imageNode?.alt ||
94+
!(imageNode?.image as ImageField).originalSrc
95+
)
96+
continue;
8597

8698
if (variant.deleted) {
8799
count++;
@@ -92,8 +104,8 @@ export const run: ActionRun = async ({
92104
title: variant.title,
93105
productTitle: variant.product?.title,
94106
image: {
95-
source: image.source,
96-
alt: image.alt,
107+
source: (imageNode?.image as ImageField)?.originalSrc ?? "",
108+
alt: imageNode.alt,
97109
},
98110
};
99111
}
@@ -108,8 +120,8 @@ export const run: ActionRun = async ({
108120
price: variant.price,
109121
compareAtPrice: variant.compareAtPrice,
110122
image: {
111-
source: image.source,
112-
alt: image.alt,
123+
source: (imageNode?.image as ImageField)?.originalSrc ?? "",
124+
alt: imageNode.alt,
113125
},
114126
};
115127
}

shopify/wishlist-template/api/models/shopifyProductImage/actions/create.ts renamed to shopify/wishlist-template/api/models/shopifyFile/actions/create.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
import { applyParams, save, ActionOptions } from "gadget-server";
22
import { preventCrossShopDataAccess } from "gadget-server/shopify";
33

4-
export const run: ActionRun = async ({
5-
params,
6-
record,
7-
logger,
8-
api,
9-
connections,
10-
}) => {
4+
export const run: ActionRun = async ({ params, record, logger, api, connections }) => {
115
applyParams(params, record);
126
await preventCrossShopDataAccess(params, record);
137
await save(record);
148
};
159

16-
export const onSuccess: ActionOnSuccess = async ({
17-
params,
18-
record,
19-
logger,
20-
api,
21-
connections,
22-
}) => {
10+
export const onSuccess: ActionOnSuccess = async ({ params, record, logger, api, connections }) => {
2311
// Your logic goes here
2412
};
2513

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { deleteRecord, ActionOptions } from "gadget-server";
2+
import { preventCrossShopDataAccess } from "gadget-server/shopify";
3+
4+
export const run: ActionRun = async ({ params, record, logger, api, connections }) => {
5+
await preventCrossShopDataAccess(params, record);
6+
await deleteRecord(record);
7+
};
8+
9+
export const onSuccess: ActionOnSuccess = async ({ params, record, logger, api, connections }) => {
10+
// Your logic goes here
11+
};
12+
13+
export const options: ActionOptions = { actionType: "delete" };

0 commit comments

Comments
 (0)