Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Managing pricing

Managing pricing

Getting Prices in the Cart

The shopping cart uses the PriceLookupFacade service to retrieve prices. For example, AbstractCatalogControllerImpl contains the following code:

protected Map<String, Price> getProductPrices(final Collection<StoreProduct> products, final ShoppingCart cart) {
    if (products == null) {
        return Collections.EMPTY_MAP;
    }
    return priceLookupFacade.getPromotedPricesForProducts(
            new ArrayList<Product>(products),
            cart.getStore(),
            cart.getCustomerSession(),
            cart.getAppliedRules());
}

The getPromotedPricesForProducts method of PriceLookupFacade returns a map of prices (keyed on product code) for the current shopper for the specified products with all cart promotion rules applied.

Getting the Shopper's Price List Stack

The PriceListLookupService's retrievePriceListStack method is called to fetch the price list stack.

void retrievePriceListStack(final CustomerSession customerSession) {
    customerSession.setPriceListStack(
            priceListLookupService.getPriceListStack(
                    customerSession.getCustomer().getStore().getCatalog().getCode(),
                    customerSession.getCurrency(),
                    customerSession.getCustomerTagSet()
            )
    );
}

getPriceListStack gets the price list stack for a shopper in the specified currency. Note that you can customize how it determines which price lists are in the stack by Customizing the price list stack lookup strategy and wiring it to the PriceListLookupService bean.

Getting Prices in the Commerce Manger

The PriceListService is used in the CM to retrieve price list descriptors and prices. Note that this service uses DTOs to minimize overhead of working with domain objects, which contain additional data and persistence method that are not required on the client.

PriceListService priceListService = getBeanFactory().getBean(ContextIdNames.PRICE_LIST_CLIENT_SERVICE);
BaseAmountDTO baseAmount = priceListService.getBaseAmount(baseAmountGuid);