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.
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; }
}
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();
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?
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):
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
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.
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!
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).
where
IShipmentRateQuote
isHi 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".
A few things to confirm:
PackageBasket
extension is not null AND that the country code is assigned.If the shipment is not null - how many items got packaged?
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;
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
is working on a reply...