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