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:
@@ -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