mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 07:56:59 +00:00
chore: simplify cart function
This commit is contained in:
parent
d67e8f57c1
commit
63dbf7fc9e
@ -7,7 +7,7 @@ import { ExtendedCart, ExtendedLineItem, messageKeys } from 'lib/shopware/api-ex
|
||||
import { revalidateTag } from 'next/cache';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
export const fetchCart = async function (cartId?: string): Promise<ExtendedCart | undefined> {
|
||||
async function fetchCart(cartId?: string): Promise<ExtendedCart | undefined> {
|
||||
try {
|
||||
const apiClient = getApiClient(cartId);
|
||||
const cart = await apiClient.invoke('readCart get /checkout/cart?name', {});
|
||||
@ -21,7 +21,7 @@ export const fetchCart = async function (cartId?: string): Promise<ExtendedCart
|
||||
console.error('==>', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function addItem(prevState: any, selectedVariantId: string | undefined) {
|
||||
const cart = await getCart();
|
||||
@ -73,7 +73,7 @@ export async function addItem(prevState: any, selectedVariantId: string | undefi
|
||||
}
|
||||
}
|
||||
|
||||
async function getCart() {
|
||||
export async function getCart() {
|
||||
const cartId = cookies().get('sw-context-token')?.value;
|
||||
|
||||
if (cartId) {
|
||||
|
@ -1,17 +1,11 @@
|
||||
import { fetchCart } from 'components/cart/actions';
|
||||
import { cookies } from 'next/headers';
|
||||
import { getCart } from 'components/cart/actions';
|
||||
import CartModal from './modal';
|
||||
import { transformCart } from 'lib/shopware/transform';
|
||||
|
||||
export default async function Cart() {
|
||||
let resCart;
|
||||
const cartId = cookies().get('sw-context-token')?.value;
|
||||
|
||||
if (cartId) {
|
||||
resCart = await fetchCart(cartId);
|
||||
}
|
||||
|
||||
let cart;
|
||||
const resCart = await getCart();
|
||||
|
||||
if (resCart) {
|
||||
cart = transformCart(resCart);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user