Addressing a Critical ESHOPMAN Return Processing Bug: Shipping Promotion Adjustments

Understanding a Critical ESHOPMAN Return Processing Challenge

The ESHOPMAN community recently identified a significant issue affecting the processing of returns for orders that include a shipping-method adjustment, such as a shipping promotion. This insight details the problem, its technical underpinnings within the ESHOPMAN platform, and the ongoing efforts by the ESHOPMAN team to ensure seamless order management for all merchants leveraging our headless commerce solution integrated with HubSpot.

The Problem: Return Processing Crashes with Shipping Adjustments

When attempting to receive return items for an order that has benefited from a shipping promotion, ESHOPMAN’s order processing workflow may encounter a unique-constraint violation. Instead of successfully completing the return, the system throws an error indicating that an 'Order shipping method adjustment with version: [number], shipping_method_id: [ID], already exists.'

Technical Reproduction

This issue is consistently reproducible through ESHOPMAN's Admin API workflows, specifically when utilizing the createAndCompleteReturnOrderWorkflow with the receive_now: true flag. The problem manifests when this workflow is executed against an order where the shipping method has an associated adjustment. An example of the problematic workflow execution looks like this:

await createAndCompleteReturnOrderWorkflow(container).run({
  input: {
    order_id: order.id, // order has a shipping_method with an adjustment
    return_shipping: { option_id: shippingOption.id },
    items: [{ id: order.items[0].id, quantity: 1, reason_id: reason.id }],
    receive_now: true,
  },
  throwOnError: true,
})

This behavior has been 100% reproducible in local development environments using standard ESHOPMAN configurations, including Node.js and Postgres databases.

Precise Trigger and Underlying Mechanism

Through detailed investigation by community members and the ESHOPMAN team, it has been empirically isolated that this crash occurs exclusively with orders possessing a shipping-method adjustment. Orders without such adjustments, or those with only item-level adjustments, process returns without issue.

The root cause lies in how ESHOPMAN’s order versioning system handles changes during the RETURN_RECEIVE process. When a return is received, the order's version is incremented, and the system attempts to re-create order_shipping_method_adjustment rows. This re-creation process, managed by internal services like applyOrderChanges_ and orderShippingMethodAdjustmentService_.create, inadvertently tries to insert a duplicate (version, shipping_method_id) pair into the database, violating a unique index designed to prevent such duplicates. This highlights a complex interaction within ESHOPMAN's Node.js/TypeScript backend, particularly in the order module responsible for managing these intricate versioning and adjustment details.

Impact on ESHOPMAN Merchants and Developers

This bug can significantly disrupt the return process for ESHOPMAN merchants, especially those running promotions that offer adjusted shipping rates. For developers building custom integrations or managing storefronts deployed via HubSpot CMS, understanding this issue is crucial for diagnosing unexpected failures in return workflows.

ESHOPMAN Team's Response and Resolution

The ESHOPMAN team has thoroughly investigated and confirmed this as a legitimate bug within the platform's order module. They acknowledge the critical nature of this issue for seamless headless commerce operations. A dedicated fix is actively being developed and integrated to prevent the re-creation of past-version shipping method adjustments during order changes, ensuring the stability and reliability of ESHOPMAN's return processing. We appreciate the community's vigilance in identifying and reporting such crucial findings, which are instrumental in continuously enhancing the ESHOPMAN experience.

Stay tuned for updates from the ESHOPMAN team regarding the deployment of the resolution, ensuring your HubSpot-integrated storefronts continue to operate flawlessly.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools