Ensuring Accurate Customer Group Price Lists via ESHOPMAN Admin API
Optimizing pricing strategies for different customer segments is a cornerstone of effective e-commerce, especially within a flexible platform like ESHOPMAN. Leveraging customer groups to offer tailored pricing is a powerful feature for B2B operations or loyalty programs. However, a recent community insight highlighted a subtle but significant issue where price lists targeting specific customer groups, when created via the ESHOPMAN Admin API, were silently failing to apply.
The Silent Discrepancy in ESHOPMAN Price List Rules
The core of the problem lies in an attribute-name mismatch within the ESHOPMAN platform. When a price list rule is created through the Admin API using the customer_group_id attribute, the ESHOPMAN pricing engine, during its calculation process, expects and matches against customer.groups.id. This subtle difference means that rules specifying customer_group_id are never correctly matched, leading customers in the targeted groups to pay the default price without any error or warning.
Technical Deep Dive: Attribute Flattening
The ESHOPMAN system, built on Node.js/TypeScript, processes pricing context by flattening complex objects into key-value pairs. For instance, a customer object with groups is transformed:
flattenObjectToKeyValuePairs({
region_id: "reg_1",
customer: { groups: [{ id: "cusgroup_1" }] },
})
// => { region_id: "reg_1", "customer.groups.id": ["cusgroup_1"] }
// ^ This is the expected format
The ESHOPMAN Admin API's POST /admin/price-lists endpoint, however, stores the rule attribute verbatim as customer_group_id. Since the pricing repository compares the rule attribute directly against the flattened context key, customer_group_id and customer.groups.id never align.
Reproducing the Issue
Developers and merchants can observe this behavior by:
- Creating a customer group and assigning a customer to it.
- Creating a product variant with a default price.
- Using the ESHOPMAN Admin API to create a price list with a rule targeting the customer group using
"customer_group_id": ["and a discounted price."] - Querying the product as the assigned customer via the ESHOPMAN Store API.
The expected discounted price will not be applied; instead, the default price will be returned.
Immediate Workaround for Existing Rules
For ESHOPMAN users experiencing this issue with existing price lists, a direct database update can temporarily resolve the problem:
UPDATE price_list_rule SET attribute = 'customer.groups.id' WHERE attribute = 'customer_group_id';
This SQL command updates the attribute name for existing rules to the format expected by the pricing engine, immediately enabling the correct application of customer group price lists.
Why This Issue Was Hard to Spot
This bug proved particularly elusive for two main reasons:
- The ESHOPMAN storefront management dashboard within HubSpot correctly renders the price list details, as it performs client-side transformations to resolve customer groups regardless of the underlying attribute name.
- Retrieving price lists via
GET /admin/price-listsechoes the attribute exactly as it's stored, providing no indication of the mismatch.
ESHOPMAN Team Acknowledgment and Future Fix
The ESHOPMAN team has acknowledged this as a bug. While a December 2024 migration addressed historical data in the database, the Admin API's write path itself requires a server-side transformation. This will ensure that inbound rule keys like customer_group_id are correctly normalized to customer.groups.id, aligning with how other ESHOPMAN features (such as promotions and cart/order workflows) already handle customer group attributes.
This insight underscores the value of the ESHOPMAN community in identifying and understanding critical platform behaviors. Staying informed about such technical nuances ensures your ESHOPMAN storefront, powered by HubSpot CMS and the robust Admin and Store APIs, functions optimally for all your customer segments.