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

Best Practice for Applying Custom LineItem Pricing in Optimizely Commerce?

Vote:
 

Hi everyone,

We’re implementing Floor Sample pricing (Custom Pricing) in an Optimizely Commerce 14 project and I wanted to check if the approach we’re using is considered best practice, or if there’s a more Commerce-native way to handle dynamic pricing.

Right now, when an item qualifies as a Floor Sample, we override the price directly on the line item:

lineItem.PlacedPrice = floorSamplePrice; // custom price from database - decimal
_cartRepository.SaveCart(cart); // Save cart after updating placed price

This works, but I’m not sure if overriding PlacedPrice is the recommended pattern, especially when:

  • promotions need to run on top of the modified price

  • cart recalculation happens (totals, taxes, fees, etc.)

  • the user refreshes the cart or shipping methods

  • the price needs to persist through checkout → purchase order conversion

  • we later need to audit/track that the price used was a floor-sample price

 

My questions:

  1. Is directly setting PlacedPrice the correct way to inject custom/dynamic pricing?
    Or should we instead be extending a service like:

    • IPriceService

    • IPlacedPriceProcessor

    • or IShippingPromotionProcessor (if price affects eligibility)?

  2. Does changing PlacedPrice interfere with the pricing engine or further recalculations?

  3. Should we be storing the Floor Sample price in a custom line item property instead of overwriting PlacedPrice, and let a custom price processor pick it up?

Looking for guidance from anyone who has implemented custom/dynamic pricing outside the standard Price Cards. Any best practices or pitfalls would be really helpful!

 

Thanks

#341103
Edited, Nov 26, 2025 10:46
Vote:
 

Hi everyone,

I want to share a more robust, maintainable approach for applying custom prices (like Floor Sample pricing) in Optimizely Commerce.

Why directly setting PlacedPrice is fragile

Previous code:

lineItem.PlacedPrice = floorSamplePrice;
_cartRepository.SaveCart(cart);

It works - but I found few drawbacks:

  • If the cart is recalculated (promotions applied, taxes, shipping, quantities changed), the overridden price may be overwritten or ignored.

  • Promotion engine, discounts, price adjustments expect pricing to come from the catalog/price service, so customizing price this way can lead to unexpected results.

  • Future upgrades or changes to pricing logic might break your custom override.

 

Recommended Pattern: Use a Custom Price Processor

Instead of manually setting PlacedPrice, a better pattern is:

  • Store your custom price in a custom line-item property (e.g. FloorSamplePrice)

  • Implement a custom IPlacedPriceProcessor that inspects that property and, when present, applies it as the placed price.

  • Let the rest of the Commerce pricing pipelines (promotions, taxes, recalculation) work as normal — now they will operate with your custom price as the base.

 

Example Implementation:

[ServiceConfiguration(typeof(IPlacedPriceProcessor))]
public class FloorSamplePriceProcessor : DefaultPlacedPriceProcessor
{
    public override void ApplyPlacedPrice(
        IOrderGroup orderGroup,
        IOrderForm orderForm,
        ILineItem lineItem,
        IMarket market)
    {
        // If our custom price is provided, use it
        if (lineItem.Properties["FloorSamplePrice"] is string custom &&
            decimal.TryParse(custom, out var floorPrice))
        {
            lineItem.PlacedPrice = floorPrice;
        }
        else
        {
            // fallback to standard pricing logic
            base.ApplyPlacedPrice(orderGroup, orderForm, lineItem, market);
        }
    }
}

When adding to cart:

lineItem.Properties["FloorSamplePrice"] = floorSamplePrice.ToString();
_cartRepository.SaveCart(cart);

 

With that:

  • Custom price becomes part of the standard pricing pipeline — so discounts, promotions, taxes, shipping, and all calculations respect it.
  • If a line item doesn’t need custom pricing, default behavior remains unchanged.

This pattern aligns with how Optimizely Commerce expects custom pricing to be handled (via custom pricing providers / price processors).

 

If anyone else has implemented a similar pattern (customer-specific pricing, ERP-driven price feeds, display-sample pricing, etc.), I’d love to hear your feedback or lessons learned.

#341122
Edited, Nov 27, 2025 10:33
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.