Ensuring Accurate Price Display: Resolving Original Amount Discrepancies in ESHOPMAN Sales and Overrides
In the world of e-commerce, accurate price display is paramount, not just for customer trust but also for legal compliance. ESHOPMAN, as a robust headless commerce platform integrated with HubSpot, provides powerful pricing capabilities, including customer group overrides and sales. However, a recent community discussion highlighted a critical bug affecting how the original_amount is calculated and displayed when these complex pricing rules interact.
The Challenge: Misleading Price References on Your ESHOPMAN Storefront
The issue arises when an ESHOPMAN customer group is assigned both an override price list (representing their standard, non-retail price) and a sale price list. While ESHOPMAN's calculatePrices function correctly determines the final calculated_amount (the sale price), it incorrectly assigns the product's base price to the original_amount, rather than the customer's specific override price.
Consider a wholesale customer whose normal price for an item is 34.96. If a sale reduces the price to 29.95, the storefront might display ~~49.95~~ 29.95, implying a discount off a retail price they never pay. The honest and legally compliant display should be ~~34.96~~ 29.95. This discrepancy is not just a visual issue; the incorrect reference price is also persisted onto the line item's compare_at_unit_price in stored orders, posing a significant legal risk for businesses, especially in regions with strict consumer protection laws like the EU (PAngV / UWG).
Understanding the Technical Root Cause in ESHOPMAN's Pricing Module
The core of this problem lies within the calculatePrices() function in ESHOPMAN's pricing module, built on Node.js/TypeScript. Two factors contribute to the incorrect original_amount:
- Hardwired Original Price: The
originalPricevariable is initially set to thedefaultPrice(the base price) and is not consistently reassigned within theSALEprice list type branch. This means if a sale is active, the system defaults to the base price for comparison, ignoring any active customer group overrides. - Single List Price Selection: The logic to find a list price (
prices.find((p) => p.price_list_id)) only retrieves the first matching list price. Due to the repository's sorting by amount (ascending), when both an override and a cheaper sale price exist for the same customer group, the sale price wins, and the override price is effectively dropped from consideration for theoriginal_amount.
This combination ensures that once a cheaper sale is active, the customer's specific override price can never correctly be the original_amount.
The ESHOPMAN Community Solution: A Precise Code Adjustment
To rectify this, the ESHOPMAN community has proposed a targeted fix that ensures the original_amount accurately reflects the single, real (non-sale) price applicable to the customer's context. The solution involves a symmetrical approach: while the calculated_amount resolves over all applicable prices, the original_amount should resolve over all prices excluding sales.
Here's the suggested adjustment to the pricing module's logic:
const n => p.price_list_type !== "sale")
let originalPrice =
nonSale.find((p) => p.price_list_id) // the override, taken unconditionally (as OVERRIDE already is)
?? nonSale.find((p) => !p.price_list_id) // else base
This modification ensures that the system first identifies all non-sale prices. Then, it prioritizes finding an active customer group override. If no override is found, it gracefully falls back to the base price. This logic correctly establishes the true reference price for the customer.
Why This Fix is Safe and Essential for ESHOPMAN Merchants
This proposed fix is both safe and crucial:
- No Impact on Payable Amount: The
original_amountsolely affects the displayed and persisted reference price. It does not alter the actual payableunit_priceor total, which are correctly computed from thecalculated_amount. - Targeted Correction: The fix is a no-op unless the specific scenario of a sale stacked on a customer group override occurs – precisely the case that is currently flawed.
- Ensures Compliance: By correcting the reference price, ESHOPMAN merchants can ensure their storefronts on HubSpot CMS display prices accurately and comply with consumer protection regulations.
For ESHOPMAN developers and merchants utilizing complex pricing strategies, implementing this fix is vital for maintaining transparency, trust, and legal compliance in their e-commerce operations powered by HubSpot.