Copied to clipboard

Flag this post as spam?

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


  • Sean Dooley 288 posts 527 karma points
    May 03, 2022 @ 11:31
    Sean Dooley
    0

    Set orderline price depending on quantity for certain products

    Have a requirement to set the price for certain products depending on the quantity that has been added to the basket.

    Product A x 1 | 12.95
    Product A x 2 | 25.90
    ---
    Product B x 1 | 24.95
    Product B x 2 | 39.95
    Product B x 4 | 59.95
    

    Product A is a straight forward unit price * quantity. Whereas Product B requires some bespoke logic.

    From what I can workout, I should be applying the logic with a custom OrderLine calculator. See a work in progress example below.

    public override Price CalculateOrderLineUnitPrice(OrderReadOnly order, OrderLineReadOnly orderLine, Guid currencyId, TaxRate taxRate)
        {
            try
            {
                var store = _storeService.GetStore(order.StoreId);
                var price = store.PricesIncludeTax
                    ? orderLine.UnitPrice.Base.WithTax * orderLine.Quantity
                    : orderLine.UnitPrice.Base.WithoutTax * orderLine.Quantity;
    
                return Price.Calculate(price, taxRate, currencyId, store.PricesIncludeTax);
            }
            catch (Exception exception)
            {
                return base.CalculateOrderLineUnitPrice(order, orderLine, currencyId, taxRate);
            }
        }
    

    Am I taking the right approach?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    May 03, 2022 @ 12:50
    Matt Brailsford
    100

    Hi Sean,

    Yea, that's how you'd want to tackle it.

    The idea I had (but haven't tested yet) is to have a price on a product, and then have a nested content field on the product for price breaks and in each entry have a quantity + price adjustment value, then in the order line calculator you could lookup the price break that applies and apply it to the base product price.

    I've got a feeling there may be a forum post somewhere on here that discusses this but I'm not sure the link off the top of my head. Might be worth a search.

    Hope this helps

    Matt

  • Sean Dooley 288 posts 527 karma points
    May 03, 2022 @ 20:04
  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    May 04, 2022 @ 07:26
    Matt Brailsford
    0

    That's the one 👍

  • Sean Dooley 288 posts 527 karma points
    May 05, 2022 @ 16:46
    Sean Dooley
    0

    The logic works, however it isn't the required result in this instance as we are looking to have the the price to be fixed at that value rather than a discount.

    The solution we can think of at the moment is to add the quantities as separate products with a fixed price and shared SKU in the CMS.

    I would be grateful if you had any thoughts?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    May 06, 2022 @ 07:57
    Matt Brailsford
    0

    Hey Sean,

    Then couldn't you just have fixed prices in the nested content editor and in the calculator, just return that price rather than deducting it from the base price?

    Matt

  • Sean Dooley 288 posts 527 karma points
    May 06, 2022 @ 09:15
    Sean Dooley
    0

    I've been treating the price break as a fixed cost, however it shows in the basket as a discount (which the client doesn't want) and multiples the unit price by the quantity as expected.

    Think the issue I'm trying to get my head around is that the requirement is to show, using the example in the original post, Product B x 4 as a variant with a fixed cost rather than a quantity though the client/fulfillment doesn't have an SKU for Product B x 2 and Product B x 4. This means showing the them as a single product on the frontend, yet sending it over the client/fulfillment as a quantity.

    Think in this instance, adding them as separate products in the CMS might be the way to go.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    May 06, 2022 @ 09:20
    Matt Brailsford
    0

    Hmm, if it's fixed known quantities and you can't just buy X many and you get a price break at different levels, it does sound like specific products might be better 🤔

Please Sign in or register to post replies

Write your reply to:

Draft