Fix: Correct dummy CartProduct structure in getCart

Resolves a TypeScript type error in `lib/shopify/index.ts` where
the dummy data for `getCart`'s `lines.merchandise.product` did not
match the `CartProduct` type.

Specifically, properties like `availableForSale`, `description`,
`descriptionHtml`, and `images` (array) were removed from the
nested `product` objects within the dummy cart lines. The
`featuredImage` property was ensured to be a single object
conforming to the `Image` type.

This change aligns the dummy cart data with the type definitions in
`lib/shopify/types.ts`, fixing the build error:
"Object literal may only specify known properties, and 'X' does not
exist in type 'CartProduct'."
This commit is contained in:
google-labs-jules[bot] 2025-05-23 05:47:44 +00:00
parent cde034d799
commit 9016b4df92

View File

@ -36,7 +36,7 @@ import {
Cart, // Ensure Cart type is imported Cart, // Ensure Cart type is imported
Collection, Collection,
Connection, Connection,
Image, Image, // Image type is needed for featuredImage
Menu, // Menu type is essential Menu, // Menu type is essential
Page, Page,
Product, Product,
@ -282,13 +282,12 @@ export async function updateCart(
export async function getCart(): Promise<Cart | undefined> { export async function getCart(): Promise<Cart | undefined> {
console.log('getCart called - returning dummy cart data / undefined.'); // For observability console.log('getCart called - returning dummy cart data / undefined.'); // For observability
// Using Option 2 from the example: Return a basic dummy cart structure
const dummyCart: Cart = { const dummyCart: Cart = {
id: 'dummy-cart-id-123', id: 'dummy-cart-id-123',
checkoutUrl: '/cart-checkout', // Or some placeholder checkoutUrl: '/cart-checkout',
cost: { cost: {
subtotalAmount: { amount: '100.00', currencyCode: 'USD' }, subtotalAmount: { amount: '100.00', currencyCode: 'USD' },
totalAmount: { amount: '105.00', currencyCode: 'USD' }, // Including some dummy tax/shipping totalAmount: { amount: '105.00', currencyCode: 'USD' },
totalTaxAmount: { amount: '5.00', currencyCode: 'USD' } totalTaxAmount: { amount: '5.00', currencyCode: 'USD' }
}, },
lines: [ lines: [
@ -300,29 +299,19 @@ export async function getCart(): Promise<Cart | undefined> {
}, },
merchandise: { merchandise: {
id: 'dummy-merch-id-1', id: 'dummy-merch-id-1',
title: 'Dummy Product A', title: 'Dummy Product A', // This is merchandise.title (variant title)
selectedOptions: [{ name: 'Color', value: 'Red' }], selectedOptions: [{ name: 'Color', value: 'Red' }],
product: { // Ensure this matches the Product type expected by CartLine.merchandise.product product: { // This is the CartProduct
id: 'dummy-prod-id-A', id: 'dummy-prod-id-A',
handle: 'dummy-product-a', handle: 'dummy-product-a',
title: 'Dummy Product A', title: 'Dummy Product A', // This is product.title
// featuredImage, priceRange, etc., might be needed if CartLine.merchandise.product expects a full Product featuredImage: {
// For this dummy data, keeping it minimal as per example. url: '/placeholder-product-a.jpg',
// Add other Product fields if Cart type expects them from merchandise.product altText: 'Dummy Product A Image',
// Based on current 'Product' type, these are the minimum required: width: 100,
availableForSale: true, height: 100
description: 'A dummy product', }
descriptionHtml: '<p>A dummy product</p>', // Removed: availableForSale, description, descriptionHtml, images (array), options, priceRange, seo, tags, updatedAt, variants
images: [], // Assuming empty array is acceptable or provide dummy images
options: [],
priceRange: {
maxVariantPrice: { amount: '25.00', currencyCode: 'USD' },
minVariantPrice: { amount: '25.00', currencyCode: 'USD' }
},
seo: { title: 'Dummy Product A', description: 'Dummy A' },
tags: [],
updatedAt: new Date().toISOString(),
variants: [], // Assuming empty array is acceptable or provide dummy variants
} }
} }
}, },
@ -334,25 +323,19 @@ export async function getCart(): Promise<Cart | undefined> {
}, },
merchandise: { merchandise: {
id: 'dummy-merch-id-2', id: 'dummy-merch-id-2',
title: 'Dummy Product B', title: 'Dummy Product B', // Merchandise.title
selectedOptions: [{ name: 'Size', value: 'M' }], selectedOptions: [{ name: 'Size', value: 'M' }],
product: { // Ensure this matches the Product type expected by CartLine.merchandise.product product: { // This is the CartProduct
id: 'dummy-prod-id-B', id: 'dummy-prod-id-B',
handle: 'dummy-product-b', handle: 'dummy-product-b',
title: 'Dummy Product B', title: 'Dummy Product B', // Product.title
availableForSale: true, featuredImage: {
description: 'Another dummy product', url: '/placeholder-product-b.jpg',
descriptionHtml: '<p>Another dummy product</p>', altText: 'Dummy Product B Image',
images: [], width: 100,
options: [], height: 100
priceRange: { }
maxVariantPrice: { amount: '50.00', currencyCode: 'USD' }, // Removed: availableForSale, description, descriptionHtml, images (array), options, priceRange, seo, tags, updatedAt, variants
minVariantPrice: { amount: '50.00', currencyCode: 'USD' }
},
seo: { title: 'Dummy Product B', description: 'Dummy B' },
tags: [],
updatedAt: new Date().toISOString(),
variants: [],
} }
} }
} }
@ -360,12 +343,9 @@ export async function getCart(): Promise<Cart | undefined> {
totalQuantity: 3 totalQuantity: 3
}; };
await new Promise(resolve => setTimeout(resolve, 50)); // Simulate delay await new Promise(resolve => setTimeout(resolve, 50));
// To test the "empty cart" scenario, you can conditionally return undefined or dummyCart here.
// For now, let's return the dummyCart.
return dummyCart; return dummyCart;
// return undefined; // Use this to test how Navbar/CartProvider handles no cart
} }