Copied to clipboard

Flag this post as spam?

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


  • Mikkel Johannsen 32 posts 185 karma points
    Jan 12, 2017 @ 09:47
    Mikkel Johannsen
    0

    Merchello shipment rate quotes object reference not set to an instance of an object

    Hi

    I'm looking for help regarding Merchello. I'm trying to just build a small shop and I'm not really using Merchello exactly how it should be used. I'm doing most things in views, but hoping I can get just a small webshop up and running.

    var basket = CurrentCustomer.Basket();
    var checkoutManager = basket.GetCheckoutManager();
    var billToAddress = checkoutManager.Customer.GetBillToAddress();
    var shipToAddress = checkoutManager.Customer.GetShipToAddress();
    var key = Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey;
    var rateTableProvider = (FixedRateShippingGatewayProvider)MerchelloContext.Current.Gateways.Shipping.GetProviderByKey(key);
    var shippingMethods = rateTableProvider.ShipMethods;
    var shipment = basket.PackageBasket(shipToAddress ?? billToAddress).FirstOrDefault();
    
    @foreach (var item in shippingMethods)
    {
        <h1>@item.Name @item.Key @shipment.ShipmentRateQuoteByShipMethod(item.Key)</h1>
    }
    

    When running the above code, I simply get a object reference not set to an instance of an object.

    I think it's something within my "shipment" that's null, but I can't figure out what.

    Any help is greatly appreciated!

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 12, 2017 @ 17:37
    Rusty Swayne
    0

    Normally you should not need to get the shipping provider by it's key (unless you have multiple shipping providers and your doing something specific).

       var shipment = basket.PackageBasket(shipToAddress ?? billToAddress).FirstOrDefault();
       var quotes =  shipment.ShipmentRateQuotes().ToArray();
    
       foreach(var quote in quotes) 
       {
              // quote is IShipmentRateQuote
       }
    

    where IShipmentRateQuote is

          /// <summary>
    /// Defines a shipment rate quote
    /// </summary>
    public interface IShipmentRateQuote
    {
        /// <summary>
        /// The <see cref="IShipment"/> associated with this rate quote
        /// </summary>
        IShipment Shipment { get; }
    
        /// <summary>
        /// The <see cref="IShipMethod"/> used to obtain the quote
        /// </summary>
        IShipMethod ShipMethod { get; }
    
        /// <summary>
        /// The calculated quoted rate for the shipment
        /// </summary>
        decimal Rate { get; set; }
    }
    
  • Mikkel Johannsen 32 posts 185 karma points
    Jan 15, 2017 @ 09:29
    Mikkel Johannsen
    0

    Hi Rusty

    Thanks for getting back to me. I was getting the shipping provider by its key just to see if that would work, but I couldn't get that working either.

    I've tried the code below and when running shipment.ShipmentRateQuotes().ToArray() I still get "object reference not set to an instance of an object".

    var basket = CurrentCustomer.Basket();
    var checkoutManager = basket.GetCheckoutManager();
    var billToAddress = checkoutManager.Customer.GetBillToAddress();
    var shipToAddress = checkoutManager.Customer.GetShipToAddress();
    var paymentMethods = checkoutManager.Payment.GetPaymentGatewayMethods();
    var shipment = basket.PackageBasket(shipToAddress ?? billToAddress).FirstOrDefault();
    
  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 16, 2017 @ 16:57
    Rusty Swayne
    0

    A few things to confirm:

    • The address that winds up being passed to the PackageBasket extension is not null AND that the country code is assigned.
    • You have ship methods setup for the country you are attempting to make a quote and, if the fixed rate provider, that one of your tiers (either weight or price range) would match the shipping items.
    • Your products are shippable

    If the shipment is not null - how many items got packaged?

      shipment.Items
    
  • Keith Donnell 82 posts 187 karma points
    Mar 08, 2018 @ 17:37
    Keith Donnell
    0

    This became an issue for us with UPS once they stopped supporting SSL3 and early versions of TLS. In order to fix, you simply need to force newer TLS (in your implementation of App_Start):

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

  • M N 125 posts 212 karma points
    Aug 21, 2018 @ 03:51
    M N
    0

    Hey Rusty,

    on 2.6 the following code yields no Ship Rate quotes - https://gist.github.com/rustyswayne/598049064a02fce1597c

    Was wondering if the process has changed since you posted this? Not getting any rates on my own code, so I tested it vs yours and same result! Shippable, yes, Fixed Rate assigned under US, yes. Not sure about PackageBasket, do we need this?

    About to store the shipping address in the Invoice Notes lol

Please Sign in or register to post replies

Write your reply to:

Draft