Broadleaf Microservices

Pricing Provider

Overview

Provider for interfacing with a Pricing Engine that can supply merchandise pricing for the contents of a cart. The default implementation facilitates HTTP requests against the Pricing Services endpoints. The Pricing Engine should provide retail, sale, contract, etc. prices.

Default Implementation Details

The default implementation, ExternalPricingProvider, handles building out the DTOs and pricing contexts the Broadleaf Pricing Engine requires. Each CartItem can be converted into a PriceableTarget. This process is delegated to CartItemPricingUtils, which also handles mapping the PriceInfo that the Pricing Engine returns back onto the corresponding cart items.

Request Details

A PriceableTarget is a DTO representing any kind of entity that can be priced. It includes

  • the ID,

  • the type (e.g., SKU, PRICING_KEY),

  • a map representing the priceable fields of the entity (e.g., basePrice → $10.99, salePrice → $9.99, cost → 1.99),

  • a reference to the marketplace vendor to help identify the target for applicable pricing,

  • and a map of arbitrary attributes that the pricing engine can target such as the entity’s name, categories it belongs to, etc.

These targets are included in the pricing request in the X-Price-Info-Context header as well as

  • the IDs of any prefetched price lists,

  • whether to include the PriceTypeDetails mentioned above in the response

Pricing requests can also include additional context in the X-Price-Context header such as

  • the locale,

  • currency,

  • users,

  • web request attributes like user agent or URL on the frontend being viewed

Response Details

The result of a request to the Pricing Engine is a list of PriceInfos, which are then mapped back onto their respective cart items. A PriceInfo represents the pricing information for a target. This includes

  • The target itself

  • The best overall price chosen for it

  • The type of the best price (whether base/retail, sale, contract)

  • The ID of the price list that provided the price (if any)

  • A map of all candidate prices by type of price. This includes a similar structure called a PriceTypeDetail that has the best price for that type (e.g., sale price) as well as a map of all candidate sale prices.

Configuration

ExternalPricingProperties defines the properties for configuring the ExternalPricingProvider. These include

  • broadleaf.cartoperation.pricingprovider.url: The base url of the Pricing Engine

  • broadleaf.cartoperation.pricingprovider.priceInfosUri The context path for retrieving PriceInfos for the cart This is appended to the url property.

Examples of building request from properties
UriComponentsBuilder.fromHttpUrl(properties.getUrl())
        .path(properties.getPriceInfosUri())
        .toUriString())