From e7faa7cb2d420157b65ca1643b492a8e64aa4969 Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Tue, 4 Jun 2024 04:32:50 +0200 Subject: [PATCH 1/2] Update .gitignore and .graphqlrc.ts for admin-2024-04 schema, adjust updatePrice for location-based shipping --- .gitignore | 3 +-- .graphqlrc.ts | 4 ++-- .../product/update/update-price.ts | 21 +++++++++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 6d9aa654..bfd1c0e8 100644 --- a/.gitignore +++ b/.gitignore @@ -104,6 +104,5 @@ __azurite_db*__.json app/lib/api/model app/lib/api/*.ts app/lib/zod -admin-2023-10.schema.json -admin-2024-01.schema.json +admin-2024-04.schema.json admin.types.d.ts \ No newline at end of file diff --git a/.graphqlrc.ts b/.graphqlrc.ts index a10fbfe1..f572fbd0 100644 --- a/.graphqlrc.ts +++ b/.graphqlrc.ts @@ -1,12 +1,12 @@ import { ApiType, shopifyApiProject } from "@shopify/api-codegen-preset"; export default { - schema: "https://shopify.dev/admin-graphql-direct-proxy/2024-01", + schema: "https://shopify.dev/admin-graphql-direct-proxy/2024-04", documents: ["./src/**/*.{ts,tsx}"], projects: { default: shopifyApiProject({ apiType: ApiType.Admin, - apiVersion: "2024-01", + apiVersion: "2024-04", documents: ["./src/**/*.{ts,tsx}"], outputDir: "./src/types", }), diff --git a/src/functions/customer/orchestrations/product/update/update-price.ts b/src/functions/customer/orchestrations/product/update/update-price.ts index b7fc6c9c..8d8bd544 100644 --- a/src/functions/customer/orchestrations/product/update/update-price.ts +++ b/src/functions/customer/orchestrations/product/update/update-price.ts @@ -1,4 +1,5 @@ import { CustomerProductServiceGet } from "~/functions/customer/services/product/get"; +import { LocationTypes } from "~/functions/location"; import { shopifyAdmin } from "~/library/shopify"; export const updatePriceName = "updatePrice"; @@ -9,10 +10,15 @@ export const updatePrice = async ({ customerId: number; productId: number; }) => { - const { variantId, price, compareAtPrice } = await CustomerProductServiceGet({ - customerId, - productId, - }); + const { variantId, price, compareAtPrice, locations } = + await CustomerProductServiceGet({ + customerId, + productId, + }); + + const isDestination = locations.some( + (l) => l.locationType === LocationTypes.DESTINATION + ); const { data } = await shopifyAdmin().request(PRODUCT_PRICE_UPDATE, { variables: { @@ -22,6 +28,13 @@ export const updatePrice = async ({ id: `gid://shopify/ProductVariant/${variantId}`, price: price.amount, compareAtPrice: compareAtPrice.amount, + ...(isDestination + ? { + inventoryItem: { + requiresShipping: false, + }, + } + : {}), }, ], }, From 68a532b06e43a38589556f2a53fd3716ebf88121 Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Tue, 4 Jun 2024 04:40:41 +0200 Subject: [PATCH 2/2] Add requiresShipping field to inventoryItem in update-price.spec --- .../orchestrations/product/update/update-price.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/functions/customer/orchestrations/product/update/update-price.spec.ts b/src/functions/customer/orchestrations/product/update/update-price.spec.ts index 8aa8f160..740394ae 100644 --- a/src/functions/customer/orchestrations/product/update/update-price.spec.ts +++ b/src/functions/customer/orchestrations/product/update/update-price.spec.ts @@ -99,6 +99,9 @@ describe("CustomerProductUpdateOrchestration", () => { ?.variants.nodes[0].id, price: product.price?.amount, compareAtPrice: product.compareAtPrice?.amount, + inventoryItem: { + requiresShipping: false, + }, }, ], },