0

I went through the Broadleaf commerce v2.2 documentation/tutorial, specifically Customizing Add Item Workflow and Dynamic Pricing module.

I want to dynamically price a product when it is being added to a cart.

Am I correct in thinking - when a product has to be repriced there can be two approaches to do so ?:

This can be illustrated:

Approach 1:

class DynamicPricingActivity extends BaseActivity{

....
@Override
public ProcessContext execute(ProcessContext context) throws Exception {
CartOperationRequest request = ((CartOperationContext) context).getSeedData();

updatePhonePrice(request.getOrder());

return context;
}
....
}

Approach 2:

There are questions regarding instructions in Dynamic Pricing Configuration.

  • How does the method MyDynamicSkuPricingServiceImpl # getSkuPrices() get called?

    (In documentation it is mentioned that MyDynamicSkuPricingServiceImpl#getSkuPrices() will get invoked when getPrice() method gets called, I configured everything as mentioned in the documentation but getSkuPrices() never gets called implicitly)

UPDATED - I discovered if the HashMap pricingConsiderations is empty in DynamicPricingFilter, the DynamicPricingService#getSkuPrices() will not be invoked. Thus, for the dynamicPricingService to work, it is essential to have a non-empty HashMap and it will be invoked implicitly.Not sure why it is required...

How do I update the pricing of a product added to the cart without persisting this value in the database?

UPDATED

I was able to add dynamic pricing without having to persist the value in database:

  DiscreteOrderItem orderItem = orderItemService.createDynamicPriceDiscreteOrderItem(orderRequest,          pricingConsiderations);
    orderItem.setRetailPrice(new Money("623.34"));
    orderItem.setSalePrice(new Money("888.888"));
    orderItem.setPrice(orderItem.getSalePrice());
    cart.addOrderItem(orderItem);

    cart = orderService.save(cart, true);

However, the cart total is set to retail price value : 623.34. How do I get the correct total(888.888)?

aces.
  • 3,902
  • 10
  • 38
  • 48

1 Answers1

1

For your last question about overriding the price. Broadleaf provides methods for overriding the price (orderItem.setOverrideRetailPrice(), orderItem.setOverrideSalePrice()).

Without using these methods, the pricing service will reset to the current price on the SKU (or dynamic pricing implementation).

In all cases, a salePrice that is greater than the retailPrice will be ignored.

Often when overriding prices, you also want to bypass the discount engine. You can use the orderItem.setDiscountingAllowed(false).

Since this is typical behavior, a convenience method is also provided [orderItem.setPrice()] which will override both the sale and retail prices as well as set discounting allowed to false.

Brian Polster -- Broadleaf Commerce

aces.
  • 3,902
  • 10
  • 38
  • 48
polster
  • 1,353
  • 1
  • 8
  • 6