Project : Tallahesse914 GIT
https://sanacommerce.visualstudio.com/Sana%20Projects/_workitems/edit/77068
update the culture
public static class CustomHtmlExtensions { /// <summary> /// Converts the .NET date format to jQuery UI date format. /// If <paramref name="dateFormat"/> is not specified, the format from the current culture is used. /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="dateFormat">The .NET date format.</param> /// <returns>Returns the date format used by jQuery UI.</returns> /// 77068-Delete duplicate products & Date format public static string GetCustomJQueryUIDateFormat(this HtmlHelper htmlHelper, string dateFormat = null) { //switch the date format from US to AUS format (Date / Month/ Year) System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-AU"); if (dateFormat == null) dateFormat = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern; dateFormat = dateFormat.Replace("dddd", "DD").Replace("ddd", "D"); if (dateFormat.Contains("MMMM")) dateFormat = dateFormat.Replace("MMMM", "MM"); else if (dateFormat.Contains("MMM")) dateFormat = dateFormat.Replace("MMM", "M"); else if (dateFormat.Contains("MM")) dateFormat = dateFormat.Replace("MM", "mm"); else dateFormat = dateFormat.Replace("M", "m"); return dateFormat.Contains("yyyy") ? dateFormat.Replace("yyyy", "yy") : dateFormat.Replace("yy", "y"); } }
Inputs.cshtml /Sana.Commerce.Startersite/Views/Default/Helpers/Inputs.cshtml
@helper DatePicker(IDictionary<string, object> htmlAttributes) { htmlAttributes["class"] = (htmlAttributes.GetOrDefault("class") + " datepicker").Trim(); var obj = new { dateFormat = CurrentView.Html.GetCustomJQueryUIDateFormat(), firstDay = htmlAttributes.GetOrDefault("firstDay") };
This will update always when using Date pickers
public class ExtendedRequestInitializer : RequestInitializer
{
protected override void SetLanguage(ShopContext shopContext, int languageId)
{
shopContext.CommerceContext.LanguageId = languageId;
var cultureInfo = CultureInfo.GetCultureInfo(languageId);
//Thread.CurrentThread.CurrentCulture = cultureInfo;
//Thread.CurrentThread.CurrentUICulture = cultureInfo;
// Ticket 77068: Delete duplicate products & Date format
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-AU");
Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-AU");
}
}
Order details page
public class ExtendedOrdersController : OrdersController { protected override dynamic CreateOrderListJsonItem(IOrder order, OrderListFilterInputModel filter, string returnUrl = null) { var val = base.CreateOrderListJsonItem(order, filter, returnUrl); // Ticket 77068: Delete duplicate products & Date format // Date formate has been Changed to "dd/MM/yyyy" val.DocumentDate = order.DocumentDate.GetValueOrDefault(order.OrderDate).ToString("dd/MM/yyyy"); return val; } }
_Lines
@helper SimpleProductLine(SimpleProductLine productLine, bool showLineDiscounts, bool showUnitOfMeasure, bool showShippingStatus) { var line = (IOrderLine)productLine.SalesLine; var isCancelled = Model.Order.Status == OrderStatus.Cancelled || line.IsCancelled; <tr class="upper-row row-simple-product @When(isCancelled, "order-line-cancelled")"> <td>@line.ProductId</td> <td> <span class="product-title font-bigger">@line.ProductTitle</span> </td> @{ var shipmentDate = line.ShipmentDate.GetValueOrDefault().ToString("dd/MM/yyyy"); } @When(showShippingStatus, @<td>@ShippingStatus(line)</td>) @When(!Shop.IsB2cCustomer, @<td>@shipmentDate</td>) @When(Model.ShowPrices, @<td class="col-price">@line.Price.FormatAsPrice(Model.Order.CurrencyId)</td>)
Details.cshtml
@using Sana.Commerce @{ var order = Model.Order; Layout = LayoutPaths.Profile; PageInfo.Title = (order.DocumentId.AsHtml(encode: true) + " " + Sana.SimpleText("OrderType_" + order.OrderType.Value.ToString())).AsHtml(); ViewBag.PageKey = order.OrderType == OrderType.Quote ? "Quotes" : "Orders"; bool orderOrQuote = order.DocumentType == "Order" || order.DocumentType == "Quote"; var customerType = ShopApi.UserState.GetCustomerType(Shop); var shipmentDate = order.ShipmentDate.HasValue ? order.ShipmentDate.GetValueOrDefault().ToString("dd/MM/yyyy") : null; var requestedDeliveryDate = order.RequestedDeliveryDate.HasValue ? order.RequestedDeliveryDate.GetValueOrDefault().ToString("dd/MM/yyyy") : null; var promisedDeliveryDate = order.PromisedDeliveryDate.HasValue ? order.PromisedDeliveryDate.GetValueOrDefault().ToString("dd/MM/yyyy") : null; var orderDate = order.OrderDate.ToString("dd/MM/yyyy"); var documentDate = order.DocumentDate.HasValue ? order.DocumentDate.GetValueOrDefault().ToString("dd/MM/yyyy") : null; var dueDate = order.DueDate.HasValue ? order.DueDate.GetValueOrDefault().ToString("dd/MM/yyyy") : null; var paymentDiscountDate = order.PaymentDiscountDate.HasValue ? order.PaymentDiscountDate.GetValueOrDefault().ToString("dd/MM/yyyy") : null;
var leftProperties = new List<Prop> { Prop.ForAll("OrderNumber", orderOrQuote ? order.DocumentId : order.OriginalOrderId), Prop.ForAll("ShippingStatus", Shop.Settings.IsOrderShippingStatusVisible(customerType) ? ShippingStatus(order) : null), Prop.ForAll("OrderDetail_ShippingMethod", order.ShippingMethodName.Or(null)), Prop.ForAll("OrderDetail_ShippingTrackingLink", Html.TrackingLinkOrNumber(order).Or(null)), Prop.ForB2B("ShipmentDate", shipmentDate), // order.ShipmentDate.ToShortDateString() Prop.ForB2B("OrderDetail_LocationCode", order.LocationCode), Prop.ForB2B("RequestedDeliveryDate", order.RequestedDeliveryDate.ToShortDateString().Or(null)), Prop.ForB2B("OrderDetail_PromisedDeliveryDate", order.PromisedDeliveryDate.ToShortDateString().Or(null)), Prop.ForB2B("OrderDetail_SalesPersonCode", order.SalesPerson.Or(order.SalesPersonId).Or(null)), Prop.ForB2B("OrderDetail_SellToContact", order.Contact.Or(order.ContactId)), Prop.ForB2B("ReferenceNumber", order.ReferenceNo.Or(null)), Prop.ForB2B("Comments", Html.NewLinesToHtmlBreaks(order.Comment)), };
@foreach (var template in Model.Templates) { <tr> <td class="cell-check-box text-center"> <label> <span class="chb"><input name="templateIds" type="checkbox" value="@template.Basket.Id" data-bind="checked: checkedValues" /><ins><!----></ins></span> </label> </td> <td> <a class="font-title" data-bind="click: openTemplate" data-id="@template.Basket.Id">@template.Basket.Name</a> </td> <td>@template.Basket.CreatedDate.ToString("dd/MM/yyyy")</td> </
---------------------------------------------------------------------------------
if we receiving a casting problem when the user change language
borsig
protected override void FillSalesLineProperties(TypedValueDictionary fields, ISalesLine salesLine) { //----- above code remove for clearance ----- // Fixing DeliveryDate casting issue. //fields.ReadDate("Deliverydate").GetValueOrDefault(); Date DeliveryDate = Date.Empty; var dateString = fields.ReadString("Deliverydate"); if (!dateString.IsNullOrWhiteSpace()) { var date = DateTime.Parse(dateString, new CultureInfo("en-US", true)); DeliveryDate = new Date(date); }
convert dateTime to Sana .Date
var date = DateTime.Parse(dateString, new CultureInfo("en-US", true)); Sana.Date DeliveryDate = new Date(date);