Skip to content

Commit

Permalink
Changed from productImage to productMedia
Browse files Browse the repository at this point in the history
  • Loading branch information
DevAOC committed Oct 24, 2024
1 parent d71285c commit 4cdf9d4
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
filter ($session: Session) on ShopifyFile [
where shopId == $session.shopId
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
filter ($session: Session) on ShopifyProductMedia [
where shopId == $session.shopId
]
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export const permissions: GadgetPermissions = {
"accessControl/filters/shopify/shopifyCustomer.gelly",
},
},
shopifyFile: {
read: {
filter: "accessControl/filters/shopify/shopifyFile.gelly",
},
actions: {
create: true,
delete: true,
update: true,
},
},
shopifyGdprRequest: {
read: {
filter:
Expand Down Expand Up @@ -59,10 +69,10 @@ export const permissions: GadgetPermissions = {
update: true,
},
},
shopifyProductImage: {
shopifyProductMedia: {
read: {
filter:
"accessControl/filters/shopify/shopifyProductImage.gelly",
"accessControl/filters/shopify/shopifyProductMedia.gelly",
},
actions: {
create: true,
Expand Down
20 changes: 13 additions & 7 deletions shopify/product-reviews-template/api/actions/fetchOrderData.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ export async function run({ params, logger, api, connections }) {
product: {
id: true,
title: true,
images: {
edges: {
node: {
source: true,
},
featuredMedia: {
file: {
url: true,
alt: true,
},
},
},
Expand All @@ -54,14 +53,21 @@ export async function run({ params, logger, api, connections }) {
const products = [];

for (const {
product: { id, title, images },
product: {
id,
title,
featuredMedia: {
file: { alt, url },
},
},
} of allLineItems) {
if (!seen[id]) {
seen[id] = true;
products.push({
id: id,
title: title,
image: images.edges[0].node.source,
image: url,
alt,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ActionOptions, ScheduledShopifySyncGlobalActionContext } from "gadget-server";
import { globalShopifySync } from "gadget-server/shopify";

const HourInMs = 60 * 60 * 1000;

/**
* @param { ScheduledShopifySyncGlobalActionContext } context
*/
export async function run({ params, logger, api, connections }) {
const syncOnlyModels = connections.shopify.enabledModels
.filter(model => model.syncOnly)
.map(model => model.apiIdentifier);

const syncSince = new Date(Date.now() - 25 * HourInMs)

await globalShopifySync({
apiKeys: connections.shopify.apiKeys,
syncSince,
models: syncOnlyModels
});
};

/** @type { ActionOptions } */
export const options = {
triggers: {
scheduler: [
{
every: "day",
at: "14:21 UTC",
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const schema: GadgetModel = {
"lastName",
"lastOrder",
"lastOrderName",
"locale",
"marketingOptInLevel",
"metafield",
"multipassIdentifier",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { applyParams, save, ActionOptions, CreateShopifyProductImageActionContext } from "gadget-server";
import { applyParams, save, ActionOptions, CreateShopifyFileActionContext } from "gadget-server";
import { preventCrossShopDataAccess } from "gadget-server/shopify";

/**
* @param { CreateShopifyProductImageActionContext } context
* @param { CreateShopifyFileActionContext } context
*/
export async function run({ params, record, logger, api, connections }) {
applyParams(params, record);
Expand All @@ -11,7 +11,7 @@ export async function run({ params, record, logger, api, connections }) {
};

/**
* @param { CreateShopifyProductImageActionContext } context
* @param { CreateShopifyFileActionContext } context
*/
export async function onSuccess({ params, record, logger, api, connections }) {
// Your logic goes here
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { deleteRecord, ActionOptions, DeleteShopifyFileActionContext } from "gadget-server";
import { preventCrossShopDataAccess } from "gadget-server/shopify";

/**
* @param { DeleteShopifyFileActionContext } context
*/
export async function run({ params, record, logger, api, connections }) {
await preventCrossShopDataAccess(params, record);
await deleteRecord(record);
};

/**
* @param { DeleteShopifyFileActionContext } context
*/
export async function onSuccess({ params, record, logger, api, connections }) {
// Your logic goes here
};

/** @type { ActionOptions } */
export const options = { actionType: "delete" };
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { applyParams, save, ActionOptions, UpdateShopifyProductImageActionContext } from "gadget-server";
import { applyParams, save, ActionOptions, UpdateShopifyFileActionContext } from "gadget-server";
import { preventCrossShopDataAccess } from "gadget-server/shopify";

/**
* @param { UpdateShopifyProductImageActionContext } context
* @param { UpdateShopifyFileActionContext } context
*/
export async function run({ params, record, logger, api, connections }) {
applyParams(params, record);
Expand All @@ -11,7 +11,7 @@ export async function run({ params, record, logger, api, connections }) {
};

/**
* @param { UpdateShopifyProductImageActionContext } context
* @param { UpdateShopifyFileActionContext } context
*/
export async function onSuccess({ params, record, logger, api, connections }) {
// Your logic goes here
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { GadgetModel } from "gadget-server";

// This file describes the schema for the "shopifyFile" model, go to https://product-reviews-template.gadget.app/edit to view/edit your model in Gadget
// For more information on how to update this file http://docs.gadget.dev

export const schema: GadgetModel = {
type: "gadget/model-schema/v1",
storageKey: "DataModel-Shopify-File",
fields: {},
shopify: {
fields: [
"alt",
"boundingBox",
"duration",
"embedUrl",
"fileErrors",
"fileStatus",
"filename",
"host",
"image",
"mediaContentType",
"mediaErrors",
"mediaWarnings",
"mimetype",
"originUrl",
"originalFileSize",
"originalSource",
"preview",
"product",
"shop",
"shopifyCreatedAt",
"shopifyUpdatedAt",
"sources",
"status",
"type",
"url",
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export const schema: GadgetModel = {
"body",
"category",
"compareAtPriceRange",
"featuredMedia",
"handle",
"images",
"hasVariantsThatRequiresComponents",
"media",
"orderLineItems",
"productCategory",
"productType",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { applyParams, save, ActionOptions, CreateShopifyProductMediaActionContext } from "gadget-server";
import { preventCrossShopDataAccess } from "gadget-server/shopify";

/**
* @param { CreateShopifyProductMediaActionContext } context
*/
export async function run({ params, record, logger, api, connections }) {
applyParams(params, record);
await preventCrossShopDataAccess(params, record);
await save(record);
};

/**
* @param { CreateShopifyProductMediaActionContext } context
*/
export async function onSuccess({ params, record, logger, api, connections }) {
// Your logic goes here
};

/** @type { ActionOptions } */
export const options = { actionType: "create" };
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { deleteRecord, ActionOptions, DeleteShopifyProductImageActionContext } from "gadget-server";
import { deleteRecord, ActionOptions, DeleteShopifyProductMediaActionContext } from "gadget-server";
import { preventCrossShopDataAccess } from "gadget-server/shopify";

/**
* @param { DeleteShopifyProductImageActionContext } context
* @param { DeleteShopifyProductMediaActionContext } context
*/
export async function run({ params, record, logger, api, connections }) {
await preventCrossShopDataAccess(params, record);
await deleteRecord(record);
};

/**
* @param { DeleteShopifyProductImageActionContext } context
* @param { DeleteShopifyProductMediaActionContext } context
*/
export async function onSuccess({ params, record, logger, api, connections }) {
// Your logic goes here
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { applyParams, save, ActionOptions, UpdateShopifyProductMediaActionContext } from "gadget-server";
import { preventCrossShopDataAccess } from "gadget-server/shopify";

/**
* @param { UpdateShopifyProductMediaActionContext } context
*/
export async function run({ params, record, logger, api, connections }) {
applyParams(params, record);
await preventCrossShopDataAccess(params, record);
await save(record);
};

/**
* @param { UpdateShopifyProductMediaActionContext } context
*/
export async function onSuccess({ params, record, logger, api, connections }) {
// Your logic goes here
};

/** @type { ActionOptions } */
export const options = { actionType: "update" };
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import type { GadgetModel } from "gadget-server";

// This file describes the schema for the "shopifyProductImage" model, go to https://product-reviews-template.gadget.app/edit to view/edit your model in Gadget
// This file describes the schema for the "shopifyProductMedia" model, go to https://product-reviews-template.gadget.app/edit to view/edit your model in Gadget
// For more information on how to update this file http://docs.gadget.dev

export const schema: GadgetModel = {
type: "gadget/model-schema/v1",
storageKey: "DataModel-Shopify-ProductImage",
storageKey: "DataModel-Shopify-ProductMedia",
fields: {},
shopify: {
fields: [
"alt",
"height",
"featuredMediaForProduct",
"file",
"position",
"product",
"shop",
"shopifyCreatedAt",
"shopifyUpdatedAt",
"source",
"width",
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const schema: GadgetModel = {
"eligibleForPayments",
"email",
"enabledPresentmentCurrencies",
"files",
"finances",
"forceSsl",
"gdprRequests",
Expand Down Expand Up @@ -80,7 +81,7 @@ export const schema: GadgetModel = {
"planName",
"preLaunchEnabled",
"primaryLocale",
"productImages",
"productMedia",
"products",
"province",
"provinceCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ document.addEventListener("DOMContentLoaded", () => {
for (let i = 0; i < window.reviews.length; i++) {
const reviewDiv = document.getElementById(`review-${i}`);

console.log(parseFloat(reviews[i].rating.value));

for (let j = 1; j <= 5; j++) {
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg.setAttribute("viewBox", "-2.15 -2.15 58.17 58.17");
Expand Down
3 changes: 2 additions & 1 deletion shopify/product-reviews-template/settings.gadget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export const settings: GadgetSettings = {
apiVersion: "2024-10",
enabledModels: [
"shopifyCustomer",
"shopifyFile",
"shopifyOrder",
"shopifyOrderLineItem",
"shopifyProduct",
"shopifyProductImage",
"shopifyProductMedia",
],
type: "partner",
scopes: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { api } from "../api";
import { useState } from "react";
import Stars from "./Stars";

export default ({ id: productId, title, orderId, image }) => {
export default ({ id: productId, title, orderId, image, alt }) => {
const [open, setOpen] = useState(false);
const [completed, setCompleted] = useState(false);

Expand All @@ -33,7 +33,10 @@ export default ({ id: productId, title, orderId, image }) => {
<BlockStack gap="300">
<InlineStack align="space-between" blockAlign="center">
<InlineStack blockAlign="center" gap="400">
<Thumbnail source={image || ImageIcon} />
<Thumbnail
source={image || ImageIcon}
alt={alt || "Image placeholder"}
/>
<Text as="h2" variant="headingMd">
{title}
</Text>
Expand Down

0 comments on commit 4cdf9d4

Please sign in to comment.