Streamlining Product Deletion in ESHOPMAN: Managing Inventory Reservations

Streamlining Product Deletion in ESHOPMAN: Managing Inventory Reservations

As an e-commerce migration expert at Move My Store, we understand the intricacies of managing your digital storefront. ESHOPMAN, our headless commerce platform built as a HubSpot application, offers robust tools for storefront management and deployment via HubSpot CMS. However, a common challenge arises when merchants or developers attempt to delete products that have existing inventory reservations.

This community insight delves into a critical workflow limitation within ESHOPMAN's Admin API and explores community-driven solutions to ensure a smooth product lifecycle management experience.

The ESHOPMAN Product Deletion Challenge

The standard process for deleting products in ESHOPMAN, typically initiated via the DELETE /admin/products/:id endpoint, encounters a significant hurdle when linked inventory items still hold reservations. This situation creates a "dead-end" in the deletion workflow. For instance, if a product has ever been part of a completed order (which keeps reservations until fulfillment cleanup) or even a soft-deleted/cancelled test order (which can keep them indefinitely), it cannot be deleted through the ESHOPMAN admin interface or the Admin API.

Current Behavior Breakdown:

  • The deleteProductsWorkflow identifies which inventory items are eligible for deletion. An item is only removed if every variant linked to it is also being deleted.
  • Subsequently, the validateInventoryDeleteStep triggers a MedusaError INVALID_DATA, preventing deletion with the message: "Cannot remove following inventory item(s) since they have reservations: [iitem_xxx]."
  • The Admin API then returns a 400 error, leaving no guided recovery path. Operators must manually locate and delete reservations for each inventory item.
  • Crucially, the productsDeleted hook, intended for post-deletion customizations, fires after the deletion steps. This timing prevents any pre-emptive cancellation of linked reservations, making it ineffective for releasing resources.

Why This Matters for Your ESHOPMAN Store

This limitation impacts ESHOPMAN merchants and developers in several ways:

  • The primary cleanup path for products becomes unusable for any item with a reservation history.
  • Reservations associated with a product that is being deleted can never be fulfilled. Cancelling them is logically sound and ensures stock returns to the available pool.
  • The intricate logic for determining which inventory items are truly linked to the product being deleted (and thus should have their reservations cancelled) is often duplicated across custom workarounds, leading to potential inconsistencies.

Community-Proposed Solutions for ESHOPMAN

The ESHOPMAN community has highlighted two primary approaches to address this challenge, aiming for a more robust and developer-friendly platform:

Option A: Built-in Handling in the Core Workflow (Preferred)

This approach suggests enhancing ESHOPMAN's core deleteProductsWorkflow. Before delegating to deleteInventoryItemWorkflow, the system would automatically cancel (soft-delete) reservations held on precisely the inventory items slated for removal. A critical component of this would be a restore-compensation mechanism, ensuring reservations are reinstated if the overall product deletion fails. The workflow could also expose cancelledReservationIds for better observability. ESHOPMAN's Inventory Module already provides the necessary APIs like softDeleteReservationItems and restoreReservationItems.

Option B: Framework-Level Minimum - A New Hook

As a minimum framework enhancement, the community proposes adding a beforeProductsDeleted hook. This new hook would fire before the deletion transaction, providing customizations with access to the full query result (variants, inventory, reservations). This would empower developers to release linked resources effectively without having to re-run complex queries themselves.

A Practical Workaround: Custom ESHOPMAN Workflow Wrapper

Until these enhancements are integrated into ESHOPMAN's core, a community-developed workaround involves creating a wrapper around the core deletion workflow. This custom workflow, named deleteProductsWithReservationsWorkflow, mirrors ESHOPMAN's internal logic and safely handles reservations:

// Pure helper mirroring the core selection rule exactly
export function computeInventoryItemsToDelete(variants: VariantInventoryRef[]): string[] {
  const variantsMap = new Map(variants.map((v) => [v.id, v]))
  const toDeleteIds = new Set()
  variants.forEach((variant) => {
    if (!variant.manage_inventory) return
    for (const inventoryItem of variant.inventory ?? []) {
      // empty variant list is vacuously true — matches core
      if (inventoryItem.variants.every((linked) => variantsMap.has(linked.id))) {
        toDeleteIds.add(inventoryItem.id)
      }
    }
  })
  return Array.from(toDeleteIds)
}

// Step: list reservations for these items -> softDeleteReservationItems
// Compensation: restoreReservationItems(ids) if a later step fails

This wrapper is designed to be empty-safe, precisely mirrors ESHOPMAN's core variant/inventory selection rules, restores reservations if the product deletion fails, and returns the IDs of cancelled reservations for transparency.

Moving Forward with ESHOPMAN

This discussion highlights the ESHOPMAN community's active role in shaping the platform's capabilities. While these are currently feature requests for core ESHOPMAN enhancements, the proposed solutions and existing workarounds provide valuable insights for developers managing complex product lifecycles within their headless commerce setup on HubSpot CMS. Efficient management of product data, including inventory reservations, is crucial for maintaining a streamlined and error-free e-commerce operation.

Start with the tools

Explore migration tools

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

Explore migration tools