Copied to clipboard

Flag this post as spam?

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


  • Neil Hodges 338 posts 987 karma points
    Aug 04, 2020 @ 13:57
    Neil Hodges
    0

    In Vendr is there a way to Calculate product price when adding to Basket?

    In TC i use:

    public override Price CalculatePrice(OrderLine orderLine, Currency currency, Order order)
    

    Within :

    public class CustomOrderLineCalculator : OrderLineCalculator
    

    To calculate the price of a product when adding to the basket. Can this be done in Vendr similarly?

    I'm using :

    public override Price CalculateOrderLineUnitPrice(OrderReadOnly order, OrderLineReadOnly orderLine, Guid currencyId, TaxRate taxRate)
    

    But as these are ReadOnly I cant effectively change the Price when it gets added to the basket.

    The product has a Base Price, and then properties sent along with the product in the orderLine will be then calculated before adding it to the basket.

    So for instance the product is 20sm in size @ 12.00 per 2m, I'd need to calculate that when adding to the basket for this particular product.

    Is there any way of doing that in Vendr?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 04, 2020 @ 14:18
    Matt Brailsford
    100

    Hi Neil,

    CalculateOrderLineUnitPrice is the correct newer method, but I'm not sure I understand what you mean that you can't change the price? Yes, Price objects are immutable, but the job of CalculateOrderLineUnitPrice is to return the calculated price so you can return your own instance of a Price object with a different value to have it override the Price.

    return new Price(valueWithoutTax, taxAmount, currencyId);
    

    Or, if you want it to automatically calculate the tax amount for you from the passed in tax rate

    return Price.Calculate(valueWithoutTax, taxRate, currencyId);
    

    /Matt

  • Neil Hodges 338 posts 987 karma points
    Aug 04, 2020 @ 14:23
    Neil Hodges
    0

    Ah yes, sorry see what you mean. Sorry, it's been a long day.

    Great stuff, I can calc the price given by properties.

    Thanks, Matt.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 04, 2020 @ 14:37
    Matt Brailsford
    0

    I know the feeling well. Glad I could help never the less 👍

Please Sign in or register to post replies

Write your reply to:

Draft