Developer forum

Forum » Ecommerce - Standard features » Where to do some orderline recalc?

Where to do some orderline recalc?

Peter Leleulya
Reply

Hi folks,

I have the following scenerio I need to get working with DW and I'm struggling:

Ecom product is of type ProductType.BOM
The price needs to be calculated as following:

Ecom product price * User defined quantity + sum of (bomitem user defined quantity * bomitem price)
The subtotal of "bomitem user defined quantity * bomitem price" can never get below "predefined quantity * bomitem price"

For example:

Package A has a Fixed price of EUR 100 and has 2 bom items
- 1 x Bom A, UnitPrice EUR 25
- 2 x Bom B, UnitPrice EUR 50

The product tile will show EUR 100 (that is ok)
The product page will show EUR 100 (that is ok, i show the additional costs with javascript)

The user plusses "Bom B" from quantity 2 to 4  (the additional costs are changed by javascript)
The user plusses "Package 1" from quantity 1 to 10

The user adds this to the cart (I change the selected bom quantity in the EcomCartLineAddedObserver)

The cart shows:

10 x Package A, UnitPrice EUR 100, Subtotal EUR 1.000
 - 1 x Bom A
 - 4 x Bom B
----------------------------------------------------
Total: EUR 1.000

I ONLY want to do custom calculation on the Subtotal mentioned above, I need it to be set to EUR 1.225 (10 x 100 + (1x25) + (4x50)) and then update the tot price accordingly. I need a PLACE to calculate and replace the orderline price to custom business rules.

What is the proper way to accomplish this?

I've been tinkering with PriceProvider, EcomCartLineAddedObserver, PreparedPrices, etc. but can't get the Orderline.Price.Price to not be recalculated to EUR 1.000


Thanks in advance,

Peter.


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Peter

If you set AllowOverridePrices property on the orderline to false, and then change the Price propery on the orderlines as well, the orderline will not get recalculated by DW.

BR Nicolai

 
Peter Leleulya
Reply

Thanx for your quick response Nicolai.

So in my example beneith the orderline price should be 15 in the cart?
Because it isn't ...
Or did I misinterpret? Or editing in the wrong observer?

    public class EcomCartLineAddedObserver : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            if (!(args is eCommerce.Cart.Line.AddedArgs)) return;

            var added = (eCommerce.Cart.Line.AddedArgs)args;

        // do a bunch of stuff
            
            var orderLine = OrderLine.GetOrderLineByID(added.AddedLine.ID);
            orderLine.AllowOverridePrices = false;
            orderLine.Price.PriceWithoutVAT = 15.00;    // hardcoded test value
            orderLine.Price.PriceWithVAT = 15.00;    // hardcoded test value
            orderLine.Price.VATPercent = 0;        // hardcoded test value
            orderLine.Save();

            // clear chach to show shanged orderline prices
            var order = Order.GetOrderByID(added.AddedLine.OrderID);
            order.ClearCachedPrices();

        }
    }

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Peter,

Setting AllowOverridePrices to false causes the price calculation routine to kick back in. You should set it to true instead, and I believe it was a typo on Nicolai's behalf. You do need to make sure that AllowOverridePrices is set to true whenever the cart is recalculated until the cart gets converted to an order (happens on the checkout step). Otherwise the price calculation overrides your specified price.

- Jeppe

 

You must be logged in to post in the forum