refactor: fix cart items routing

This commit is contained in:
Bolaji 2022-02-08 06:52:50 +01:00
parent 8cac636022
commit 4dbe8b5bce
No known key found for this signature in database
GPG Key ID: 00342E72694643BB
6 changed files with 27 additions and 22 deletions

View File

@ -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,

View File

@ -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,
},

View File

@ -44,8 +44,8 @@ export const handler: MutationHook<any> = {
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,
},

View File

@ -34,7 +34,7 @@ export const handler: MutationHook<any> = {
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,

View File

@ -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": "<p><span>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.</span></p>",
"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
}