From 4dbe8b5bcefdf46e5ae5ab51e07a1edaa9212cd2 Mon Sep 17 00:00:00 2001 From: Bolaji Date: Tue, 8 Feb 2022 06:52:50 +0100 Subject: [PATCH] refactor: fix cart items routing --- .../wishlist/{index.tsx => index.ts} | 0 .../api/operations/get-product.ts | 2 +- .../api/utils/normalizeLineItems.ts | 7 +++- framework/commercelayer/cart/use-add-item.tsx | 4 +-- .../commercelayer/cart/use-update-item.tsx | 2 +- framework/commercelayer/data.json | 34 +++++++++---------- 6 files changed, 27 insertions(+), 22 deletions(-) rename framework/commercelayer/api/endpoints/wishlist/{index.tsx => index.ts} (100%) diff --git a/framework/commercelayer/api/endpoints/wishlist/index.tsx b/framework/commercelayer/api/endpoints/wishlist/index.ts similarity index 100% rename from framework/commercelayer/api/endpoints/wishlist/index.tsx rename to framework/commercelayer/api/endpoints/wishlist/index.ts diff --git a/framework/commercelayer/api/operations/get-product.ts b/framework/commercelayer/api/operations/get-product.ts index 42026c167..bbfb5cd77 100644 --- a/framework/commercelayer/api/operations/get-product.ts +++ b/framework/commercelayer/api/operations/get-product.ts @@ -1,8 +1,8 @@ import type { CommercelayerConfig } from '../index' import { Product } from '@commerce/types/product' import { GetProductOperation } from '@commerce/types/product' -import data from '../../data.json' import type { OperationContext } from '@commerce/api/operations' +import data from '../../data.json' export default function getProductOperation({ commerce, diff --git a/framework/commercelayer/api/utils/normalizeLineItems.ts b/framework/commercelayer/api/utils/normalizeLineItems.ts index d0ebdd72d..e68fccef5 100644 --- a/framework/commercelayer/api/utils/normalizeLineItems.ts +++ b/framework/commercelayer/api/utils/normalizeLineItems.ts @@ -1,3 +1,6 @@ +import { is } from '@react-spring/shared' +import data from '../../data.json' + export default function normalizeLineItems(lineItems: any[]) { return lineItems .filter((l) => { @@ -6,9 +9,11 @@ export default function normalizeLineItems(lineItems: any[]) { .map((lineItem) => { const id = lineItem.id const attributes = lineItem.attributes + const products = data.products return { id, name: attributes.name, + path: products.find((p) => p.id === attributes.reference)?.slug, productId: attributes.reference, variantId: attributes.reference, quantity: attributes.quantity, @@ -20,7 +25,7 @@ export default function normalizeLineItems(lineItems: any[]) { price: attributes.unit_amount_float, image: { url: `https://data.commercelayer.app/vercel-provider/${attributes.reference}_FLAT.png`, - altText: 'Black Women Long Sleeve Shirt', + altText: attributes.name, width: 1000, height: 1000, }, diff --git a/framework/commercelayer/cart/use-add-item.tsx b/framework/commercelayer/cart/use-add-item.tsx index 51f242eac..7b74b4d1d 100644 --- a/framework/commercelayer/cart/use-add-item.tsx +++ b/framework/commercelayer/cart/use-add-item.tsx @@ -44,8 +44,8 @@ export const handler: MutationHook = { sku: input.variantId, price: attributes.unit_amount_float, image: { - url: `/commercelayer_assets/${input.productId}_FLAT.png`, - altText: 'Black Women Long Sleeve Shirt', + url: `https://data.commercelayer.app/vercel-provider/${input.productId}_FLAT.png`, + altText: attributes.name, width: 1000, height: 1000, }, diff --git a/framework/commercelayer/cart/use-update-item.tsx b/framework/commercelayer/cart/use-update-item.tsx index 363de4167..0d36a3d28 100644 --- a/framework/commercelayer/cart/use-update-item.tsx +++ b/framework/commercelayer/cart/use-update-item.tsx @@ -34,7 +34,7 @@ export const handler: MutationHook = { sku: lineItem.data.sku_code, price: attributes.unit_amount_float, image: { - url: `/commercelayer_assets/${item.variantId}_FLAT.png`, + url: `https://data.commercelayer.app/vercel-provider/${item.variantId}_FLAT.png`, altText: 'Black Women Long Sleeve Shirt', width: 1000, height: 1000, diff --git a/framework/commercelayer/data.json b/framework/commercelayer/data.json index c5b073d9f..85179e129 100644 --- a/framework/commercelayer/data.json +++ b/framework/commercelayer/data.json @@ -4,27 +4,27 @@ "id": "SHIRTWLS000000FFFFFF", "name": "Black Women Long Sleeve Shirt", "brandId": "Commerce Layer", - "path": "/women-long-sleeve-shirt", - "slug": "women-long-sleeve-shirt", + "path": "/black-women-long-sleeve-shirt", + "slug": "black-women-long-sleeve-shirt", "categoryId": "clothings", "price": { "value": 50, "currencyCode": "USD" }, "descriptionHtml": "

This relaxed long sleeve tee combines the best of both worlds, proving that cozy can also be chic. 65/35 polyester/viscose. Drop shoulder. Curved bottom hem.

", "images": [ { "url": "https://data.commercelayer.app/vercel-provider/SHIRTWLS000000FFFFFF_FLAT.png", - "altText": "Black Women Long Sleeve Shirt", + "altText": " A Black Women Long Sleeve Shirt", "width": 1000, "height": 1000 }, { "url": "https://data.commercelayer.app/vercel-provider/SHIRTWLS000000FFFFFF_01.png", - "altText": "Black Women Long Sleeve Shirt", + "altText": " A Black Women Long Sleeve Shirt", "width": 1000, "height": 1000 }, { "url": "https://data.commercelayer.app/vercel-provider/SHIRTWLS000000FFFFFF_02.png", - "altText": "Black Women Long Sleeve Shirt", + "altText": " A Black Women Long Sleeve Shirt", "width": 1000, "height": 1000 } @@ -134,19 +134,19 @@ "images": [ { "url": "https://data.commercelayer.app/vercel-provider/EMUG12OZFFFFFF000000_FLAT.png", - "altText": "White Enamel Mug", + "altText": " A White Enamel Mug", "width": 1000, "height": 1000 }, { "url": "https://data.commercelayer.app/vercel-provider/EMUG12OZFFFFFF000000_01.png", - "altText": "White Enamel Mug", + "altText": " A White Enamel Mug", "width": 1000, "height": 1000 }, { "url": "https://data.commercelayer.app/vercel-provider/EMUG12OZFFFFFF000000_02.png", - "altText": "White Enamel Mug", + "altText": " A White Enamel Mug", "width": 1000, "height": 1000 } @@ -202,25 +202,25 @@ "images": [ { "url": "https://data.commercelayer.app/vercel-provider/VFLEXFIT000000FFFFFF_FLAT.png", - "altText": "Black Visor Flexfit", + "altText": " A Black Visor Flexfit", "width": 1000, "height": 1000 }, { "url": "https://data.commercelayer.app/vercel-provider/VFLEXFIT000000FFFFFF_01.png", - "altText": "Black Visor Flexfit", + "altText": " A Black Visor Flexfit", "width": 1000, "height": 1000 }, { "url": "https://data.commercelayer.app/vercel-provider/VFLEXFIT000000FFFFFF_02.png", - "altText": "Black Visor Flexfit", + "altText": " A Black Visor Flexfit", "width": 1000, "height": 1000 }, { "url": "https://data.commercelayer.app/vercel-provider/VFLEXFIT000000FFFFFF_03.png", - "altText": "Black Visor Flexfit", + "altText": " A Black Visor Flexfit", "width": 1000, "height": 1000 } @@ -276,7 +276,7 @@ "images": [ { "url": "https://data.commercelayer.app/vercel-provider/FACEMASK000000FFFFFF_FLAT.png", - "altText": "Black Face Mask", + "altText": " A Black Face Mask", "width": 1000, "height": 1000 } @@ -332,7 +332,7 @@ "images": [ { "url": "https://data.commercelayer.app/vercel-provider/SHIRTWLS9397A0000000_FLAT.png", - "altText": "Gray Women Long Sleeve Shirt", + "altText": " A Gray Women Long Sleeve Shirt", "width": 1000, "height": 1000 } @@ -442,7 +442,7 @@ "images": [ { "url": "https://data.commercelayer.app/vercel-provider/FACEMASKFFFFFF000000_FLAT.png", - "altText": "White Face Mask", + "altText": " A White Face Mask", "width": 1000, "height": 1000 } @@ -498,7 +498,7 @@ "images": [ { "url": "https://data.commercelayer.app/vercel-provider/BEANIEXXFFFFFF000000_FLAT.png", - "altText": "White Beanie", + "altText": " A White Beanie", "width": 1000, "height": 1000 } @@ -554,7 +554,7 @@ "images": [ { "url": "https://data.commercelayer.app/vercel-provider/DUFFLBAGFFFFFF000000_FLAT.png", - "altText": "White Face Mask", + "altText": " A White Face Mask", "width": 1000, "height": 1000 }