How to show it.
Create the nop order with the shipping method. Create the shipment with a tracking code.
Save it.
Delete shipping method plugin from the nopcommerce.
Try to open this shipment, you will see error message
System.NullReferenceException: Object reference not set to an instance of an object.
at Nop.Services.Shipping.ShipmentService.GetShipmentTrackerAsync(Shipment shipment)
at Nop.Web.Areas.Admin.Factories.OrderModelFactory.PrepareShipmentModelAsync(ShipmentModel model, Shipment shipment, Order order, Boolean excludeProperties)
at Nop.Web.Areas.Admin.Controllers.OrderController.ShipmentDetails(Int32 id)
at
The reason of this error in the code
return await shippingRateComputationMethod?.GetShipmentTrackerAsync();
You need replace it with
if (shippingRateComputationMethod != null)
return await shippingRateComputationMethod?.GetShipmentTrackerAsync();
else
return null;
Please do it for the pickup too
This is the new correct code
public virtual async Task<IShipmentTracker> GetShipmentTrackerAsync(Shipment shipment)
{
var order = await _orderRepository.GetByIdAsync(shipment.OrderId, cache => default);
if (!order.PickupInStore)
{
var shippingRateComputationMethod = await _shippingPluginManager
.LoadPluginBySystemNameAsync(order.ShippingRateComputationMethodSystemName);
if (shippingRateComputationMethod != null)
return await shippingRateComputationMethod?.GetShipmentTrackerAsync();
else
return null;
}
var pickupPointProvider = await _pickupPluginManager
.LoadPluginBySystemNameAsync(order.ShippingRateComputationMethodSystemName);
if (pickupPointProvider != null)
return await pickupPointProvider?.GetShipmentTrackerAsync();
else
return null;
}