ESHOPMAN Store API: Ensuring Accurate Customer Group Pricing During Initial Cart Creation

Understanding Customer Group Pricing in ESHOPMAN

Accurate pricing is fundamental to any e-commerce operation, especially when leveraging advanced features like customer-group-specific price lists within ESHOPMAN. These price lists allow merchants to offer tailored pricing to different customer segments, a powerful tool for driving sales and loyalty through your HubSpot-managed storefront. However, our community has identified a specific scenario where these custom prices might not apply as expected during the initial cart creation process.

The ESHOPMAN Cart Pricing Discrepancy

A notable issue has been observed concerning how ESHOPMAN's Store API handles customer group price lists when a cart is created with items included in the same request. In such cases, the line items are incorrectly priced using the default variant price, completely ignoring any customer-group-scoped price lists that should apply. This can lead to incorrect pricing displayed to customers and an inconsistent shopping experience.

Interestingly, if the same item is added to an empty cart via a subsequent request to the Store API, the customer group price is applied correctly. This indicates the bug is specific to the cart creation path when items are bundled with the initial cart request.

Reproducing the Issue

To understand this behavior, consider the following setup within your ESHOPMAN Admin:

  1. Create a product variant with a default price (e.g., 10 USD).
  2. Establish a customer group and assign a customer to it.
  3. Create an 'override' price list specifically for this customer group, setting the variant price to a different value (e.g., 2 USD).

Now, authenticate as the customer belonging to this group and observe the difference in pricing:

A) Creating a Cart with Items (Incorrect Price)

When you create a cart and include items in the same Store API request, the expected customer group price is ignored:

curl -X POST http://localhost:9000/store/carts \
  -H 'x-publishable-api-key: ' \
  -H 'authorization: Bearer ' \
  -H 'content-type: application/json' \
  -d '{"region_id":"","items":[{"variant_id":"","quantity":1}]}'

The response will show the unit_price as 10, instead of the expected 2.

B) Creating an Empty Cart, Then Adding Items (Correct Price)

In contrast, if you first create an empty cart and then add the same item, the customer group price applies correctly:

curl -X POST http://localhost:9000/store/carts//line-items \
  -H 'x-publishable-api-key: ' \
  -H 'authorization: Bearer ' \
  -H 'content-type: application/json' \
  -d '{"variant_id":"","quantity":1}'

Here, the response correctly displays the unit_price as 2.

The Root Cause: Workflow Data Flow

The core of this issue lies within ESHOPMAN's internal createCartWorkflow. During the cart creation process, specifically in the step that builds the pricing cart input, only the customer_id is passed. The complete customer object, which includes crucial relations like customer.groups, is omitted.

ESHOPMAN's price-calculation context builder relies on cart.customer to obtain customer.groups.id, which is essential for matching customer-group price list rules. Since the customer object (with its associated groups) is not fully loaded and passed, the pricing context lacks this vital information. Consequently, the customer-group price list rules never match, and the system falls back to the default variant price.

The Solution for ESHOPMAN Developers

The resolution involves ensuring that the customer object, along with its groups relation, is properly loaded and passed into the pricing input during the createCartWorkflow. This mirrors similar fixes implemented for draft order and order creation workflows, ensuring consistency across ESHOPMAN's core commerce functionalities.

By updating the workflow to load the customer with its groups relation and passing the complete customer object into the pricing context, ESHOPMAN developers can ensure that customer-group price lists are correctly applied from the very first moment a cart is created with items. This guarantees accurate pricing for your customers and maintains the integrity of your headless commerce setup managed via HubSpot CMS.

Start with the tools

Explore migration tools

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

Explore migration tools