Skip to content

Fix quotes with unit multiplier - #83

Closed
nicholas-maestrello wants to merge 2 commits into
masterfrom
B2BTEAM-3154
Closed

Fix quotes with unit multiplier#83
nicholas-maestrello wants to merge 2 commits into
masterfrom
B2BTEAM-3154

Conversation

@nicholas-maestrello

@nicholas-maestrello nicholas-maestrello commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

What problem is this solving?

This PR fixes critical pricing issues in the B2B Quotes GraphQL backend when applying quotes to shopping carts:

1. Index-Based Mapping Bug (Price Mismatch)

Problem: When a quote contained multiple lines of the same SKU at different prices, the useQuote mutation was using a simple index-based mapping that didn't account for VTEX's automatic item grouping. This caused:

  • Wrong prices applied to wrong products
  • Items merged incorrectly in the cart
  • Discrepancies between quote totals and cart totals

Example:

Quote with multiple prices:
- Line 1: SKU-A, 2 units @ $1,000 (original price)
- Line 2: SKU-A, 2 units @ $800 (promotional price)
- Line 3: SKU-B, 5 units @ $500

Old behavior (index-based mapping):
1. Map by array index: [0]→$1000, [1]→$800, [2]→$500
2. VTEX groups SKU-A → creates 2 cart lines
3. Look up prices by cart index: [0]→$1000 ✅, [1]→$800 ❌ (applies to SKU-B!)
Result: SKU-B charged $800 instead of $500, promotional pricing lost

New behavior:
Cart shows:
- 2x SKU-A @ $1,000 = $2,000 (original price line)
- 2x SKU-A @ $800 = $1,600 (promotional line)
- 5x SKU-B @ $500 = $2,500
All prices correct, promotions visible!

2. Currency Precision (ORD024 Error)

Problem: VTEX's OrderForm API rejects prices that don't match the currency's decimal precision. For currencies like CLP and JPY that have 0 decimal places, prices must be multiples of 100.

Error:

ORD024 - "Precisión del precio inválida"
Item 305644: price 305644 is invalid for CLP currency

3. Gift Item Errors

Problem: The mutation attempted to apply manual prices to gift items, which is forbidden by VTEX's checkout API.

4. UnitMultiplier in Subtotals

Problem: Quote subtotal calculations weren't applying unitMultiplier, causing mismatches between displayed quote totals and actual cart totals for items sold by weight, volume, or other measurements.


How to test it?

Test 1: Weighted Average Pricing

  1. Create a quote with multiple lines of the same SKU at different prices
  2. Use GraphQL mutation:
mutation {
  useQuote(id: "quote-id")
}
  1. Verify cart total matches quote subtotal (weighted average)

Test 2: CLP Currency Handling

  1. Configure store to use CLP currency
  2. Create quotes with various prices
  3. Apply quotes and verify:
    • No ORD024 errors
    • All prices are multiples of 100

Test 3: USD/BRL Currency Handling

  1. Configure store to use USD or BRL
  2. Verify normal penny-precision rounding works
  3. Verify weighted averages preserve cents

Test 4: Gift Items

  1. Add gift items to a quote
  2. Apply quote to cart
  3. Verify gift items are preserved without repricing

Test 5: UnitMultiplier

  1. Create quote with items that have unitMultiplier != 1 (e.g., products sold by kg)
  2. Verify quote subtotal includes multiplication
  3. Verify cart total matches quote subtotal

Screenshots or example usage

Screen.Recording.2026-02-19.at.13.19.47.mov

Related to / Depends on


@nicholas-maestrello nicholas-maestrello self-assigned this Feb 19, 2026
@vtex-io-ci-cd

vtex-io-ci-cd Bot commented Feb 19, 2026

Copy link
Copy Markdown

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@vtex-io-docs-bot

vtex-io-docs-bot Bot commented Feb 19, 2026

Copy link
Copy Markdown

Beep boop 🤖

I noticed you didn't make any changes at the docs/ folder

  • There's nothing new to document 🤔
  • I'll do it later 😞

In order to keep track, I'll create an issue if you decide now is not a good time

  • I just updated 🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant