Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Vineeth 71 posts 291 karma points
    Jan 28, 2019 @ 09:14

    Custom Discount Functionality

    How can we subtract a custom discount coupon amount in orderline(When we add a product to the basket?

    We are implementing custom discount coupons as the requirement for the discount is a built differently than the out of the box TeaCommerce gift coupons functionality.

    We created Umbraco doc types and nodes to keep the codes and discount rules.

    enter image description here Now I’ve used CustomOrderLineCalculator to calculate the price to override the price with my custom discount coupon amount. But when i add a product to basket the CalculatePrice method receives a total amount as ‘0’ in the orderLine parameter.

    I’ve used the below example code to override the orderLine price : enter image description here

    Is this the right way or any other way to implement this ?

  • Matt Brailsford 4099 posts 22021 karma points MVP 9x c-trib
    Jan 28, 2019 @ 09:52
    Matt Brailsford

    Hi @Vineeth

    I think the issue is that when using a custom OrderLineCalculator, it is the calculators job to calculate the ENTIRE price for the OrderLine and so there won't be an existing total for you to base your calculation on, it is the calculators job to work out the orderline price from nothing.

    If you want to know what the default calculator would have calculated, you could try calling the base method to do it's calculation first and then base your value on that.

    var basePrice = base.CalculatePrice(orderLine, currency, order);
    // Do some calculation on basePrice

    In terms of other approaches, there are multiple options:

    1) Add discount codes as products with a negative price value
    2) Use events to listen for an order line to be added a modify the price then

    Hope this helps.


Please Sign in or register to post replies

Write your reply to: