Posted on 21/04/2023 21:56:51
AFAIK, there's indeed no model for recurring orders. But you can fetch them using the API. This is what we have in CustomerOrderViewSearchList.cshtml:
@foreach (var order in Model.Orders.Where(x => x.Completed.HasValue && x.Completed.Value).OrderBy(o => o.StateName))
{
string orderLink = $"/Default.aspx?ID={Pageview.Page.ID}&OrderId={order.Id}";
var recurringOrder = Dynamicweb.Ecommerce.Orders.RecurringOrder.GetRecurringOrderById(order.RecurringOrderId.GetValueOrDefault());
string recurringPlacedDateForOrder = ((DateTime?)order.CompletedDate)?.ToString("dd MMM yyyy");
string recurringNextDelivery = ((DateTime?)recurringOrder.NextDelivery)?.ToString("dd MMM yyyy");
string recurringLastDelivery = ((DateTime?)recurringOrder.LastDelivery)?.ToString("dd MMM yyyy");
var deliveryURL = $"/Default.aspx?ID=2100&OrderId={order.Id}";
<tr>
<td>
<a href="@orderLink" class="d-block text-start text-decoration-none" tabindex="-1">@Translate(order.StateName)</a>
</td>
<td>
<a href="@orderLink" class="d-block text-start text-decoration-none" tabindex="-1">@recurringOrder.Interval @Translate(recurringOrder.IntervalUnit.ToString())</a>
<br />
</td>
<td>
<a href="@orderLink" class="d-block text-end text-decoration-none" tabindex="-1">@recurringNextDelivery</a>
</td>
<td>
<a href="@orderLink" class="d-block text-end text-decoration-none" tabindex="-1">@recurringLastDelivery</a>
</td>
<td>
<a href="@orderLink" class="d-block text-end text-decoration-none" tabindex="-1">
<span class="text-price">@order.Price.PriceFormatted</span>
</a>
</td>
</tr>
}
And here's what we have in CustomerOrderDetails.cshtml:
var recurringOrder = Dynamicweb.Ecommerce.Orders.RecurringOrder.GetRecurringOrderById(Model.RecurringOrderId.GetValueOrDefault());
Then you can access recurring order details as follows:
var delUrl = "Default.aspx?ID=" + Pageview.Page.ID + "&DelRecurringOrderId" + Pageview.CurrentParagraph.ID + "=" + Model.RecurringOrderId.ToString();
<a href="@delUrl">@Translate("Unsubscribe")</a>
@if (!string.IsNullOrEmpty(recurringOrder.Frequency))
{
<tr>
<td>@Translate("Frequency")</td>
<td class="text-end">@recurringOrder.Interval @Translate(recurringOrder.IntervalUnit.ToString())</td>
</tr>
}
@if (!string.IsNullOrEmpty(recurringOrder.StartDate.ToString()))
{
var orderDate = recurringOrder.StartDate.Value.ToString();
<tr>
<td>@Translate("Start Date")</td>
<td class="text-end">@orderDate.Substring(0, orderDate.Length - 9)</td>
</tr>
}
@if (!string.IsNullOrEmpty(recurringOrder.LastDelivery.ToString()))
{
<tr>
<td>@Translate("Last Delivery Date")</td>
<td class="text-end">@recurringOrder.LastDelivery</td>
</tr>
}
Hope this helps, but let me know if you need more info. I didn't want to post the full templates as they contain tons of other code.
Imar