Copied to clipboard

Flag this post as spam?

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


  • Johannes Lantz 156 posts 839 karma points c-trib
    Jun 18, 2021 @ 08:11
    Johannes Lantz
    0

    Bundled orderline price 0

    Hi!

    I have a product wich includes a "main product" and several "sub products". So I have added the "sub products" as bundled items to the "main prodcut" (AddProductToBundle). I would like to make the "sub products" price to become 0 while they are added these way. I have looked at Pipelines, Events, Calculators. But with no success. I would love some input on this.

    //Johannes

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 18, 2021 @ 08:21
    Matt Brailsford
    100

    Hi Johannes,

    I think your best bet would be to implement a custom IOrderLineCalculator inheriting from the default OrderLineCalculator and in it, override the CalculateOrderLineUnitPrice and if the order line belongs to a bundle, return a zero price, otherwise return the price calculated from the base implementation.

    Hope this helps

    Matt

  • Johannes Lantz 156 posts 839 karma points c-trib
    Jun 18, 2021 @ 11:32
    Johannes Lantz
    0

    Hi Matt!

    Thank you! I am a bit unsure on how I would return the orderline, that dosen't belong to the bundle. I got the following:

    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 (orderLine.BundleId == "foo")
            {
                return new Price(0, 0, currencyId);
            }
    
            return ????;
        }
    }
    

    //Johannes

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jun 18, 2021 @ 12:05
    Matt Brailsford
    1

    Almost there

    return base.CalculateOrderLineUnitPrice(order, orderLine, currenyId, taxRate);
    
  • Johannes Lantz 156 posts 839 karma points c-trib
    Jun 18, 2021 @ 15:00
    Johannes Lantz
    0

    Thank you so much Matt! 🥳

  • Paul 89 posts 167 karma points
    Oct 26, 2021 @ 20:18
    Paul
    0

    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 4125 posts 22223 karma points MVP 9x c-trib
    Oct 27, 2021 @ 08:11
    Matt Brailsford
    0

    Hi Paulius,

    I'm happy to help but you could you please raise this as a new question of it's own rather than replying on the end of an already marked as answered question.

    It just helps keeps things clear and searchable for others that have the same problem.

    Many thanks

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft