File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use server' ;
22
3- import { TAGS } from 'lib/constants' ;
43import { addToCart , removeFromCart , updateCart } from 'lib/bigcommerce' ;
4+ import { TAGS } from 'lib/constants' ;
55import { revalidateTag } from 'next/cache' ;
66import { cookies } from 'next/headers' ;
77
@@ -70,8 +70,13 @@ export async function updateItemQuantity(
7070
7171 try {
7272 if ( quantity === 0 ) {
73- await removeFromCart ( cartId , [ lineId ] ) ;
73+ const response = await removeFromCart ( cartId , [ lineId ] ) ;
7474 revalidateTag ( TAGS . cart ) ;
75+
76+ if ( ! response && cartId ) {
77+ cookies ( ) . delete ( 'cartId' ) ;
78+ }
79+
7580 return ;
7681 }
7782
Original file line number Diff line number Diff line change 11import { isVercelCommerceError } from 'lib/type-guards' ;
2+ import { notFound } from 'next/navigation' ;
23import { NextRequest , NextResponse } from 'next/server' ;
34import { BIGCOMMERCE_GRAPHQL_API_ENDPOINT } from './constants' ;
45
@@ -81,7 +82,7 @@ const getEntityIdByHandle = async (entityHandle: string) => {
8182 }
8283 } ) ;
8384
84- return res . body . data . site . route . node . entityId ;
85+ return res . body . data . site . route . node ? .entityId ;
8586} ;
8687
8788export async function bigCommerceFetch < T > ( {
@@ -585,6 +586,11 @@ export async function getMenu(handle: string): Promise<VercelMenu[]> {
585586
586587export async function getPage ( handle : string ) : Promise < VercelPage > {
587588 const entityId = await getEntityIdByHandle ( handle ) ;
589+
590+ if ( ! entityId ) {
591+ notFound ( ) ;
592+ }
593+
588594 const res = await bigCommerceFetch < BigCommercePageOperation > ( {
589595 query : getPageQuery ,
590596 variables : {
You can’t perform that action at this time.
0 commit comments