Preventing Over-Discounting: Ensuring Accurate BuyGet Promotion Stacking in ESHOPMAN

At Move My Store, we empower merchants to leverage the full potential of ESHOPMAN for their headless commerce needs, seamlessly integrated with HubSpot. A key aspect of any successful e-commerce operation is robust promotion management. Recently, our community identified a critical issue related to how ESHOPMAN handles stacked promotions, specifically involving "BuyGet" (BUYGET) discounts. Understanding this behavior is crucial for maintaining accurate pricing and preventing financial discrepancies in your HubSpot-deployed storefronts.

The Challenge: Over-Discounting with Stacked BuyGet Promotions

Merchants utilizing ESHOPMAN's powerful promotion engine might encounter situations where a "BuyGet" promotion, when applied to line items that already have existing discounts, leads to an unintended over-discounting. This can result in a line item's total value becoming negative, which is an undesirable outcome for any e-commerce platform.

Understanding the Root Cause

The core of this issue lies within ESHOPMAN's promotion calculation logic, specifically in the module responsible for computing BuyGet actions. Our community observations point to the promotion/src/utils/compute-actions/buy-get.ts file, particularly within the getComputedActionsForBuyGet and applyPromotionToTargetItems methods. It appears that while these methods retrieve previously applied promotion values (e.g., via methodIdPromoValueMap.get(item.id)), this value isn't consistently subtracted from the eligible amount before a subsequent BuyGet discount is calculated.

Consequently, the BuyGet promotion calculates its discount based on the line item's original unit price, rather than the remaining value after prior discounts have been applied. This oversight allows the combined discounts to exceed the actual value of the line item.

A Practical Example of Over-Discounting

Consider the following scenario in your ESHOPMAN storefront:

  • Line item quantity: 3 units
  • Unit price: 199 ESHOPMAN Credits (or currency equivalent)
  • Original subtotal: 597
  • Previously applied discount: 500 (from a prior promotion)
  • Remaining eligible amount: 97

When a subsequent BuyGet promotion is applied, offering a 100% discount on one unit, the system incorrectly calculates this discount as 199 (based on the original unit price). This leads to:

  • Total discounts: 500 (previous) + 199 (BuyGet) = 699
  • Final line item total: 597 - 699 = -102

Similarly, a fixed discount of 150 applied after the initial 500 discount would result in total discounts of 650, leading to a negative line item total of -53.

Expected vs. Actual Behavior in ESHOPMAN

Expected Behavior: ESHOPMAN's promotion engine should always account for all previously applied promotion adjustments. Any subsequent discount, including BuyGet promotions, should be capped at the remaining eligible value of the line item. Critically, a line item's total should never become negative due to promotion stacking. If a line item has already been fully discounted, no further promotions should apply.

Actual Behavior: As observed, BuyGet promotions currently calculate discounts without properly subtracting the values of previously applied promotions. This flaw allows the total discounts to exceed the line item's actual value, resulting in negative totals and potential financial inconsistencies for merchants managing their stores via HubSpot.

Impact and Resolution for ESHOPMAN Users

This issue highlights the importance of robust promotion logic for ESHOPMAN, a headless commerce platform built on Node.js/TypeScript that provides storefront management within HubSpot. Accurate discount application is fundamental for maintaining customer trust and operational integrity. While a platform-level fix is required to address this calculation anomaly, understanding this behavior helps ESHOPMAN developers and merchants identify and report such discrepancies, contributing to a more resilient and precise commerce experience.

The ESHOPMAN community is actively working to ensure that all promotion types, including BuyGet, consistently respect accumulated promotion values, aligning with best practices for e-commerce discount computations across the Admin API and Store API.

Start with the tools

Explore migration tools

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

Explore migration tools