nopSolutions / nopCommerce

ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
https://www.nopcommerce.com
Other
9.14k stars 5.25k forks source link

Null reference Error, Admin/OrderModelFactory/PrepareOrderModelShippingInfoAsync #7124

Closed danFbach closed 5 months ago

danFbach commented 5 months ago

nopCommerce version: 4.60.6

I'm actively getting an exception thrown here on an order.

protected virtual async Task PrepareOrderModelShippingInfoAsync(OrderModel model, Order order)

if (!order.PickupInStore)
{
    //null reference possibility, as order.ShippingAddressId is never checked to have a value.
    var shippingAddress = await _addressService.GetAddressByIdAsync(order.ShippingAddressId.Value);
    var shippingCountry = await _countryService.GetCountryByAddressAsync(shippingAddress);

    model.ShippingAddress = shippingAddress.ToModel(model.ShippingAddress);
    model.ShippingAddress.CountryName = shippingCountry?.Name;
    model.ShippingAddress.StateProvinceName = (await _stateProvinceService.GetStateProvinceByAddressAsync(shippingAddress))?.Name;
    await _addressModelFactory.PrepareAddressModelAsync(model.ShippingAddress, shippingAddress);
    SetAddressFieldsAsRequired(model.ShippingAddress);
    model.ShippingAddressGoogleMapsUrl = "https://maps.google.com/maps?f=q&hl=en&ie=UTF8&oe=UTF8&geocode=&q=" +
        $"{WebUtility.UrlEncode(shippingAddress.Address1 + " " + shippingAddress.ZipPostalCode + " " + shippingAddress.City + " " + (shippingCountry?.Name ?? string.Empty))}";
}
AndreiMaz commented 5 months ago

@danFbach Please provide a list of steps to reproduce the issue on the clean installation. This method validates whether this order required shipping. Hence, a shipping address cannot be null (until you manually deleted it from the database)

danFbach commented 5 months ago

The order was created without shipping required, so no shipping address was added. However, the order was actually shipped with a third party fulfillment channel, as it turned out there was something to ship. I'm guessing when it posted the shipping method back to nop, it changed the order to require shipping, however the order still does not have a shipping address.

AndreiMaz commented 5 months ago

However, the order was actually shipped with a third party fulfillment channel.

In this case this "import" should be fixed third-party developers. This order wasn't properly updated by this third party fulfillment channel.