Unpacking ESHOPMAN Item-Level Discount Glitches on Draft Orders
Understanding ESHOPMAN's Item-Level Discount Behavior on Draft Orders
In the dynamic world of headless commerce, precise discount application is paramount for both customer satisfaction and accurate financial reporting. ESHOPMAN, leveraging HubSpot CMS for storefronts and a robust Node.js/TypeScript backend with Admin and Store APIs, empowers merchants with flexible promotion capabilities. However, a recent community insight has highlighted a specific challenge: item-level discounts applied to draft orders are not calculating as expected, despite being accepted by the Admin API.
The Problem Identified: Discounts Not Reflecting on Draft Orders
A detailed report from an ESHOPMAN developer outlined a scenario where applying an item-level promotion to a draft order via the Admin API endpoint POST /admin/draft-orders/{id}/edit/promotions results in the promotion being added to the order's promotions array, but without any corresponding discount calculation. This means the discount_total remains zero, item totals are unaffected, and critically, the application_method field is entirely missing from the promotion object in the API response. This behavior is specifically observed with item-level promotions; order-level promotions appear to function correctly.
Technical Deep Dive and Reproduction Steps
To illustrate the issue, a test configuration was used involving a fixed-value item-level promotion. This promotion, with a code like SPCPROD20, was configured for a fixed $20.00 CAD discount, targeting specific items within a particular product category (e.g., 'Pre Roll'). The promotion was set to apply to 'each' qualifying item, with a maximum quantity of one. A product matching these criteria, priced at $25.99 CAD, was added to a draft order. The promotion's structure, retrieved from the ESHOPMAN Admin API, looked like this:
{
"id": "promo_01KEJFSWKSY6X6N19J3WDXVNQS",
"code": "SPCPROD20",
"type": "standard",
"status": "active",
"is_automatic": false,
"is_tax_inclusive": false,
"application_method": {
"id": "proappmet_01KEJFSWKTQ4NMNWYKQ2J3JGC5",
"currency_code": "cad",
"max_quantity": 1,
"type": "fixed",
"target_type": "items",
"allocation": "each",
"value": 20,
"target_rules": [
{
"id": "prorul_01KEJFSWKVK0WY5YA9R06AE3QE",
"attribute": "items.product.categories.id",
"operator": "eq",
"values": [
{
"value": "pcat_01KAS4E6JEX5J2YMWJ5BV0GQZW"
}
]
}
]
}
}Upon sending the POST request to apply the SPCPROD20 promo code to the draft order, the ESHOPMAN Admin API returned an updated order object. The key discrepancy was that while the promotions array now included the SPCPROD20 promotion, all financial fields related to discounts remained unchanged. For comparison, here's a simplified view of the expected vs. actual order state after applying the promotion:
// Expected Order State (excerpt)
{
"order": {
"discount_total": 20.00,
"subtotal": 5.99,
"tax_total": 0.30,
"total": 6.29,
"items": [
{
"subtotal": 5.99,
"discount_total": 20.00,
"tax_total": 0.30,
"total": 6.29
}
],
"promotions": [
{
"code": "SPCPROD20",
"application_method": {
"type": "fixed",
"value": 20,
"target_type": "items"
// ... more details
}
}
]
}
}
// Actual Order State (excerpt - BUG DETECTED)
{
"discount_total": 0,
"subtotal": 25.99,
"tax_total": 1.2995,
"total": 27.2895,
"items": [
{
"subtotal": 25.99,
"total": 27.2895
// discount_total missing or 0
}
],
"promotions": [
{
"code": "SPCPROD20"
// application_method MISSING
}
]
}This clearly illustrates that the discount logic for item-level promotions on draft orders was not triggered or processed correctly, and the crucial application_method object was absent from the returned promotion details.
Impact and Community Insight
This detailed report serves as a vital piece of community knowledge for ESHOPMAN developers and merchants. Accurate discount application is fundamental for sales, marketing campaigns, and maintaining trust in pricing. While order-level promotions work, the failure of item-level discounts on draft orders can lead to incorrect pricing, customer dissatisfaction, and operational challenges, especially when preparing orders or quotes. This insight highlights a specific area where ESHOPMAN's core platform needs attention to ensure the robust functionality expected from a headless commerce solution integrated with HubSpot CMS. The community looks forward to a resolution that ensures seamless and accurate promotion application across all scenarios.