fix: unify free shipping threshold to 10000 RSD across all pages
- Create centralized shipping config file (src/lib/config/shipping.ts) - Update CartDrawer.tsx: change hardcoded 5000 to FREE_SHIPPING_THRESHOLD_RSD constant - Update TickerBar.tsx: change hardcoded 10000 to use centralized constant - Ensure uniform free shipping messaging across all pages and localizations
This commit is contained in:
@@ -9,6 +9,7 @@ import { useTranslations, useLocale } from "next-intl";
|
|||||||
import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore";
|
import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore";
|
||||||
import { formatPrice } from "@/lib/saleor";
|
import { formatPrice } from "@/lib/saleor";
|
||||||
import { useAnalytics } from "@/lib/analytics";
|
import { useAnalytics } from "@/lib/analytics";
|
||||||
|
import { FREE_SHIPPING_THRESHOLD_RSD } from "@/lib/config/shipping";
|
||||||
|
|
||||||
export default function CartDrawer() {
|
export default function CartDrawer() {
|
||||||
const t = useTranslations("Cart");
|
const t = useTranslations("Cart");
|
||||||
@@ -251,9 +252,9 @@ export default function CartDrawer() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{(checkout?.subtotalPrice?.gross?.amount || 0) < 5000 && (
|
{(checkout?.subtotalPrice?.gross?.amount || 0) < FREE_SHIPPING_THRESHOLD_RSD && (
|
||||||
<p className="text-xs text-[#666666] text-center">
|
<p className="text-xs text-[#666666] text-center">
|
||||||
{t("freeShippingOver", { amount: formatPrice(5000) })}
|
{t("freeShippingOver", { amount: formatPrice(FREE_SHIPPING_THRESHOLD_RSD) })}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
|
import { FREE_SHIPPING_THRESHOLD_RSD } from "@/lib/config/shipping";
|
||||||
|
|
||||||
export default function TickerBar() {
|
export default function TickerBar() {
|
||||||
const items = [
|
const items = [
|
||||||
"Free shipping on orders over 10000 RSD",
|
`Free shipping on orders over ${FREE_SHIPPING_THRESHOLD_RSD} RSD`,
|
||||||
"Natural ingredients",
|
"Natural ingredients",
|
||||||
"Cruelty-free",
|
"Cruelty-free",
|
||||||
"Handmade with love",
|
"Handmade with love",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user