Overview
Optimized storefront and checkout performance, resolved duplicate API calls, fixed cart item retention after order placement, and improved variant selection accuracy across the e-commerce storefront and backend services.
Repository 1: Backend (evergreen_pos_be)
1. Key Modifications & Features
Checkout API Optimization (/api/v1/comm/checkout): Parallelized independent database lookups (CartService.getCartByIdEcom, ClientModel.findOne, CouponModel.find, and resolveCouponTimezone) using Promise.all. Added a 2-second timeout guard on external tax calculations to avoid checkout delays.
Cart API Optimization (/api/v1/comm/cart): Implemented lazy-loading in getCartByIdEcom. If the cart is empty, it returns immediately without executing redundant queries against ProductModel, OfferModel, or weather services. Added short-lived caching for active offers (60s TTL).
Post-Order Cart Clearing (/api/v1/comm/dlt-all): Replaced multiple sequential remote database calls and iterative updateMany loops with a single consolidated $or query matching both _id and customerId.
Loyalty & Referral Quote Acceleration: Parallelized customer and loyalty wallet lookups, cached active loyalty programs (2 min TTL), and added a cached tenant lookup for referral quotes to eliminate redundant Companies.findOne queries.
Shipping Split Rates Caching & Deduplication: Added in-flight request deduplication for FedEx live rate calculation to eliminate concurrent duplicate rate calls.
Database Indexing: Added explicit compound indexes on cartSchema (customerId: 1, userId: 1) to eliminate collection scans.
2. Bug Fixes
Fixed post-order cart cleanup where ordered items persisted due to mismatched cart identifiers between guest and authenticated sessions.
Corrected reference resolution in clearCustomerEcomCart to prevent unhandled rejections during cart purge.
Fixed award of loyalty points for pickup and direct cash/zelle delivery orders in sale.service.js.
3. File-by-File Summary
File Changes Made
src/controllers/nursery/ecom.controller.js
Removed unindexed admin queries in CartGetById; streamlined CartDltAll into a single bulk update query; added safe fallback in CartNWCount.
src/controllers/nursery/referral.controller.js
Added slugToDbNameCache (5m TTL) to avoid querying Companies on every referral quote.
src/models/nursery/cart.model.js
Added indexes on customerId and userId.
src/routes/nursery/ecom.route.js
Standardized split-rates, PDP, and checkout route definitions.
src/routes/nursery/shop.route.js
Streamlined storefront catalog routing.
src/services/loyaltyEngine.js
Parallelized wallet and customer fetches; added caching for active loyalty programs.
src/services/loyaltyProgram.service.js
Optimized point calculation queries; avoided redundant product lookups when item prices are present in cart.
src/services/nursery/cart.service.js
Implemented early return for empty carts; cached active offers (60s); updated composite variant inventory resolution; fixed clearCustomerEcomCart.
src/services/nursery/ecom.service.js
Parallelized getCheckoutDataEcom queries; cached active coupons (30s) and tax calculations (60s) with timeout fallback; fixed syntax error.
src/services/nursery/order.service.js
Ensured cart cleanup triggers upon order creation.
src/services/nursery/product.service.js
Optimized /api/v1/comm/find search with indexed queries and parallel counts.
src/services/nursery/rbac.service.js
Cleaned error handling and role lookup execution.
src/services/nursery/referral.service.js
Added customerCreditCache (30s TTL) with instant invalidation upon credit application.
src/services/nursery/sale.service.js
Updated processLoyaltyEcomEarning to award loyalty points on pickup and cash/zelle delivered orders.
src/services/shipping/shippingSplit.service.js
Deduplicated in-flight split rate requests; cached rate results.
Repository 2: Frontend (evergreenpos_E-commerce_new)
1. Key Modifications & Features
Checkout Network Optimization: Added debouncing (500ms) and payload memoization (lastReferralPayloadRef) to referral quote calculations, preventing repeated calls on state updates. Added 250ms debounce on address verification during checkout load.
PDP Duplicate API Prevention: Prevented duplicate trust badge, review, and Q&A API calls when navigating between Cart and PDP using fetchedTrustPidRef.
Preorder API Scope Restriction: Suppressed preorder availability background checks on post-purchase pages (/order-success, /orders, /my-account).
Cart Cleanup Reliability: Enhanced clearCustomerCartOnOrderSuccess to optimistically clear local storage, Redux cart state, and backend cart records simultaneously upon order placement.
Variant Selection Stability: Enhanced variant selection logic to default to index 0 when opening PDP while correctly mapping composite IDs (<productId>_<variantSku>) from the cart.
2. Bug Fixes
Fixed missing TrendingDown icon import in
productdetailsui.tsx
.
Fixed issue where products remained in the cart after completing order placement.
Resolved variant selector mismatch in cart items where variant attributes did not sync with the active SKU.
3. File-by-File Summary
File Changes Made
src/api/ecomApiPaths.ts
Centralized and normalized API endpoint paths.
src/components/CartItemVariantSelector.tsx
Fixed active variant detection to accurately reflect SKU changes.
src/context/PreorderAvailabilityContext.tsx
Suppressed preorder polling on order success, account, and confirmation routes.
src/features/cart/page/components/CartItemCard.tsx
Fixed variant attribute rendering and navigation link state.
src/features/cart/page/components/CartProducts.tsx
Updated empty cart state and clear cart triggers.
src/features/checkout/pages/Checkout.tsx
Debounced referral quotes and address checks; stabilized variant modal selection.
src/features/checkout/pages/CheckoutPreorder.tsx
Applied debounce guards to preorder checkout calculations.
src/features/loyalty/components/LoyaltyProfilePanel.tsx
Safe number parsing and currency formatting for reward balance displays.
src/features/loyalty/pages/RewardsPage.tsx
Handled edge cases where point balance or tier info is undefined.
src/features/loyalty/utils.ts
Shared loyalty formatting utilities.
src/features/orders/pages/OrderSuccess.tsx
Ensured comprehensive cart wipe (local storage, Redux, backend) on mount.
src/features/products/pages/productdetailsui.tsx
Fixed TrendingDown icon import; prevented duplicate API requests on navigation; preserved variant selection.
src/hooks/useCart.tsx
Added optimistic state clearing; corrected composite item ID matching.
src/utils/cartCleanup.ts
Implemented unified cart purge utility across storage and remote API.
src/utils/storefrontUtils.ts
Added helper utilities for query formatting and variant identification.