A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More.
A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More.
The right way would be using OrderValidationService, which will validate the order for any issues (like out of stock items, price changed etc.), and apply promotions
For the record, I don't recognize ICartPipeline, nor ICartService. They are likely part of your solution, not a part of the platform APIs
Thanks Quan for your response, yes those methods are part of our solution.
Also I’ve refined a safe and repeatable approach to force a full order recalculation before SaveAsPurchaseOrder in Commerce 14. This ensures capture the latest prices, promotions, taxes, and validations, mitigating edge issues like inventory changes or price updates mid-checkout.
Recommended Full Recalculation + Order Save Flow
Use a helper routine that runs this sequence on the cart - then converts to a PurchaseOrder only after everything is fresh:
// Example helper method
public IDictionary<ILineItem, ValidationIssue> RecalculateCart(ICart cart)
{
var issues = new Dictionary<ILineItem, ValidationIssue>();
var contact = _customerContext.CurrentContact;
// 1. Validate items — availability, market, dates, etc.
cart.ValidateOrRemoveLineItems(
(item, issue) => issues[item] = issue,
_lineItemValidator);
// 2. (Re-)Apply placed prices — catalog or custom pricing
cart.UpdatePlacedPriceOrRemoveLineItems(
contact,
(item, issue) => issues[item] = issue,
_placedPriceProcessor);
// 3. Run promotions / discounts
cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings());
// 4. Recalculate totals: subtotal, discounts, tax, shipping, grand total
_orderGroupCalculator.GetOrderGroupTotals(cart);
return issues;
}
Checkout / Order Save sequence:
var issues = RecalculateCart(cart);
if (issues.Any())
{
// Inform user / handle invalid items or price issues
// e.g. “Cart updated — please review before checkout.”
return;
}
var purchaseOrder = _orderRepository.SaveAsPurchaseOrder(cart);
_orderRepository.Save(purchaseOrder);
Thanks,
yes - good point!OrderValidationService does wrap a similar sequence internally (validation → price processors → promotions → totals), which is why my custom flow looks very close to what that service does under the hood.
In our case, we needed a little more control over when recalculation happens (specifically right before SaveAsPurchaseOrder) and the ability to plug in some project-specific logic around:
custom price sources
extra line-item validations
address-dependent recalculation
enforcing a “cart state must not change after this point” rule
So the custom recalculation pipeline is effectively the same pattern as OrderValidationService, just with more explicit hooks for our checkout flow.
Thanks for pointing it out - definitely helpful for others reading the thread!
Hi,
I’m working on a checkout flow in Commerce 14 where I need the order to be fully recalculated (prices, discounts, taxes, fees, shipping) right before the cart is converted into a
PurchaseOrder.Right now, I’m doing something like this:
It works most of the time, but I’ve noticed a few edge cases:
If inventory changes during checkout
If shipping address changes
If customer-specific pricing is applied
If promotions expire in between steps
…the totals on the final PurchaseOrder are sometimes slightly different from what the customer saw in the cart, and right now I am just showing payment sums not matched Error message on Website.
Is there a recommended way to force a full recalculation (pricing + taxes + promotions + shipping) right before
SaveAsPurchaseOrder, with guaranteed consistency?Should I be using:
ICartPipeline.Run(...)?ICartService.RecalculateShipment(...)?ILineItemCalculator+IOrderFormCalculatormanually?Or some end-to-end “checkout pipeline” pattern?
Looking for guidance on a clean, production-safe approach.
Thanks,
Sunil