diff --git a/src/components/cart/CartDrawer.tsx b/src/components/cart/CartDrawer.tsx index 0a1a75a..6aebc6d 100644 --- a/src/components/cart/CartDrawer.tsx +++ b/src/components/cart/CartDrawer.tsx @@ -9,6 +9,7 @@ import { useTranslations, useLocale } from "next-intl"; import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore"; import { formatPrice } from "@/lib/saleor"; import { useAnalytics } from "@/lib/analytics"; +import { FREE_SHIPPING_THRESHOLD_RSD } from "@/lib/config/shipping"; export default function CartDrawer() { const t = useTranslations("Cart"); @@ -251,9 +252,9 @@ export default function CartDrawer() { - {(checkout?.subtotalPrice?.gross?.amount || 0) < 5000 && ( + {(checkout?.subtotalPrice?.gross?.amount || 0) < FREE_SHIPPING_THRESHOLD_RSD && (
- {t("freeShippingOver", { amount: formatPrice(5000) })} + {t("freeShippingOver", { amount: formatPrice(FREE_SHIPPING_THRESHOLD_RSD) })}
)} diff --git a/src/components/home/TickerBar.tsx b/src/components/home/TickerBar.tsx index c86c276..eebe94e 100644 --- a/src/components/home/TickerBar.tsx +++ b/src/components/home/TickerBar.tsx @@ -1,10 +1,11 @@ "use client"; import { motion } from "framer-motion"; +import { FREE_SHIPPING_THRESHOLD_RSD } from "@/lib/config/shipping"; export default function TickerBar() { const items = [ - "Free shipping on orders over 10000 RSD", + `Free shipping on orders over ${FREE_SHIPPING_THRESHOLD_RSD} RSD`, "Natural ingredients", "Cruelty-free", "Handmade with love", diff --git a/src/lib/config/shipping.ts b/src/lib/config/shipping.ts new file mode 100644 index 0000000..8b71b78 --- /dev/null +++ b/src/lib/config/shipping.ts @@ -0,0 +1,50 @@ +/** + * Shipping configuration + * Centralized configuration for shipping rules and thresholds + */ + +/** + * Free shipping threshold in RSD (Serbian Dinar) + * Orders above this amount qualify for free shipping + */ +export const FREE_SHIPPING_THRESHOLD_RSD = 10000; + +/** + * Default shipping cost in RSD when order is below threshold + */ +export const DEFAULT_SHIPPING_COST_RSD = 500; + +/** + * Currency code for shipping calculations + */ +export const SHIPPING_CURRENCY = "RSD"; + +/** + * Check if an order qualifies for free shipping + * @param orderTotal - The total amount of the order + * @returns boolean indicating if order qualifies for free shipping + */ +export function qualifiesForFreeShipping(orderTotal: number): boolean { + return orderTotal >= FREE_SHIPPING_THRESHOLD_RSD; +} + +/** + * Calculate shipping cost based on order total + * @param orderTotal - The total amount of the order + * @returns Shipping cost (0 if qualifies for free shipping) + */ +export function calculateShippingCost(orderTotal: number): number { + return qualifiesForFreeShipping(orderTotal) ? 0 : DEFAULT_SHIPPING_COST_RSD; +} + +/** + * Get the remaining amount needed for free shipping + * @param orderTotal - The current order total + * @returns Amount needed to reach free shipping threshold (0 if already qualified) + */ +export function getRemainingForFreeShipping(orderTotal: number): number { + if (qualifiesForFreeShipping(orderTotal)) { + return 0; + } + return FREE_SHIPPING_THRESHOLD_RSD - orderTotal; +}