Tag: shipping

  • Fulfillment – Daily Changelog – October 23, 2025

    Fulfillment – Daily Changelog – October 23, 2025

    Changelog – October 23, 2025

    🚀 New Features & Improvements

    New Batch Page Enhancements

    • Fixed ShippingEasy Preview: Resolved “shippingeasy” preview not working on new batch page by removing non-existent database columns (o.shipping_address2, o.shipping_phone)
    • Customer Information Display: Fixed missing customer information display on new batch page by updating display logic to check order.shipping_name || order.customer_name || order.shipping_address1
    • Individual Shipment Creation: Fixed “Create Shipment” button to create shipments for individual orders instead of adding all line items from all orders to one shipment
    • Individual Packing Lists: Implemented one packing list per order instead of per batch, with individual “Print Packing List” buttons for each order
    • Bulk Packing Lists: Added “Print Packing Lists” button at batch level to print all order packing lists at once
    • Work Order Generation: Modified work order creation to group by decoration process instead of product, creating one work order with multiple pages (001, 002, 003, etc.)
    • Bulk Work Orders: Added “Print Work Orders” button to print all work orders for a batch

    Database & API Improvements

    • Connection Pool Management: Fixed “too many clients already” errors by replacing individual pg.Pool instances with shared db connection from @/lib/db in multiple API routes
    • Bulk Packing Lists API: Created new /api/batches/[id]/bulk-packing-lists endpoint to fetch all packing list data for multiple orders in a single query
    • Color Data Integration: Fixed missing color information in packing lists by joining with blank_style_colors table and using bc.color_name
    • Database Schema Corrections: Updated queries to use correct column names (snapshot_variant_size, snapshot_variant_color_name, snapshot_product_title)

    Print System Overhaul

    • Print Layout Fixes: Resolved multiple print layout issues including:
    • Blank pages between packing lists
    • Incorrect page dimensions causing 2 pages per packing list
    • Single page printing all packing lists
    • Width overflow issues
    • Print Styles Optimization: Implemented multiPagePrintStyles utility for consistent print formatting across packing lists
    • Individual Packing List Pages: Created /orders/[id]/packing-list pages with auto-print functionality
    • Bulk Packing List Pages: Created /batches-new/[id]/packing-lists for printing multiple packing lists with proper page breaks

    Inventory & Shipment Management

    • Inventory Check Bypass: Added force: true parameter to shipment creation to bypass inventory checks for new batch page workflow
    • Shipment Dialog Fixes: Removed undefined state variable references (setPendingShipmentData, setNotReadyItems, setShowOverrideDialog)
    • ShippingEasy Integration: Updated ShippingEasy data preparation to match exact format of working send-to-shippingeasy endpoint

    🐛 Bug Fixes

    Database Issues

    • Column Existence Errors: Fixed multiple “column does not exist” errors by removing references to non-existent columns in mama_tried_orders table
    • Type Mismatches: Fixed string vs number ID comparison issues in shipment creation filtering
    • Connection Leaks: Resolved database connection limit errors by standardizing on shared db connection

    Print System Issues

    • Sidebar in Print: Fixed sidebar appearing in printed packing lists by adding proper CSS print media queries
    • Checkbox Issues: Removed header row checkbox and set item checkboxes to checked by default
    • Date Display: Removed unnecessary date from packing list headers
    • Page Break Issues: Fixed multiple page break problems causing incorrect pagination

    UI/UX Issues

    • Customer Information: Fixed missing customer information display on new batch page
    • Shipment Creation: Fixed shipment creation to work with individual orders instead of all orders at once
    • Button Functionality: Fixed “Create Shipment” button to properly filter line items by selected order

    🔧 Technical Improvements

    API Route Updates

    • src/app/api/orders/prepare-shippingeasy-data/route.ts: Fixed column references and data structure
    • src/app/api/orders/[id]/shipment-references/route.ts: Replaced Pool with db connection
    • src/app/api/orders/bulk-dimensions/route.ts: Replaced Pool with db connection
    • src/app/api/shipments/route.ts: Added force parameter for inventory check bypass
    • src/app/api/batches/[id]/bulk-packing-lists/route.ts: New endpoint for bulk packing list data

    Frontend Components

    • src/app/(authenticated)/batches-new/[id]/page.tsx: Enhanced with individual shipment creation and bulk printing
    • src/app/(authenticated)/orders/[id]/packing-list/page.tsx: New individual packing list page
    • src/app/(authenticated)/batches-new/[id]/packing-lists/page.tsx: New bulk packing list page
    • src/components/orders/shipment-dialog.tsx: Fixed undefined state variables and added force parameter

    Database Schema

    • Updated queries to use correct column names from mama_tried_order_line_items
    • Added proper joins to blank_style_colors for color information
    • Implemented COALESCE for fallback data when snapshot data is null

    📊 Performance Improvements

    • Single Query Optimization: Replaced multiple API calls with single bulk queries for packing list data
    • Connection Pool Efficiency: Standardized database connections to prevent connection leaks
    • Print Performance: Optimized print styles to reduce layout calculations and improve rendering speed

    🎯 User Experience Improvements

    • Simplified Workflow: New batch page now “just works” without inventory check impediments
    • Bulk Operations: Added bulk printing capabilities for both packing lists and work orders
    • Visual Consistency: Fixed print layouts to match working individual packing lists
    • Error Prevention: Added proper error handling and data validation throughout the workflow

    📝 Documentation Updates

    • Updated database management instructions
    • Added local server management guidelines
    • Enhanced API documentation for new endpoints

    Total Commits: 7
    Files Modified: 15+
    New Files Created: 4
    Major Features Added: Bulk packing lists, individual shipment creation, print system overhaul

  • Fulfillment – Daily Changelog – September 19, 2025

    Fulfillment – Daily Changelog – September 19, 2025

    2025-09-19 – Shipping Address Badge System Fixes

    Critical Bug Fixes

    Fixed False Positive “Address Updated” Badges

    • Problem: Every order was showing “📍 Address Updated” badge even when no shipping changes occurred
    • Root Cause: Both webhook handler and sync process were calling updateOrderShippingAddress with faulty comparison logic
    • Solution: Temporarily disabled automatic shipping address updates in both webhook and sync processes
    • Result: Only legitimate address changes now show the badge (e.g., order #5303 from 8/29)

    Database Cleanup

    • Cleared all false positive shipping_updated_at timestamps from recent orders
    • Restored only the legitimate shipping update for order #5303
    • Prevented system from appearing unreliable to staff/customers

    Code Changes

    • src/app/api/webhooks/shopify/route.ts: Disabled updateOrderShippingAddress calls in webhook handler
    • src/app/api/orders/sync/route.ts: Disabled shipping updates during order sync process
    • Database: Reset shipping_updated_at values to prevent false badge displays

    Build & Deployment Fixes

    Fixed Multiple Build Errors

    • JSX Syntax Error: Fixed missing fragment wrapper in invoice-dialog.tsx
    • Import Path Error: Corrected useToast import path in invoice-creation-success.tsx
    • Linting Errors: Commented out unused variables and fixed unescaped entities
    • Route Conflict: Removed duplicate API route causing Next.js build failures

    Current Status

    Working

    • Badge system now shows accurate shipping address change indicators
    • Invoice creation flow functional
    • Build and deployment process stable

    Root cause: updateOrderShippingAddress comparison logic is faulty – treats every address as “changed”

    What needs to be done RIGHT NOW:

    1. Debug the address comparison in updateOrderShippingAddress function
    2. Fix the logic so it only flags actual changes
    3. Re-enable webhook and sync shipping updates
    4. Test with real address changes to make sure it works

    System Reliability

    • Address root cause of frequent Friday system failures
    • Implement better testing for critical workflows
    • Consider staging environment for testing changes
  • Fulfillment – Daily Changelog – September 15, 2025

    Fulfillment – Daily Changelog – September 15, 2025

    Changelog – September 15, 2025

    Order Sync Logic Updates

    Enhanced Shipping Address Synchronization

    • Added shipping address update utility in src/lib/orderUtils.ts
    • New updateOrderShippingAddress() function to update shipping fields in mama_tried_orders
    • Updates: shipping_address, shipping_name, shipping_address1, shipping_city, shipping_state, shipping_country, shipping_zip, and updated_at

    Shopify Webhook Enhancements

    • Updated webhook handler in src/app/api/webhooks/shopify/route.ts
    • Added support for orders/updated and orders/edited webhook topics
    • Automatically refreshes shipping address when Shopify order is modified
    • Returns early for order updates to avoid duplicate processing

    Scheduled Sync Improvements

    • Enhanced order sync in src/app/api/orders/sync/route.ts
    • Added shipping address refresh for existing orders during sync
    • Ensures shipping data stays current even for orders not recently updated

    Packing-Time Final Check

    • Added final shipping verification at packing time in multiple endpoints:
    • src/app/api/shipments/route.ts – Before creating shipments
    • src/app/api/batches/[id]/send-to-shippingeasy/route.ts – Before sending to ShippingEasy
    • src/app/api/batches/[id]/bulk-weight/route.ts – Before bulk weight operations
    • Fetches latest Shopify order data and updates shipping fields as final safeguard

    Multi-Layer Protection Strategy

    • Implemented three-tier shipping address sync:
    1. Immediate: Webhook updates on orders/updated events
    2. Scheduled: Regular sync refreshes existing orders
    3. Final: Packing-time check ensures accuracy before shipment creation

    Technical Details

    • Uses existing getShopifyOrder() utility to fetch latest order data
    • Leverages transformRestOrder() for consistent data normalization
    • All updates are idempotent and safe to run multiple times
    • Graceful error handling – failures don’t break core functionality

    Visual Indicators

    • Added “Address Updated” badge on orders page (src/app/(authenticated)/orders/page.tsx)
    • Shows orange badge when shipping_updated_at is set
    • Indicates when shipping address was modified after order creation
    • Helps identify orders with address changes at a glance

    Database Schema Updates

    • Added shipping_updated_at column to mama_tried_orders table
    • Tracks timestamp of actual shipping address changes
    • Only set when address actually changes (not on every order update)
    • Used for visual indicators and change tracking

    Debug and Testing Tools

    • Created comprehensive debug endpoints:
    • /api/debug/shipping-updates – List orders with shipping updates
    • /api/debug/shipping-changes – Show before/after address changes
    • /api/debug/test-webhook-endpoint – Test webhook accessibility
    • /api/debug/webhook-diagnostics – Troubleshooting guide
    • /api/debug/latest-updates – Recent order activity
    • /api/debug/test-shipping-update – Simulate address changes
    • /api/debug/reset-shipping-updated-at – Clear false positives

    Shopify Webhook Configuration

    • Configured three webhook events in Shopify Admin:
    • Order creation → https://fulfillment.orchardstreetpress.com/api/webhooks/shopify
    • Order updated → https://fulfillment.orchardstreetpress.com/api/webhooks/shopify
    • Order edited → https://fulfillment.orchardstreetpress.com/api/webhooks/shopify
    • All webhooks use JSON format and proper HMAC signature verification

    Benefits

    • Ensures shipping addresses are always current when orders are packed
    • Handles edge cases where orders are modified after initial import
    • Provides redundancy to catch any missed updates
    • Maintains data integrity throughout the fulfillment process
    • Visual feedback for staff to quickly identify address changes
    • Comprehensive debugging tools for troubleshooting