I want to add data to the order details in admin section. Because I want to minimize changes of the core code I've decided to add a widget calling in view and create a widget.
So in file _OrderDetails.Shipping.cshtml I've added:
@Html.Widget("order_shipping_info_bottom", Model.Id)
Widget has following methods implemented:
public void GetDisplayWidgetRoute(string widgetZone, out string actionName, out string controllerName,
out RouteValueDictionary routeValues)
{
controllerName = "ShoppingCartWeight";
routeValues = new RouteValueDictionary
{
{"Namespaces", "Nop.Plugin.Ralfeus.ShoppingCartWeight.Controllers"},
{"area", null},
{"widgetZone", widgetZone}
};
switch (widgetZone)
{
case "order_summary_cart_footer":
actionName = "Cart";
break;
case "productdetails_before_collateral":
actionName = "ProductDetails";
break;
case "order_shipping_info_bottom":
controllerName = "AdminOrderWeight";
actionName = "OrderShipping";
break;
default:
actionName = null;
break;
}
}
[ChildActionOnly]
public ActionResult OrderShipping(int orderId)
{
var primaryWeight = this._measureService.GetMeasureWeightById(this._measureSettings.BaseWeightId);
var order = _orderService.GetOrderById(orderId);
decimal orderWeight = 0;
foreach (var orderItem in order.OrderItems)
{
var product = _productService.GetProductById(orderItem.ProductId);
orderWeight += product.Weight;
}
var model = new ShoppingCartWeightModel
{
Weight =
$"{orderWeight:N0} {primaryWeight.Name}"
};
return PartialView("~/Plugins/Ralfeus.ShoppingCartWeight/Views/AdminOrderWeight/_Shipping.cshtml", model);
}
When I try to open order details page I get following exception:
The parameters dictionary contains a null entry for parameter 'orderId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult OrderShipping(Int32)' in 'Nop.Plugin.Ralfeus.ShoppingCartWeight.Controllers.AdminOrderWeightController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
I've checked that while calling widget order ID is passed. What could go wrong?