Magento pre-sale countdown Function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.