Ensuring Accurate Pricing: Resolving ESHOPMAN's Price List Priority for Calculated Amounts

Unpacking ESHOPMAN's Pricing Logic: A Critical Community Insight

Accurate pricing is the bedrock of any successful e-commerce operation, especially for businesses leveraging ESHOPMAN to power their HubSpot-managed storefronts. Our community recently identified a nuanced but critical behavior within ESHOPMAN's core pricing module that could lead to customers being charged incorrect amounts. This insight highlights the importance of understanding how ESHOPMAN prioritizes different price lists and offers a clear path to resolution, ensuring your HubSpot-deployed storefronts reflect the correct pricing.

The Core Issue: Price List Prioritization Discrepancy

The heart of the matter lies in how ESHOPMAN's PricingModuleService.calculatePrices function determines the final charged price for a product. While the system's internal comments suggest that OVERRIDE price lists should always take precedence, the actual implementation of price selection can sometimes lead to a SALE price list being applied instead. This happens because the selection mechanism relies on a sorting order that prioritizes price lists with more associated rules, rather than explicitly prioritizing the OVERRIDE type.

The relevant code snippet for selecting the price-list row by position is:

const priceListPrice = prices.find((p) => p.price_list_id)

Following this, the system dispatches based on the selected row's type, despite a comment indicating the opposite rule:

// If the price list is of type OVERRIDE, we always use the price list price.switch (priceListPrice.price_list_type) {

The ordering that dictates which price is found first does not consider the price list type. Instead, it sorts primarily by the number of rules associated with the price list, in descending order, then by the amount in ascending order:

query  .orderByRaw("price.price_list_id IS NOT NULL DESC")  .orderByRaw("price.rules_count + COALESCE(pl.rules_count, 0) DESC")  .orderBy("price.amount", "asc")

This means a SALE price list with more rules could inadvertently sort ahead of an OVERRIDE price list with fewer rules, causing the SALE price to be selected for the final charged amount.

A Concrete Example of the Impact

Consider a scenario where a product has a base price of 100. An OVERRIDE price list sets the price at 60 with one rule, while a SALE price list sets it at 90 with two rules, both matching the same customer. Due to the sorting logic, the SALE row (with two rules) would sort first. The outcome would be:

  • calculated_amount: 90
  • original_amount: 60

In this case, the customer is charged 90, even though a contracted OVERRIDE price of 60 should apply. This not only leads to incorrect billing but also presents a confusing discrepancy in the reported prices.

The Path to Resolution: Leveraging Existing Logic

Interestingly, the ESHOPMAN pricing module already contains a partial solution. A variable named nonSalePriceListPrice is correctly computed and identifies the true OVERRIDE price. This value is currently used for the originalPrice, but not for the calculated_amount.

The community discussion suggests that the fix involves restructuring the selection logic within the calculatePrices function. The system should explicitly prioritize the OVERRIDE row (identified by nonSalePriceListPrice) for the calculated_amount when such a price exists. The SALE price logic should only be applied as a fallback when no OVERRIDE price is applicable.

Why This Matters for ESHOPMAN Merchants and Developers

  • For Merchants: This fix ensures the integrity of your pricing strategy. If you rely on OVERRIDE price lists for specific customer segments or contracts, this correction guarantees that those prices are accurately applied, preventing customer dissatisfaction and potential revenue loss.
  • For Developers: This insight provides crucial context when building custom pricing logic or integrating with ESHOPMAN's Admin API. Understanding these nuances in the core pricing module is vital for developing robust and accurate e-commerce solutions that deploy seamlessly on HubSpot CMS.
  • For Storefronts: Ultimately, this ensures that the prices displayed and charged on your HubSpot-powered storefronts are consistently accurate, reflecting your business rules and customer agreements.

This community insight underscores the value of collaborative knowledge sharing in maintaining a robust and reliable ESHOPMAN platform. By addressing such critical details, we collectively enhance the capabilities and trustworthiness of ESHOPMAN for all users.

Start with the tools

Explore migration tools

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

Explore migration tools