Copied to clipboard

Flag this post as spam?

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


  • Puck Holshuijsen 184 posts 727 karma points
    Apr 18, 2023 @ 06:20
    Puck Holshuijsen
    0

    Add multiple Shipping Methods to an order

    Hi Matt,

    I was wondering if it would be possible to add multiple Shipping Methods to an order. I am using this method, but that only allows one:

     order.SetShippingMethod(model.ShippingMethod);
    

    In my case there are multiple types of methods:

    eg:

    • send the order or pickup
    • express delivery (receive before 10.00, 11.30 etc)
    • partial delivery (send what is in stock or wait until everything is in stock)

    Thanks!

    Puck

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Apr 18, 2023 @ 07:44
    Matt Brailsford
    0

    Hi Puck,

    You can only set a single payment method on an order currently (we are reviewing the possibility of supporting multiple shipments, but I'm not sure that's your issue here)

    You can of course define whatever shipping methods you want and allow one to be selected, but yea, an order can only have one shipping method which is whatever that selection is.

  • Puck Holshuijsen 184 posts 727 karma points
    Apr 18, 2023 @ 09:39
    Puck Holshuijsen
    0

    Hi Matt,

    That's what I thought, but just wanted to be sure.

    Is there a way to do some custom calcultion on the orders total shipping cost? I have a shippingcost calculator already, but that one is also used to get the price for the shipping method which can be chosen in the checkout. And I Couldn't find out when the calculator is processing which one.

    Because of dynamic prices, I cannot create a Shipping method for all 3 methods combined. So I was thinking to add the ShippingMethod keys in a custom order property, and use that to show in the front-end and do the correct total shipping price calculation.

    I thought overriding the OrderCalculator, but that method isn't overridable, which make me think I need to add an extra calculator in the CalculateOrderPipeline? Is that the correct way?

  • Puck Holshuijsen 184 posts 727 karma points
    Apr 18, 2023 @ 11:17
    Puck Holshuijsen
    0

    I think I got it working!

    Added a PipelineTask which adds adjustments to the shippingcost.

     public class CalculateCorrectShippingCostTask : PipelineTaskWithTypedArgsBase<OrderCalculationPipelineArgs, OrderCalculation> {
        public override PipelineResult<OrderCalculation> Execute(OrderCalculationPipelineArgs args)
        {
            var price = new Price(100, 0, args.Order.CurrencyId);
            var adjustment = new ShippingCostAdjustment("Express", "MD-001", price);
            args.Calculation.ShippingTotalPrice.Adjustments.Clear();
            args.Calculation.ShippingTotalPrice.Adjustments.Add(adjustment);
    
    
            return Ok(args.Calculation);
        }
    }
    

    This is just for testing purposes only, but the extra 100 euro's is added the shippinginfo in the order object. And also calculated correctly.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Apr 18, 2023 @ 13:59
    Matt Brailsford
    1

    Nicely done, but you might also want to check the docs here on price adjustments https://vendr.net/docs/core/3.0.0/key-concepts/price-amount-adjustments/ for how you can set them up without needing to inject your own pipeline task.

  • Puck Holshuijsen 184 posts 727 karma points
    Apr 18, 2023 @ 14:01
    Puck Holshuijsen
    0

    Thanks! I will try that also :) Maybe that will be better in my case.

Please Sign in or register to post replies

Write your reply to:

Draft