diff --git a/src/App.tsx b/src/App.tsx index 8c5ec65..4580d8b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -456,6 +456,22 @@ export default function App() { } }; + // Keep cart items dynamic prices updated when publicPlans are loaded + useEffect(() => { + if (publicPlans.length > 0 && cart.length > 0) { + setCart(prev => + prev.map(item => { + const live = getModulePrice(item); + return { + ...item, + priceInr: live.priceInr, + priceUsd: live.priceUsd, + }; + }) + ); + } + }, [publicPlans]); + const calculatePricing = async () => { setLoadingPricing(true); try { @@ -469,6 +485,7 @@ export default function App() { setPricingCalc(res.data); } catch (err) { console.error('Pricing engine calculation error:', err); + setPricingCalc(null); } finally { setLoadingPricing(false); } diff --git a/src/components/cart/CartDrawer.tsx b/src/components/cart/CartDrawer.tsx index 5c49f3f..f92da29 100644 --- a/src/components/cart/CartDrawer.tsx +++ b/src/components/cart/CartDrawer.tsx @@ -102,11 +102,16 @@ export const CartDrawer: React.FC = ({
- {currency === 'INR' - ? `₹${item.priceInr}` - : currency === 'EUR' - ? `€${item.priceEur}` - : `$${item.priceUsd}`} + {(() => { + const calculatedItem = pricingCalc?.currency === currency + ? pricingCalc?.cart_items?.find((ci: any) => ci.code === item.code) + : null; + const price = calculatedItem + ? calculatedItem.price + : (currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd); + const symbol = currency === 'INR' ? '₹' : currency === 'EUR' ? '€' : '$'; + return `${symbol}${price}`; + })()}