Copied to clipboard

Flag this post as spam?

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


  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 27, 2021 @ 08:52
    Matt Brailsford
    0

    Orderline price calculator for a Bundle

    Question by Paulius Putna

    Hi Matt,

    I have the opposite question. What if I want to keep the "main" product unit price as it is instead of sum of all sub products?

    I have this, with no luck:

    public class BundleOrderLineCalculator : OrderLineCalculator { private readonly IStoreService _storeService; private readonly IProductPriceFreezerService _productPriceFreezerService;

        public BundleOrderLineCalculator(ITaxService taxService, IStoreService storeService, IProductPriceFreezerService productPriceFreezerService) : base(taxService, storeService, productPriceFreezerService)
        {
            _storeService = storeService;
            _productPriceFreezerService = productPriceFreezerService;
        }
    
        public override Price CalculateOrderLineUnitPrice(OrderReadOnly order, OrderLineReadOnly orderLine, Guid currencyId, TaxRate taxRate)
        {
            if (orderLine.OrderLines.Any())
            {
                var store = _storeService.GetStore(order.StoreId);
                var price = _productPriceFreezerService.GetProductPrice(order.StoreId, order.Id, orderLine.ProductReference, orderLine.ProductVariantReference, currencyId).Value;
                var calculated = Price.Calculate(price, taxRate, currencyId, store.PricesIncludeTax);
    
                return calculated;
            }
    
            return base.CalculateOrderLineUnitPrice(order, orderLine, currencyId, taxRate);
        }
    }
    

    Thanks

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 27, 2021 @ 09:00
    Matt Brailsford
    0

    So you need a bundle order line to be whatever it's unit price is but everything within the bundle to be 0 priced?

  • Nelson Vicente 9 posts 29 karma points
    Mar 06, 2022 @ 20:14
    Nelson Vicente
    0

    Hello Matt, i have the same problem.

    "So you need a bundle order line to be whatever it's unit price is but everything within the bundle to be 0 priced?" Yes

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 07, 2022 @ 09:11
    Matt Brailsford
    0

    Hi @njvicente82

    Can you share what code you have tried so far?

    Many thanks

    Matt

  • Nelson Vicente 9 posts 29 karma points
    Mar 07, 2022 @ 09:15
    Nelson Vicente
    0

    Hi, I implemented a custom IOrderLineCalculator and set a bundle id to the items of the parent bundle, not sure if this is the best approach

    public class BundleCalculator : OrderLineCalculator { public BundleCalculator(ITaxService taxService, IStoreService storeService, IProductPriceFreezerService productPriceFreezerService) : base(taxService, storeService, productPriceFreezerService) { }

        public override Price CalculateOrderLineUnitPrice(OrderReadOnly order, OrderLineReadOnly orderLine, Guid currencyId, TaxRate taxRate)
        {
            if (!string.IsNullOrWhiteSpace(orderLine.BundleId))
            {
                if (orderLine.BundleId.Contains("_Subscription_Bundle_Item") || orderLine.BundleId.Contains("_Product_Bundle_item"))
                {
                    return new Price(0, 0, currencyId);
                }
            }
    
            return base.CalculateOrderLineUnitPrice(order, orderLine, currencyId, taxRate);
        }
    }
    
  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 07, 2022 @ 09:26
    Matt Brailsford
    0

    Hey Neslon,

    That's not a bad approach, but I'd probably do this based on an order line property, rather than a bundleId as there will be things in Vendr that assume bundle IDs are for a specific purpose.

    We really need to update order lines to expose a parent ID / parent Bundle ID but till then, adding a property to bundle order lines should work such that if there is a specific order line property, return a zero price like you are, otherwise fallback to the default price calculation.

    Is the code you have not working? or are you asking if this is an ok approach?

  • Nelson Vicente 9 posts 29 karma points
    Mar 07, 2022 @ 09:43
    Nelson Vicente
    0

    Hey, Yes, i'm asking if this is an valid approach. Thanks Matt

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 07, 2022 @ 09:54
    Matt Brailsford
    0

    Hey Nelson,

    Then yea, for the time being given order lines can't currently identify their parent this should be a good solution.

    Moving forward, I'm releasing a v2.1.1 shortly that I've now added ParentOrderLineId and ParentBundleId properties to order lines such that this shouldn't be necessary in future. I'll be releasing this later today.

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft