Calculating discount in a custom basket pipeline task
Hi
I'm trying to calculate a volume discount on an orderline (if user buys 10 or more of the same product, he gets a 10% discount).
Marketing Foundation can't do this for me the way I want it to, so if have to do it in a custom task in the Basket pipeline.
<!-- Apply discounts --> <value>${Basket.ApplyAwards}</value> <value>${Basket.BasketCalculateDiscount}</value> <!-- <-------------- Here's my custom task -->
<!-- Calculate order level discount total based on applied discounts --> <value>${Basket.CalculateOrderLinesUnitDiscounts}</value>
I placed my custom task in the basket.config file as shown above. Is this the correct placement, chronologically speaking? I don't want subsequent tasks to delete or override my custom discount.
My real problem is that I can't find any documentation as to how the syntax for the discount should be.
Should I simply set a Discount = 123 on the OrderLine, or should I create a Discount object, and set its AmountOffTotal = 123 and add that to the OrderLine (and perhaps to the Order itself)?
Should I save the Discount and/or the OrderLine and/or the Order since they all have Save-methods?
An example of how to add a custom discount to an OrderLine programmatically would be greatly appreciated.
Create a new discount object and set the order and orderline as references on that. You have to do just after ApplyAwards as you configured. Also set the discount amount as well :)
The entire order will be saved as the last step in the Pipeline so don't issue any saves at this point.
var discount = new Discount();
discount.AmountOffTotal = discountAmount;
order.AddDiscount(discount);
orderline.AddDiscount(discount);
I kept getting an nHibernate error when updating the quantity of the order line multiple times.
NHibernate.StaleStateException: Batch update returned unexpected row count from update; actual row count: 0; expected: 1
I think I found out that the problem was that we're using Angular to update the basket view, and that the basket pipeline was executed as soon as I touched the quantity input field, resulting in the pipeline being executed several times when changing the quantity e.g. from 10 to 20.
These multiple executions resulted in the nHibernate error since the save for execution #1 had not completed before execution #2 wanted to do something with the same order/orderline/discount.
It should work if we fix it so that the basket pipeline won't be executed as often.
Calculating discount in a custom basket pipeline task
Hi
I'm trying to calculate a volume discount on an orderline (if user buys 10 or more of the same product, he gets a 10% discount).
Marketing Foundation can't do this for me the way I want it to, so if have to do it in a custom task in the Basket pipeline.
I placed my custom task in the basket.config file as shown above. Is this the correct placement, chronologically speaking? I don't want subsequent tasks to delete or override my custom discount.
My real problem is that I can't find any documentation as to how the syntax for the discount should be.
Should I simply set a Discount = 123 on the OrderLine, or should I create a Discount object, and set its AmountOffTotal = 123 and add that to the OrderLine (and perhaps to the Order itself)?
Should I save the Discount and/or the OrderLine and/or the Order since they all have Save-methods?
An example of how to add a custom discount to an OrderLine programmatically would be greatly appreciated.
Hi Marianne,
Create a new discount object and set the order and orderline as references on that. You have to do just after ApplyAwards as you configured. Also set the discount amount as well :)
The entire order will be saved as the last step in the Pipeline so don't issue any saves at this point.
Hope that helps.
Hi again
I put this in my pipeline task.
The code is executed when I update the basket, but the discount doesn't appear on the website.
Did I misunderstand what you wrote, or am I (still) missing something, Morten?
We do it like this (more or less in our code):
Don't add it to the orderLine if it is an Orderlevel discount.
My code ended up looking like this:
I kept getting an nHibernate error when updating the quantity of the order line multiple times.
I think I found out that the problem was that we're using Angular to update the basket view, and that the basket pipeline was executed as soon as I touched the quantity input field, resulting in the pipeline being executed several times when changing the quantity e.g. from 10 to 20.
These multiple executions resulted in the nHibernate error since the save for execution #1 had not completed before execution #2 wanted to do something with the same order/orderline/discount.
It should work if we fix it so that the basket pipeline won't be executed as often.
is working on a reply...