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 ?:
Customizing Add Item Workflow using Activity - Updated Any modification done to Order Pricing is undone by pricing module. Thus, this approach does not work.
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)?