Copied to clipboard

Flag this post as spam?

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


  • Kerri Mallinson 113 posts 497 karma points
    Nov 30, 2016 @ 10:34
    Kerri Mallinson
    0

    Merchello - get 'valid' Shipping Methods

    Using Umbraco v7.3.4, Merchello v1.2.12, Bazaar

    Hi,
    I have the following which is returning a list of shipping methods but i'd like to check if the shipping method is 'valid' e.g. if the basket weight is > 500kg some of the options shouldn't show because the highest 'Range' for some Shipping Methods in the DB is 400-500kg.

            public IEnumerable<SelectListItem> GetDeliveryMethodsAsRegions(IServiceContext merchelloServices, Guid selectedShippingMethod)
        {
            var collectionOnlyShippingMethod = new Guid("69EF9331-70FD-4FCD-ABE2-53136EDD20EB");
    
            var shippingMethodKey = Core.Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey;
    
            var shippingMethods = merchelloServices.GatewayProviderService.GetShipMethodsByShipCountryKey(shippingMethodKey).Where(s => s.Key != collectionOnlyShippingMethod).Select(s => new { Value = s.Key.ToString(), Text = s.Name });
    
            return new SelectList(shippingMethods, "Value", "Text", selectedShippingMethod);
        }
    

    As always, any help would be greatly appreciated.

    Thanks :)

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 30, 2016 @ 18:10
    Rusty Swayne
    0

    Hey Kerri,

    With the standard fixed rate provider using vary by weight - (assuming you're using the default provider which it looks like given the provider key your referencing) when the highest value in the weight range is 500kg no ship methods would be returned the shipment is quoted since the provider would not be able to find a method that can handle a value outside that range.

    In your code

      // this is the PROVIDER KEY not the shipMethodKey
      var shippingMethodKey = Core.Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey;
    

    Typically in Merchello, shipping is quoted through the ShippingContext

     // accessed here
      var shippingContext = MerchelloContext.Current.Gateways.Shipping;
    

    by first packaging a shipment (a process that goes through the basket and builds a collection of shipments - by default a single shipment) comprised of shippable items in the basket.

    Then the shipment is passed to the shipping context, normally through an extension method off the shipment to the ShipmentRateQuotes method in the context.

    e.g.

      var destination = // your shipping destination IAddress (for country co
      var shipment = basket.PackageBasket(address).FirstOrDefault();
    
      var quotes = shipment.ShipmentRateQuotes([used cached value = true]);
    
      // this is the same as 
      var quotes = MerchelloContext.Current.Gateways.Shipping.GetShipRateQuotesForShipment(shipment, [optional cache value]);
    

    The context first resolves all ACTIVE shipping providers and then passes the shipment to each provider which basically does what you're trying to do in the code above. Each provider will find shipping methods that can be used to quote the shipment.

    If no methods are returned from any of the providers, a method could not be found to quote the shipment - so the quotes would be an IEnumerable<IShipRateQuote>.Empty()

  • Kerri Mallinson 113 posts 497 karma points
    Dec 01, 2016 @ 13:31
    Kerri Mallinson
    0

    Thanks for the info Rusty, that all makes sense

    This site has been altered so that the delivery options and quotes appear in the basket (before the address has been entered) so this is probably where it's going wrong, i'll do some more digging...

    Ta Kerri

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Dec 01, 2016 @ 16:35
    Rusty Swayne
    0

    Hey Kerry,

    We've had to do that before as well.

    One trick is to create an empty address and populate an assumed country code.

    If you do this, you need to make sure you set the [OPTIONAL CACHE VALUE] = false in your actually shipping rate quote query EVEN if it results in the same quoted amount because the actually delivery address is stored in a serialized shipment that is stored in the shipment line item.

    It was done this way because in some (advanced implementations) one basket can be split into multiple shipments, each quoted separately that are being delivered to different destinations.

  • Kerri Mallinson 113 posts 497 karma points
    Dec 01, 2016 @ 17:05
    Kerri Mallinson
    0

    That sounds too easy :)

    The different quotes we needed to show are actually for regions, eg Scotland (central), Scotland (northern) which have different prices which also change depending on weight.

    We have the regions set as different 'providers', we also have the regions set as part of the address. The 'provider' in the drop down list in the basket is defaulted to the user's default shipping address region if they are logged in. When they checkout the shipping address defaults to the saved default address IF the region matches, else if they have another address where the regions match it uses that, else it forces them to choose an address, if they change to an address with a different region in the checkout or if they enter a new address which is not already on their account it updates the delivery 'provider' in the checkout and re-calculates the cost.

    It's been a world of pain but we're nearly there!

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Dec 02, 2016 @ 15:56
    Rusty Swayne
    0

    Interesting - your the second person I know about to use regions with the UK.

    Merchello is setup to allow for configuring regions in the Merchello.config. You can make up your own region codes if the ISO does not exist (for regions). This will allow you to "adjust" prices in shipping and taxation providers by region either by a flat or percentage increase/decrease.

    This is important in the US and Canada for shipping to Alaska or Hawaii for example.

    Not sure it is exactly what you're looking for as it is not a completely new rate table.

    If you have time, it would be great if you could send me your specific requirement (use case) just so we have a

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Dec 02, 2016 @ 15:57
    Rusty Swayne
    0

    Interesting - your the second person I know about to use regions with the UK.

    Merchello is setup to allow for configuring regions in the Merchello.config. You can make up your own region codes if the ISO does not exist (for regions). This will allow you to "adjust" prices in shipping and taxation providers by region either by a flat or percentage increase/decrease.

    This is important in the US and Canada for shipping to Alaska or Hawaii for example.

    Not sure it is exactly what you're looking for as it is not a completely new rate table.

    If you have time, it would be great if you could send me your specific requirement (use case) just so we can understand what you've been struggling with in a bit more detail.

Please Sign in or register to post replies

Write your reply to:

Draft