OrderDetailsModel

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 years ago
Where/how can I see what is available in the OrderDetailsModel?
I would like to modify the Views/Order/Details.cshtml so it shows optional what is shipped and what is not yet shipped. So a combination of the Details.cshtml and ShipmentDetails.cshtml.
It is for version 4.10.

I have tried to add:
foreach (var shipment in Model.Shipments) {
}
and that is fine.
I would like to get a step deeper like:
foreach (var shipment in Model.Shipments) {
    foreach (var shipitem in shipment.Items)
    {
    }
}
I guess it is because there is nothing called "shipment.Items".
2 years ago
The OrderDetailsModel has ShippingStatus, but not Shipments/Items.  
The Controllers prepare the models (via factories), so you would have to customize model/controller.
(The alternative hack/workaround would be to Resolve services and call their methods in the .cshtml file)
2 years ago
Hi there,
If you want to accomplish it by modifying only on view level, then this is for you.
Note: I must say it's not a good process to do if you want to do by source code modification.
Reference and injected service
@*Custom Start*@
@using Nop.Core.Infrastructure;
@using Nop.Services.Shipping;
@using Nop.Services.Orders;
@using Nop.Services.Catalog;
@using Nop.Services.Localization;
@using Nop.Services.Seo;
@*Custom End*@

@*Custom Start*@
@{
  var shipmentService = EngineContext.Current.Resolve<IShipmentService>();
  var orderService = EngineContext.Current.Resolve<IOrderService>();
  var productService = EngineContext.Current.Resolve<IProductService>();
  var localizationService = EngineContext.Current.Resolve<ILocalizationService>();
  var urlRecordService = EngineContext.Current.Resolve<IUrlRecordService>();
}
@*Custom End*@

On Model.Shipments loop after the table row </tr>
//Custom Start
var shipment = shipmentService.GetShipmentById(item.Id);
@if (shipment != null && shipment.ShipmentItems.Any())
{
  <tr>
    <td colspan="6">
      <table class="data-table">
        <colgroup>
          @if (Model.ShowSku)
          {
            <col width="1" />
          }
          <col />
          <col />
        </colgroup>
        <thead>
          <tr>
            @if (Model.ShowSku)
            {
              <th class="sku">
                @T("Order.Shipments.Product(s).SKU")
              </th>
            }
            <th class="name">
              @T("Order.Shipments.Product(s).Name")
            </th>
            <th class="quantity">
              Qty Ordered
            </th>
            <th class="quantity">
              @T("Order.Shipments.Product(s).Quantity")
            </th>
          </tr>
        </thead>
        <tbody>
          @foreach (var shipmentItem in shipment.ShipmentItems)
          {
            var orderItem = orderService.GetOrderItemById(shipmentItem.OrderItemId);
            if (orderItem != null)
            {
              var productName = localizationService.GetLocalized(orderItem.Product, x => x.Name);
              <tr>
                @if (Model.ShowSku)
                {
                  var sku = productService.FormatSku(orderItem.Product, orderItem.AttributesXml);
                  <td class="sku">
                    @sku
                  </td>
                }
                <td class="name">
                  <em><a href="@Url.RouteUrl("Product", new { SeName = urlRecordService.GetSeName(orderItem.Product) })">@productName</a></em>
                  @if (!string.IsNullOrEmpty(orderItem.AttributeDescription))
                  {
                    <div class="attributes">
                      @Html.Raw(orderItem.AttributeDescription)
                    </div>
                  }
                </td>
                <td class="quantity">
                  @orderItem.Quantity
                </td>
                <td class="quantity">
                  @shipmentItem.Quantity
                </td>
              </tr>
            }
          }
        </tbody>
      </table>
    </td>
  </tr>
}
//Custom END

Note: I didn't include rental info intentionally, if you need that also please let me know.
And included Qty Ordered.
Here is the outcome on order details page:

If you need the file "Presentation\Nop.Web\Views\Order\Details.cshtml" please find it here,https://drive.google.com/file/d/1naKJaKhnlY2PmpQBqwkYqORKBQ5Hk4S2/view
2 years ago
Thank you so much rmahbub63 for your code example. That helped me a lot.
I ended up with modifying the Product(s) table with a column for "remaining" just after the "Quantity" column.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.