mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 07:56:59 +00:00
wip: Saving work
This commit is contained in:
parent
c044d494a4
commit
b7d78faaf0
@ -23,7 +23,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
const awardsPage = await getPage({ handle: 'awards', language: params?.locale?.toUpperCase() });
|
||||
|
@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -29,7 +29,7 @@ export default async function DisclosuresPage({
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -45,7 +45,9 @@ export default async function HomePage({
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
console.debug({ cartId });
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
console.debug({ cart });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -29,7 +29,7 @@ export default async function PrivacyPage({
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -28,7 +28,7 @@ export default async function ProductLayout({
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -30,8 +30,6 @@ export async function generateMetadata({
|
||||
language: params?.locale?.toUpperCase()
|
||||
});
|
||||
|
||||
console.debug({ product });
|
||||
|
||||
if (!product) return notFound();
|
||||
|
||||
const { url, width, height, altText: alt } = product.featuredImage || {};
|
||||
|
@ -29,7 +29,7 @@ export default async function ProductPage({
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -39,7 +39,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
const page = await getPage({ handle: 'shop-list', language: params?.locale?.toUpperCase() });
|
||||
|
@ -28,7 +28,7 @@ export default async function BlogLayout({
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -28,7 +28,7 @@ export default async function StoriesPage({
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -27,7 +27,7 @@ export default async function TermsPage({
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -1,14 +1,21 @@
|
||||
'use server';
|
||||
|
||||
import { SupportedLocale } from 'components/layout/navbar/language-control';
|
||||
import { addToCart, createCart, getCart, removeFromCart, updateCart } from 'lib/shopify';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
export const addItem = async (variantId: string | undefined): Promise<String | undefined> => {
|
||||
export const addItem = async ({
|
||||
variantId,
|
||||
locale
|
||||
}: {
|
||||
variantId: string | undefined;
|
||||
locale?: string;
|
||||
}): Promise<String | undefined> => {
|
||||
let cartId = cookies().get('cartId')?.value;
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
if (!cartId || !cart) {
|
||||
@ -30,16 +37,18 @@ export const addItem = async (variantId: string | undefined): Promise<String | u
|
||||
|
||||
export const addItems = async ({
|
||||
variantId,
|
||||
quantity = 1
|
||||
quantity = 1,
|
||||
locale
|
||||
}: {
|
||||
variantId: string | undefined;
|
||||
quantity: number;
|
||||
locale?: SupportedLocale;
|
||||
}): Promise<String | undefined> => {
|
||||
let cartId = cookies().get('cartId')?.value;
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
if (!cartId || !cart) {
|
||||
|
@ -2,9 +2,10 @@
|
||||
|
||||
import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline';
|
||||
import clsx from 'clsx';
|
||||
import { SupportedLocale } from 'components/layout/navbar/language-control';
|
||||
import LoadingDots from 'components/loading-dots';
|
||||
import { ProductVariant } from 'lib/shopify/types';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useLocale, useTranslations } from 'next-intl';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useState, useTransition } from 'react';
|
||||
import { addItems } from './actions';
|
||||
@ -20,6 +21,7 @@ export function AddManyToCart({
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const locale = useLocale();
|
||||
const t = useTranslations('Index');
|
||||
|
||||
const [currentQuantity, setCurrentQuantity] = useState<number>(quantity);
|
||||
@ -83,7 +85,8 @@ export function AddManyToCart({
|
||||
startTransition(async () => {
|
||||
const error = await addItems({
|
||||
variantId: selectedVariantId,
|
||||
quantity: currentQuantity
|
||||
quantity: currentQuantity,
|
||||
locale: locale as SupportedLocale
|
||||
});
|
||||
|
||||
if (error) {
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { SupportedLocale } from 'components/layout/navbar/language-control';
|
||||
import { getCart } from 'lib/shopify';
|
||||
import { cookies } from 'next/headers';
|
||||
import CartModal from './modal';
|
||||
|
||||
export default async function Cart() {
|
||||
export default async function Cart({ locale }: { locale?: SupportedLocale }) {
|
||||
const cartId = cookies().get('cartId')?.value;
|
||||
let cart;
|
||||
|
||||
if (cartId) {
|
||||
cart = await getCart(cartId);
|
||||
cart = await getCart({ cartId, language: locale?.toUpperCase() });
|
||||
}
|
||||
|
||||
return <CartModal cart={cart} />;
|
||||
|
@ -1,7 +1,8 @@
|
||||
import cartFragment from '../fragments/cart';
|
||||
|
||||
export const getCartQuery = /* GraphQL */ `
|
||||
query getCart($cartId: ID!) {
|
||||
query getCart($cartId: ID!, $country: CountryCode, $language: LanguageCode)
|
||||
@inContext(country: $country, language: $language) {
|
||||
cart(id: $cartId) {
|
||||
...cart
|
||||
}
|
||||
|
@ -176,6 +176,8 @@ export type ShopifyCartOperation = {
|
||||
};
|
||||
variables: {
|
||||
cartId: string;
|
||||
language?: string;
|
||||
country?: string;
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user