Bug in the method GetShipmentTrackerAsync in nop 4.50.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
один год назад
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;

        }
один год назад
Thanks a lot for reporting. We'll fix it soon - https://github.com/nopSolutions/nopCommerce/issues/6334
один год назад
done, please see this commit to more details
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.