Streamlining ESHOPMAN Order Updates: Resolving the 'Country Code Cannot Be Changed' Error

As an e-commerce migration expert at Move My Store, we frequently encounter scenarios where the robustness of platform workflows is critical. One such scenario recently highlighted a subtle but impactful issue within the ESHOPMAN platform's core order management.

A recent community discussion brought to light a specific challenge with ESHOPMAN's updateOrderWorkflow. This workflow, crucial for managing order details post-creation, was found to prevent the addition of a shipping or billing address to an order that initially had none. The workflow would incorrectly report an error: "Country code cannot be changed", even though there was no existing country code to change.

Understanding the ESHOPMAN Workflow Challenge

The root of this issue lies in a guard condition within the ESHOPMAN core flows, specifically in the update-order.ts file. This condition is designed to prevent an existing country code on an order's address from being modified. However, its implementation inadvertently treats an absent country code as if it were a different one when a new address with a country code is provided.

The Problematic Condition in ESHOPMAN Core Flows:

if (
  input.shipping_address?.country_code &&
  order.shipping_address?.country_code !== input.shipping_address?.country_code
) {
  throw new Error("Country code cannot be changed")
}

When an ESHOPMAN order is created without a shipping address, order.shipping_address?.country_code is undefined. If you then attempt to add an address with a country code (e.g., "pl"), the comparison undefined !== "pl" evaluates to true, triggering the error. The same logic applies to the billing address.

Why This Matters for ESHOPMAN Merchants and Developers

This limitation has significant implications for headless commerce setups and integrations with HubSpot. It's a common pattern for orders to be initiated (e.g., from a checkout snapshot) and then have address details provided by the buyer minutes later. The updateOrderWorkflow is the supported and recommended path for editing ESHOPMAN orders, making this "attach address later" scenario difficult to manage.

Developers are left with problematic workarounds:

  • Omitting the country code: This silently stores an incomplete address, which can lead to issues with VAT regimes and invoicing, critical for compliance.
  • Bypassing the workflow: Directly writing to the order module loses the benefits of ESHOPMAN's workflow hooks and events, potentially compromising data integrity and business logic.

The ESHOPMAN Community's Suggested Fix

Fortunately, the ESHOPMAN community has identified a straightforward fix to this issue. The proposed solution modifies the guard condition to only perform the comparison if an existing country code is actually present on the order's address. This ensures the guard's original intent—preventing changes to an existing country code—is maintained, without blocking the initial addition of an address.

The Recommended Fix for ESHOPMAN Workflows:

if (
  input.shipping_address?.country_code &&
  order.shipping_address?.country_code &&
  order.shipping_address.country_code !== input.shipping_address.country_code
) {
  throw new Error("Country code cannot be changed")
}

By adding order.shipping_address?.country_code to the condition, the check for inequality only proceeds if both the input address and the existing order address have a country code defined. This allows new addresses to be added seamlessly, supporting flexible order management within your ESHOPMAN storefront deployed via HubSpot CMS.

This insight underscores the value of the ESHOPMAN community in identifying and resolving critical issues, ensuring the platform remains robust and adaptable for complex e-commerce operations built on Node.js/TypeScript and integrated with HubSpot.

Start with the tools

Explore migration tools

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

Explore migration tools