I would like to have your opinion for my particular case.
I have to change the price of an order item during the workflow, so what i have done below:
Code: Select all
mydiscreteOrderItem.setPrice(new Money(15));
but when the method updatePrices() is called, my orderItem price use again the sku price.
So to change the order item price, i added in myDiscreteOrderItem :
Code: Select all
@Column(name="CUSTOM_PRICE", precision=19, scale=5)
@AdminPresentation(excluded=true)
protected BigDecimal customPrice;
and i overrided the method updatePrices() of the same class :
Code: Select all
@Override
public boolean updatePrices() {
Money skuRetailPrice = getSku().getRetailPrice();
Money skuSalePrice = (getSku().getSalePrice() == null ? null : getSku().getSalePrice());
boolean updated = false;
if(customPrice != null){
setBaseSalePrice(new Money(customPrice));
setSalePrice(new Money(customPrice));
setBaseRetailPrice(new Money(customPrice));
setRetailPrice(new Money(customPrice));
updated = true;
}
if(customPrice == null){
// Override retail/sale prices from skuBundle.
if (skuBundleItem != null) {
if (skuBundleItem.getSalePrice() != null) {
skuSalePrice = skuBundleItem.getSalePrice();
}
if (skuBundleItem.getRetailPrice() != null) {
skuRetailPrice = skuBundleItem.getRetailPrice();
}
}
//use the sku prices - the retail and sale prices could be null
if (!skuRetailPrice.equals(getRetailPrice())) {
setBaseRetailPrice(skuRetailPrice);
setRetailPrice(skuRetailPrice);
updated = true;
}
if (skuSalePrice != null && !skuSalePrice.equals(getSalePrice())) {
setBaseSalePrice(skuSalePrice);
setSalePrice(skuSalePrice);
updated = true;
}
}
// Adjust prices by adding in fees if they are attached.
if (getDiscreteOrderItemFeePrices() != null) {
for (DiscreteOrderItemFeePrice fee : getDiscreteOrderItemFeePrices()) {
setSalePrice(getSalePrice().add(fee.getAmount()));
setRetailPrice(getRetailPrice().add(fee.getAmount()));
}
}
return updated;
}
It works fine but is it really the best way ?
Thanks for your advise