Checking the wanted or requested date on reorders - xmpie-users/uStore-js GitHub Wiki

Overview

It is possible to create a product property in uStore to allow the customer to select a date by which the product is wanted or required. The when the product is initially ordered, the property dial can validate that the selected date is in the future and within a certain date range as configured by the uStore administrator.

However, when a previous order is "reordered" the original date is prepopulated and validation is not used. So, it is possible for the order to be submitted with a "wanted date" that is in the past.

Solution

In the shopping cart page, this script will search for the value of a date control named "Wanted by date" and if the date past, it will not let the user proceed to checkout.

Alt

Prerequisites

  1. In all relevant products the field control name needs to be the same one. In this example, it is "Wanted by date" (only the W is capitalized).

  2. The fields needs to be set to "show in shipping cart".

What it does

  1. If the value of Wanted by date is in the past, the line in the shopping cart is going to say "The wanted date already passed, please edit the order".

  2. The checkout button is going to be disabled and a message will appear (in some browsers) when hovering over the button.

Note: in this script – today’s date does not count as past due.

$(document).ready(function() {
    var dateTooLate = false;
    var todaysDate = new Date().setHours(0,0,0,0);

    $(".XmpTooltipPopup:contains('Wanted by date')").each(function(ind, obj) {
        var selectedDateObj = new Date($(obj).text().split(": ")[1]);
        if ((selectedDateObj - todaysDate) < 0) // in the past
        {
            dateTooLate = true;
            $(obj).parent().find("span").after("<div style='color:red'>The wanted date already passed, please edit the order</div>");
        }
    })
    if (dateTooLate == true)
    {
        $("#ctl00_cphMainContent_BtnSubmit").attr("disabled", "disabled").attr("title" ,"Check Wanted Dates")
    }
});
⚠️ **GitHub.com Fallback** ⚠️