[48670] [Diversey] 3.1. DELIVERY BASED ON ERP FACTORY CALENDARS
Versalert project
1. we keep disabled dates on model
ExtendedAdditionalInfoModel
public class ExtendedAdditionalInfoModel : AdditionalInfoModel { //RFC01_v1.4:[Ticket 48670] 3.1.DELIVERY BASED ON ERP FACTORY CALENDARS [Required] [LookupPeriodDateValidation(ErrorMessageResourceName = SanaTextKeys.InvalidField)] [DisableDateValidation(ErrorMessageResourceName = SanaTextKeys.InvalidField)] public override Date? DeliveryDate { get; set; } public List<string> DisableDays { get; set; } public string NextPossibleDeliveryDate { get; set; } public int DeliveryLookupPeriod { get; set; } }
2. Update the model and pass to view
ExtendedCheckoutController >
private void SetDeliveryDatesToModel(OrderOverviewModel model, List<string> deliveryDates, int deliveryCalendarLookupPeriod) { List<Date> holidays = new List<Date>(); var combindedDeliveryDatesList = new List<string>(); if (deliveryDates != null) { foreach (var item in deliveryDates) { DateTime oDate = DateTime.Parse(item); // Remove dates greater than deliveryCalendarLookupPeriod if ((oDate - DateTime.Now).TotalDays >= deliveryCalendarLookupPeriod) continue; string strDate = oDate.ToShortDateString(); combindedDeliveryDatesList.Add(strDate); // Check current date is on list holidays.Add(Date.Parse(oDate.ToShortDateString())); } ((ExtendedAdditionalInfoModel)model.AdditionalInfo).DisableDays = combindedDeliveryDatesList; } ((ExtendedAdditionalInfoModel)model.AdditionalInfo).NextPossibleDeliveryDate = GetNextPossibleDeliveryDate(holidays).ToShortDateString(); if (((ExtendedOrderManager)CommerceFrameworkBase.Orders).DeliveryCalendarLookupPeriod > 0) { // Remove one date from Lookup Period to indlude current date. ((ExtendedAdditionalInfoModel)model.AdditionalInfo).DeliveryLookupPeriod = ((ExtendedOrderManager)CommerceFrameworkBase.Orders).DeliveryCalendarLookupPeriod - 1; } }
@model AdditionalInfoModel @{ var languageFormat = System.Globalization.CultureInfo.GetCultureInfo(Shop.CommerceContext.LanguageId).DateTimeFormat.ShortDatePattern; var cultureInfo = System.Globalization.CultureInfo.GetCultureInfo(CurrentView.Shop.CommerceContext.LanguageId); var disableDays = ((ExtendedAdditionalInfoModel)Model).DisableDays; var nextPossibleDeliveryDate = ((ExtendedAdditionalInfoModel)Model).NextPossibleDeliveryDate; var deliveryLookupPeriod = ((ExtendedAdditionalInfoModel)Model).DeliveryLookupPeriod; List<string> disableDaysList = new List<string>(); var formatedNextPossibleDeliveryDate = ""; // Formate DisableDays if (disableDays != null) { foreach (var item in disableDays) { DateTime oDate = DateTime.Parse(item); string strDate = oDate.ToString(languageFormat, cultureInfo); disableDaysList.Add(strDate); } } // Formate PossibleDeliveryDate if (nextPossibleDeliveryDate != null) { DateTime oDate = DateTime.Parse(nextPossibleDeliveryDate); formatedNextPossibleDeliveryDate = oDate.ToString(languageFormat, cultureInfo); } }
get Language formate and culture info, to support Langage switch.
4.sana.datepicker.js
get the Details passed through the View from javascript
// Disable Before days to current Date. var disableBeforeDays = null; var lookupPeriod = null; if ($(".checkoutDeliveryDate").length > 0) { var deliveryLookupPeriod = $('.checkoutDeliveryDate').attr('data-deliveryLookupPeriod'); disableBeforeDays = '0'; lookupPeriod = deliveryLookupPeriod; } else { disableBeforeDays = null; } $('.datepicker').each(function () { var $self = $(this); var locale = getLocaleBasedOnCultureInfo($self); setRegional(locale); var options = $.extend({ showOn: 'both', minDate: disableBeforeDays, maxDate: lookupPeriod, onSelect: function () { $self.trigger('change').valid(); }, beforeShowDay: DisableDates }, $self.data('datepicker-options'), $self.data('datepicker-extend')); $self.datepicker(options); $self.next().attr('tabindex', '-1'); }); if ($(".checkoutDeliveryDate").length > 0) { var getDateDetails = JSON.parse($('#AdditionalInfo_DeliveryDate').attr('data-datepicker-options')); var langageFormat = getDateDetails.dateFormat; var disabledaysList = $('.checkoutDeliveryDate').attr('data-disabledays'); var nextPossibleDate = $('.checkoutDeliveryDate').attr('data-next-possible-deliverydate'); var availableDisableDateMsg = $('.checkoutDeliveryDate').attr('data-Available-DisableDate'); var unavailableDisableDateMsg = $('.checkoutDeliveryDate').attr('data-Unavailable-DisableDate'); var dates = disabledaysList; var nextPossibleDeliveryDate = nextPossibleDate; $(".datepicker").datepicker({ beforeShowDay: DisableDates, minDate: disableBeforeDays }); //Set default date as next available date. $(".datepicker").datepicker('setDate', nextPossibleDeliveryDate); } function DisableDates(date) { if ($(".checkoutDeliveryDate").length > 0) { var culture = $('.checkoutDeliveryDate').attr('data-culture-info'); var string = jQuery.datepicker.formatDate(langageFormat, date); if (dates.indexOf(string) === -1) { return [true, ""]; } else { return [false, "", unavailableDisableDateMsg]; } } else { return [true]; } } }()); $(".date-are-ovd .hasDatepicker").removeClass("hasDatepicker"); $(".date-are-ovd .datepicker").datepicker("destroy"); $(".date-are-ovd .datepicker").datepicker();