diff --git a/.env.template b/.env.template index bba85e7a9..d503cacc6 100644 --- a/.env.template +++ b/.env.template @@ -17,6 +17,7 @@ NEXT_PUBLIC_STRIPE_KEY= NEXT_PUBLIC_PAYPAL_CLIENT_ID= # Your MeiliSearch / Algolia keys. See – https://docs.medusajs.com/add-plugins/meilisearch or https://docs.medusajs.com/add-plugins/algolia +NEXT_PUBLIC_FEATURE_SEARCH_ENABLED=false NEXT_PUBLIC_SEARCH_APP_ID= NEXT_PUBLIC_SEARCH_ENDPOINT=http://127.0.0.1:7700 NEXT_PUBLIC_SEARCH_API_KEY= diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index 3ee8acb20..000000000 --- a/netlify.toml +++ /dev/null @@ -1,2 +0,0 @@ -[template.environment] -NEXT_PUBLIC_MEDUSA_BACKEND_URL="URL of your Medusa Server" diff --git a/next.config.js b/next.config.js index 3955381a9..10e4b3cd0 100644 --- a/next.config.js +++ b/next.config.js @@ -1,11 +1,7 @@ -const { withStoreConfig } = require("./store-config") -const store = require("./store.config.json") - /** * @type {import('next').NextConfig} */ -const nextConfig = withStoreConfig({ - features: store.features, +const nextConfig = { reactStrictMode: true, images: { remotePatterns: [ @@ -27,7 +23,7 @@ const nextConfig = withStoreConfig({ }, ], }, -}) +} console.log("next.config.js", JSON.stringify(module.exports, null, 2)) diff --git a/src/app/[countryCode]/(checkout)/checkout/page.tsx b/src/app/[countryCode]/(checkout)/checkout/page.tsx index 53b873608..a4704f129 100644 --- a/src/app/[countryCode]/(checkout)/checkout/page.tsx +++ b/src/app/[countryCode]/(checkout)/checkout/page.tsx @@ -6,6 +6,7 @@ import CheckoutForm from "@modules/checkout/templates/checkout-form" import CheckoutSummary from "@modules/checkout/templates/checkout-summary" import { enrichLineItems, retrieveCart } from "@lib/data/cart" import { HttpTypes } from "@medusajs/types" +import { getCustomer } from "@lib/data/customer" export const metadata: Metadata = { title: "Checkout", @@ -18,10 +19,7 @@ const fetchCart = async () => { } if (cart?.items?.length) { - const enrichedItems = await enrichLineItems( - cart?.items, - cart?.currency_code - ) + const enrichedItems = await enrichLineItems(cart?.items, cart?.region_id!) cart.items = enrichedItems as HttpTypes.StoreCartLineItem[] } @@ -30,15 +28,12 @@ const fetchCart = async () => { export default async function Checkout() { const cart = await fetchCart() - - if (!cart) { - return notFound() - } + const customer = await getCustomer() return (
- +
diff --git a/src/app/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx b/src/app/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx index abb6a4ffd..549df0fcb 100644 --- a/src/app/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx +++ b/src/app/[countryCode]/(main)/account/@dashboard/orders/details/[id]/page.tsx @@ -17,7 +17,7 @@ async function getOrder(id: string) { return } - const enrichedItems = await enrichLineItems(order.items, order.currency_code) + const enrichedItems = await enrichLineItems(order.items, order.region_id!) return { ...order, diff --git a/src/app/[countryCode]/(main)/cart/page.tsx b/src/app/[countryCode]/(main)/cart/page.tsx index 9a0264a97..1dce39983 100644 --- a/src/app/[countryCode]/(main)/cart/page.tsx +++ b/src/app/[countryCode]/(main)/cart/page.tsx @@ -18,10 +18,7 @@ const fetchCart = async () => { } if (cart?.items?.length) { - const enrichedItems = await enrichLineItems( - cart?.items, - cart?.currency_code - ) + const enrichedItems = await enrichLineItems(cart?.items, cart?.region_id!) cart.items = enrichedItems as HttpTypes.StoreCartLineItem[] } diff --git a/src/app/[countryCode]/(main)/order/confirmed/[id]/page.tsx b/src/app/[countryCode]/(main)/order/confirmed/[id]/page.tsx index 0ca4f8e3c..476597073 100644 --- a/src/app/[countryCode]/(main)/order/confirmed/[id]/page.tsx +++ b/src/app/[countryCode]/(main)/order/confirmed/[id]/page.tsx @@ -17,7 +17,7 @@ async function getOrder(id: string) { return } - const enrichedItems = await enrichLineItems(order.items, order.currency_code) + const enrichedItems = await enrichLineItems(order.items, order.region_id!) return { ...order, diff --git a/src/lib/data/cart.ts b/src/lib/data/cart.ts index 02296ecf9..017e00c03 100644 --- a/src/lib/data/cart.ts +++ b/src/lib/data/cart.ts @@ -5,7 +5,6 @@ import medusaError from "@lib/util/medusa-error" import { HttpTypes } from "@medusajs/types" import { omit } from "lodash" import { revalidateTag } from "next/cache" -import { cookies } from "next/headers" import { redirect } from "next/navigation" import { getAuthHeaders, getCartId, removeCartId, setCartId } from "./cookies" import { getProductsById } from "./products" @@ -18,18 +17,12 @@ export async function retrieveCart() { return null } - try { - const { cart } = await sdk.store.cart.retrieve( - cartId, - {}, - { next: { tags: ["cart"] }, ...getAuthHeaders() } - ) - - return cart - } catch (e) { - console.log(e) - return null - } + return await sdk.store.cart + .retrieve(cartId, {}, { next: { tags: ["cart"] }, ...getAuthHeaders() }) + .then(({ cart }) => cart) + .catch(() => { + return null + }) } export async function getOrSetCart(countryCode: string) { @@ -37,11 +30,9 @@ export async function getOrSetCart(countryCode: string) { const region = await getRegion(countryCode) if (!region) { - return null + throw new Error(`Region not found for country code: ${countryCode}`) } - const region_id = region.id - if (!cart) { const cartResp = await sdk.store.cart.create({ region_id: region.id }) cart = cartResp.cart @@ -49,24 +40,32 @@ export async function getOrSetCart(countryCode: string) { revalidateTag("cart") } - if (cart && cart?.region_id !== region_id) { - await sdk.store.cart.update(cart.id, { region_id }, {}, getAuthHeaders()) + if (cart && cart?.region_id !== region.id) { + await sdk.store.cart.update( + cart.id, + { region_id: region.id }, + {}, + getAuthHeaders() + ) revalidateTag("cart") } return cart } -export async function updateCart(data: any) { +export async function updateCart(data: HttpTypes.StoreUpdateCart) { const cartId = getCartId() if (!cartId) { - return "Missing cart ID" + throw new Error("No existing cart found, please create one before updating") } return sdk.store.cart .update(cartId, data, {}, getAuthHeaders()) - .then(({ cart }) => cart) - .catch((err) => medusaError(err)) + .then(({ cart }) => { + revalidateTag("cart") + return cart + }) + .catch(medusaError) } export async function addToCart({ @@ -79,16 +78,16 @@ export async function addToCart({ countryCode: string }) { if (!variantId) { - return "Missing product variant ID" + throw new Error("Missing variant ID when adding to cart") } const cart = await getOrSetCart(countryCode) if (!cart) { - return "Missing cart ID" + throw new Error("Error retrieving or creating cart") } - try { - await sdk.store.cart.createLineItem( + await sdk.store.cart + .createLineItem( cart.id, { variant_id: variantId, @@ -97,10 +96,10 @@ export async function addToCart({ {}, getAuthHeaders() ) - revalidateTag("cart") - } catch (e) { - return "Error adding item to cart" - } + .then(() => { + revalidateTag("cart") + }) + .catch(medusaError) } export async function updateLineItem({ @@ -111,44 +110,39 @@ export async function updateLineItem({ quantity: number }) { if (!lineId) { - return "Missing lineItem ID" + throw new Error("Missing lineItem ID when updating line item") } const cartId = getCartId() if (!cartId) { - return "Missing cart ID" + throw new Error("Missing cart ID when updating line item") } - try { - await sdk.store.cart.updateLineItem( - cartId, - lineId, - { quantity }, - {}, - getAuthHeaders() - ) - revalidateTag("cart") - } catch (e: any) { - return e.toString() - } + await sdk.store.cart + .updateLineItem(cartId, lineId, { quantity }, {}, getAuthHeaders()) + .then(() => { + revalidateTag("cart") + }) + .catch(medusaError) } export async function deleteLineItem(lineId: string) { if (!lineId) { - return "Missing lineItem ID" + throw new Error("Missing lineItem ID when deleting line item") } const cartId = getCartId() if (!cartId) { - return "Missing cart ID" + throw new Error("Missing cart ID when deleting line item") } - try { - await sdk.store.cart.deleteLineItem(cartId, lineId, getAuthHeaders()) - revalidateTag("cart") - } catch (e) { - return "Error deleting line item" - } + await sdk.store.cart + .deleteLineItem(cartId, lineId, getAuthHeaders()) + .then(() => { + revalidateTag("cart") + }) + .catch(medusaError) + revalidateTag("cart") } export async function enrichLineItems( @@ -156,14 +150,14 @@ export async function enrichLineItems( | HttpTypes.StoreCartLineItem[] | HttpTypes.StoreOrderLineItem[] | null, - currencyCode: string + regionId: string ) { if (!lineItems) return [] // Prepare query parameters const queryParams = { ids: lineItems.map((lineItem) => lineItem.product_id!), - currencyCode: currencyCode, + regionId: regionId, } // Fetch products by their IDs @@ -215,7 +209,7 @@ export async function setShippingMethod({ .then(() => { revalidateTag("cart") }) - .catch((err) => medusaError(err)) + .catch(medusaError) } export async function initiatePaymentSession( @@ -229,21 +223,20 @@ export async function initiatePaymentSession( .then(() => { revalidateTag("cart") }) - .catch((err) => { - medusaError(err) - }) + .catch(medusaError) } export async function applyPromotions(codes: string[]) { - const cartId = cookies().get("_medusa_cart_id")?.value - if (!cartId) return "No cartId cookie found" - try { - await updateCart({ promo_codes: codes }).then(() => { + const cartId = getCartId() + if (!cartId) { + throw new Error("No existing cart found") + } + + await updateCart({ promo_codes: codes }) + .then(() => { revalidateTag("cart") }) - } catch (error: any) { - throw error - } + .catch(medusaError) } export async function applyGiftCard(code: string) { @@ -296,58 +289,59 @@ export async function submitPromotionForm( const code = formData.get("code") as string try { await applyPromotions([code]) - - return null - } catch (error: any) { - return error.toString() + } catch (e: any) { + return e.message } } // TODO: Pass a POJO instead of a form entity here export async function setAddresses(currentState: unknown, formData: FormData) { - if (!formData) return "No form data received" - const cartId = getCartId() - if (!cartId) return { message: "No cartId cookie found" } - - const data = { - shipping_address: { - first_name: formData.get("shipping_address.first_name"), - last_name: formData.get("shipping_address.last_name"), - address_1: formData.get("shipping_address.address_1"), - address_2: "", - company: formData.get("shipping_address.company"), - postal_code: formData.get("shipping_address.postal_code"), - city: formData.get("shipping_address.city"), - country_code: formData.get("shipping_address.country_code"), - province: formData.get("shipping_address.province"), - phone: formData.get("shipping_address.phone"), - }, - email: formData.get("email"), - } as any - - const sameAsBilling = formData.get("same_as_billing") - if (sameAsBilling === "on") data.billing_address = data.shipping_address - - if (sameAsBilling !== "on") - data.billing_address = { - first_name: formData.get("billing_address.first_name"), - last_name: formData.get("billing_address.last_name"), - address_1: formData.get("billing_address.address_1"), - address_2: "", - company: formData.get("billing_address.company"), - postal_code: formData.get("billing_address.postal_code"), - city: formData.get("billing_address.city"), - country_code: formData.get("billing_address.country_code"), - province: formData.get("billing_address.province"), - phone: formData.get("billing_address.phone"), - } try { - await updateCart(data) + if (!formData) { + throw new Error("No form data found when setting addresses") + } + const cartId = getCartId() + if (!cartId) { + throw new Error("No existing cart found when setting addresses") + } - revalidateTag("cart") - } catch (error: any) { - return error.toString() + const data = { + shipping_address: { + first_name: formData.get("shipping_address.first_name"), + last_name: formData.get("shipping_address.last_name"), + address_1: formData.get("shipping_address.address_1"), + address_2: "", + company: formData.get("shipping_address.company"), + postal_code: formData.get("shipping_address.postal_code"), + city: formData.get("shipping_address.city"), + country_code: formData.get("shipping_address.country_code"), + province: formData.get("shipping_address.province"), + phone: formData.get("shipping_address.phone"), + }, + email: formData.get("email"), + } as any + + const sameAsBilling = formData.get("same_as_billing") + if (sameAsBilling === "on") data.billing_address = data.shipping_address + + if (sameAsBilling !== "on") + data.billing_address = { + first_name: formData.get("billing_address.first_name"), + last_name: formData.get("billing_address.last_name"), + address_1: formData.get("billing_address.address_1"), + address_2: "", + company: formData.get("billing_address.company"), + postal_code: formData.get("billing_address.postal_code"), + city: formData.get("billing_address.city"), + country_code: formData.get("billing_address.country_code"), + province: formData.get("billing_address.province"), + phone: formData.get("billing_address.phone"), + } + await updateCart(data) + } catch (e: any) { + return e.message } + redirect( `/${formData.get("shipping_address.country_code")}/checkout?step=delivery` ) @@ -355,21 +349,26 @@ export async function setAddresses(currentState: unknown, formData: FormData) { export async function placeOrder() { const cartId = getCartId() - if (!cartId) throw new Error("No cartId cookie found") - let cart - try { - cart = await sdk.store.cart.complete(cartId, {}, getAuthHeaders()) - revalidateTag("cart") - } catch (error: any) { - throw error + if (!cartId) { + throw new Error("No existing cart found when placing an order") } - if (cart?.type === "order") { - const countryCode = cart.order.shipping_address?.country_code?.toLowerCase() + const cartRes = await sdk.store.cart + .complete(cartId, {}, getAuthHeaders()) + .then((cartRes) => { + revalidateTag("cart") + return cartRes + }) + .catch(medusaError) + + if (cartRes?.type === "order") { + const countryCode = + cartRes.order.shipping_address?.country_code?.toLowerCase() removeCartId() - redirect(`/${countryCode}/order/confirmed/${cart?.order.id}`) + redirect(`/${countryCode}/order/confirmed/${cartRes?.order.id}`) } - return cart + + return cartRes.cart } /** @@ -382,20 +381,16 @@ export async function updateRegion(countryCode: string, currentPath: string) { const region = await getRegion(countryCode) if (!region) { - return null + throw new Error(`Region not found for country code: ${countryCode}`) } - try { - if (cartId) { - await updateCart({ region_id: region.id }) - revalidateTag("cart") - } - - revalidateTag("regions") - revalidateTag("products") - } catch (e) { - return "Error updating region" + if (cartId) { + await updateCart({ region_id: region.id }) + revalidateTag("cart") } + revalidateTag("regions") + revalidateTag("products") + redirect(`/${countryCode}${currentPath}`) } diff --git a/src/lib/data/products.ts b/src/lib/data/products.ts index f0241cbfe..b6e48adb2 100644 --- a/src/lib/data/products.ts +++ b/src/lib/data/products.ts @@ -5,16 +5,16 @@ import { HttpTypes } from "@medusajs/types" export const getProductsById = cache(async function ({ ids, - currencyCode, + regionId, }: { ids: string[] - currencyCode: string + regionId: string }) { return sdk.store.product .list( { id: ids, - currency_code: currencyCode, + region_id: regionId, fields: "*variants.calculated_price", }, { next: { tags: ["products"] } } diff --git a/src/lib/util/get-product-price.ts b/src/lib/util/get-product-price.ts index 8537346d0..9fbcb22cf 100644 --- a/src/lib/util/get-product-price.ts +++ b/src/lib/util/get-product-price.ts @@ -3,6 +3,10 @@ import { getPercentageDiff } from "./get-precentage-diff" import { convertToLocale } from "./money" export const getPricesForVariant = (variant: any) => { + if (!variant.calculated_price?.calculated_amount) { + return null + } + return { calculated_price_number: variant.calculated_price.calculated_amount, calculated_price: convertToLocale({ @@ -39,12 +43,14 @@ export function getProductPrice({ return null } - const cheapestVariant: any = product.variants.sort((a: any, b: any) => { - return ( - a.calculated_price.calculated_amount - - b.calculated_price.calculated_amount - ) - })[0] + const cheapestVariant: any = product.variants + .filter((v: any) => !!v.calculated_price) + .sort((a: any, b: any) => { + return ( + a.calculated_price.calculated_amount - + b.calculated_price.calculated_amount + ) + })[0] return getPricesForVariant(cheapestVariant) } diff --git a/src/modules/cart/components/item/index.tsx b/src/modules/cart/components/item/index.tsx index 8028319ed..f67b62040 100644 --- a/src/modules/cart/components/item/index.tsx +++ b/src/modules/cart/components/item/index.tsx @@ -30,12 +30,12 @@ const Item = ({ item, type = "full" }: ItemProps) => { setError(null) setUpdating(true) - const message = await updateLineItem({ + await updateLineItem({ lineId: item.id, quantity, }) .catch((err) => { - setError(message) + setError(err.message) }) .finally(() => { setUpdating(false) diff --git a/src/modules/checkout/components/discount-code/index.tsx b/src/modules/checkout/components/discount-code/index.tsx index cae400fa2..7c7160fa9 100644 --- a/src/modules/checkout/components/discount-code/index.tsx +++ b/src/modules/checkout/components/discount-code/index.tsx @@ -28,9 +28,7 @@ const DiscountCode: React.FC = ({ cart }) => { ) await applyPromotions( - validPromotions - .filter((p) => p.code === undefined) - .map((p) => p.code!) + validPromotions.filter((p) => p.code === undefined).map((p) => p.code!) ) } @@ -77,6 +75,7 @@ const DiscountCode: React.FC = ({ cart }) => { <>
= ({ cart }) => { {promotion.code} {" "} ( - {promotion.application_method?.value !== undefined && - promotion.application_method.currency_code !== undefined && ( - <> - {promotion.application_method.type === "percentage" - ? `${promotion.application_method.value}%` - : convertToLocale({ - amount: promotion.application_method.value, - currency_code: - promotion.application_method.currency_code, - })} - - )} + {promotion.application_method?.value !== undefined && + promotion.application_method.currency_code !== + undefined && ( + <> + {promotion.application_method.type === + "percentage" + ? `${promotion.application_method.value}%` + : convertToLocale({ + amount: promotion.application_method.value, + currency_code: + promotion.application_method + .currency_code, + })} + + )} ) {promotion.is_automatic && ( diff --git a/src/modules/checkout/components/payment-button/index.tsx b/src/modules/checkout/components/payment-button/index.tsx index 327ffb85a..e0e783063 100644 --- a/src/modules/checkout/components/payment-button/index.tsx +++ b/src/modules/checkout/components/payment-button/index.tsx @@ -97,10 +97,13 @@ const StripePaymentButton = ({ const [errorMessage, setErrorMessage] = useState(null) const onPaymentCompleted = async () => { - await placeOrder().catch(() => { - setErrorMessage("An error occurred, please try again.") - setSubmitting(false) - }) + await placeOrder() + .catch((err) => { + setErrorMessage(err.message) + }) + .finally(() => { + setSubmitting(false) + }) } const stripe = useStripe() @@ -201,10 +204,13 @@ const PayPalPaymentButton = ({ const [errorMessage, setErrorMessage] = useState(null) const onPaymentCompleted = async () => { - await placeOrder().catch(() => { - setErrorMessage("An error occurred, please try again.") - setSubmitting(false) - }) + await placeOrder() + .catch((err) => { + setErrorMessage(err.message) + }) + .finally(() => { + setSubmitting(false) + }) } const session = cart.payment_collection?.payment_sessions?.find( @@ -260,10 +266,13 @@ const ManualTestPaymentButton = ({ notReady }: { notReady: boolean }) => { const [errorMessage, setErrorMessage] = useState(null) const onPaymentCompleted = async () => { - await placeOrder().catch((err) => { - setErrorMessage(err.toString()) - setSubmitting(false) - }) + await placeOrder() + .catch((err) => { + setErrorMessage(err.message) + }) + .finally(() => { + setSubmitting(false) + }) } const handlePayment = () => { diff --git a/src/modules/checkout/components/payment/index.tsx b/src/modules/checkout/components/payment/index.tsx index 1244cc785..1163a1aa6 100644 --- a/src/modules/checkout/components/payment/index.tsx +++ b/src/modules/checkout/components/payment/index.tsx @@ -92,7 +92,7 @@ const Payment = ({ scroll: false, }) } catch (err: any) { - setError(err.toString()) + setError(err.message) } finally { setIsLoading(false) } diff --git a/src/modules/checkout/components/shipping/index.tsx b/src/modules/checkout/components/shipping/index.tsx index 2c6127bbc..2d0b73178 100644 --- a/src/modules/checkout/components/shipping/index.tsx +++ b/src/modules/checkout/components/shipping/index.tsx @@ -46,11 +46,8 @@ const Shipping: React.FC = ({ const set = async (id: string) => { setIsLoading(true) await setShippingMethod({ cartId: cart.id, shippingMethodId: id }) - .then(() => { - setIsLoading(false) - }) .catch((err) => { - setError(err.toString()) + setError(err.message) }) .finally(() => { setIsLoading(false) diff --git a/src/modules/checkout/templates/checkout-form/index.tsx b/src/modules/checkout/templates/checkout-form/index.tsx index efe775c2f..73dadf166 100644 --- a/src/modules/checkout/templates/checkout-form/index.tsx +++ b/src/modules/checkout/templates/checkout-form/index.tsx @@ -4,23 +4,23 @@ import { retrieveCart } from "@lib/data/cart" import { getCustomer } from "@lib/data/customer" import { listCartShippingMethods } from "@lib/data/fulfillment" import { listCartPaymentMethods } from "@lib/data/payment" -import { StoreCart, StoreCustomer } from "@medusajs/types" +import { HttpTypes, StoreCart, StoreCustomer } from "@medusajs/types" import Addresses from "@modules/checkout/components/addresses" import Payment from "@modules/checkout/components/payment" import Review from "@modules/checkout/components/review" import Shipping from "@modules/checkout/components/shipping" import { useState } from "react" -export default function CheckoutForm() { - const [cart, setCart] = useState(null) - const [customer, setCustomer] = useState(null) +export default function CheckoutForm({ + cart, + customer, +}: { + cart: HttpTypes.StoreCart | null + customer: HttpTypes.StoreCustomer | null +}) { const [shippingMethods, setAvailableShippingMethods] = useState([]) const [paymentMethods, setPaymentMethods] = useState([]) - if (!cart) { - retrieveCart().then((cart) => setCart(cart)) - } - if (!cart) { return null } @@ -33,8 +33,6 @@ export default function CheckoutForm() { setPaymentMethods(payments) ) - getCustomer().then((customer: any) => setCustomer(customer)) - return (
diff --git a/src/modules/common/components/line-item-price/index.tsx b/src/modules/common/components/line-item-price/index.tsx index 7003c31df..4ac3e8763 100644 --- a/src/modules/common/components/line-item-price/index.tsx +++ b/src/modules/common/components/line-item-price/index.tsx @@ -12,7 +12,7 @@ type LineItemPriceProps = { const LineItemPrice = ({ item, style = "default" }: LineItemPriceProps) => { const { currency_code, calculated_price_number, original_price_number } = - getPricesForVariant(item.variant) + getPricesForVariant(item.variant) ?? {} const adjustmentsSum = (item.adjustments || []).reduce( (acc, adjustment) => adjustment.amount + acc, diff --git a/src/modules/common/components/line-item-unit-price/index.tsx b/src/modules/common/components/line-item-unit-price/index.tsx index c41c81a4d..20e4af48a 100644 --- a/src/modules/common/components/line-item-unit-price/index.tsx +++ b/src/modules/common/components/line-item-unit-price/index.tsx @@ -17,7 +17,7 @@ const LineItemUnitPrice = ({ original_price_number, calculated_price_number, percentage_diff, - } = getPricesForVariant(item.variant) + } = getPricesForVariant(item.variant) ?? {} const hasReducedPrice = calculated_price_number < original_price_number return ( diff --git a/src/modules/layout/components/cart-button/index.tsx b/src/modules/layout/components/cart-button/index.tsx index 919921fbc..9f9758dfc 100644 --- a/src/modules/layout/components/cart-button/index.tsx +++ b/src/modules/layout/components/cart-button/index.tsx @@ -1,14 +1,16 @@ +import { notFound } from "next/navigation" import CartDropdown from "../cart-dropdown" import { enrichLineItems, retrieveCart } from "@lib/data/cart" const fetchCart = async () => { const cart = await retrieveCart() + if (!cart) { + return null + } + if (cart?.items?.length) { - const enrichedItems = await enrichLineItems( - cart?.items, - cart?.currency_code - ) + const enrichedItems = await enrichLineItems(cart.items, cart.region_id!) cart.items = enrichedItems } diff --git a/src/modules/layout/templates/nav/index.tsx b/src/modules/layout/templates/nav/index.tsx index 128727303..d3bc678af 100644 --- a/src/modules/layout/templates/nav/index.tsx +++ b/src/modules/layout/templates/nav/index.tsx @@ -31,7 +31,7 @@ export default async function Nav() {
- {process.env.FEATURE_SEARCH_ENABLED && ( + {process.env.NEXT_PUBLIC_FEATURE_SEARCH_ENABLED && ( { - if (value) { - nextConfig.env[`FEATURE_${key.toUpperCase()}_ENABLED`] = true - } - }) - - return nextConfig -} - -module.exports = { withStoreConfig } diff --git a/store.config.json b/store.config.json deleted file mode 100644 index e4df9fa66..000000000 --- a/store.config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "features": { - "search": false - } -} diff --git a/tsconfig.json b/tsconfig.json index 90a5cfc53..efb930f45 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,12 +26,7 @@ } ] }, - "include": [ - "next-env.d.ts", - "**/*.ts", - "**/*.tsx", - ".next/types/**/*.ts" - ], + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": [ "node_modules", ".next",