1. First, you must set a date attribute in the background to the pre-sale date.
2. Then retrieve the property value $ _ product-> getresource ()-> getattribute ('code')-> getfrontend ()-> getvalue ($ _ product );
A string-type time data is retrieved. You need to use the strtotime () function to convert the time into a timestamp, and then get the current time. the subtraction of the two is the countdown seconds.
3. display the countdown using JS
VaR intdiff = parseint (time); // time is the total number of seconds in the countdown function timer (intdiff) {window. setinterval (function () {var day = 0, hour = 0, minute = 0, second = 0; // default value of time if (intdiff> 0) {day = math. floor (intdiff/(60*60*24); hour = math. floor (intdiff/(60*60)-(day * 24); minute = math. floor (intdiff/60)-(day * 24*60)-(hour * 60); Second = math. floor (intdiff)-(day * 24*60*60)-(hour * 60*60)-(minute * 60);} If (minute <= 9) minute = '0' + minute; If (second <= 9) Second = '0' + second; jquery('{day_show'{.html (day + "days ,"); jquery('{hour_show'{.html ('<s id = "H"> </S>' + hour + ':'); jquery('{minute_show'{.html ('<S> </S>' + minute + ': '); jquery('{second_show'{.html (' <S> </S> '+ second); intdiff --;}, 1000);} jquery (function () {timer (intdiff );});
Magento pre-sale countdown Function