Page 1 of 1

Advise for change order item price during add item workflow

Posted: Mon Apr 15, 2013 11:02 am
by denis
Hi guys,

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

Re: Advise for change order item price during add item workflow

Posted: Wed Apr 17, 2013 9:06 pm
by phillipuniverse
Denis,

I think this solution is fine. I know we have similar logic going into 2.3.0 to support price splits, but there is similar functionality to what you did.

Re: Advise for change order item price during add item workflow

Posted: Wed Apr 17, 2013 9:06 pm
by phillipuniverse
Denis,

I think this solution is fine. I know we have similar logic going into 2.3.0 to support price splits, but there is similar functionality to what you did.

Re: Advise for change order item price during add item workflow

Posted: Thu Apr 18, 2013 7:03 am
by denis
Ok thanks for your answer !