2

I want to display timer countdown in product view page.

how to achieve this ?

2
1

you are in luck i am currently working on timer here is my code.

      <?php $end_datetime='your end date and time';
        $date =  date( "Y/m/d H:i:s",strtotime($end_datetime));   

        $endstr= date(strtotime($date));

        $nowstr = Mage::getModel('core/date')->timestamp(time());
        $now =  date('Y/m/d H:i:s', $nowstr); ?>

          <span id="countdown" class"countdown">

            <script>getTimer('<?php echo $date?>','<?php echo $now ?>')</script>

            </span>

js script

function getTimer(dt,no)
{

 var end = new Date(dt);
 var now_date= new Date(no);

    var _second = 1000;
    var _minute = _second * 60;
    var _hour = _minute * 60;
    var _day = _hour * 24;
      flag_time = true;
    timer = '';
    setInterval(function(){showRemaining();},1000);








    function showRemaining() 
    {
        var date = no;
                var now = new Date(date);
                var de= now.getTime();

                if ( flag_time ) {
                timer = de;
                }
                var d = new Date(timer);
                currentYear = d.getFullYear();
                month = d.getMonth()+1;

                var currentDate = d.getDate();
                currentDate = currentDate < 10 ? '0'+currentDate : currentDate;

                var hours = d.getHours();
                var minutes = d.getMinutes();
                var seconds = d.getSeconds();

                minutes = minutes < 10 ? '0'+minutes : minutes;
                seconds = seconds < 10 ? '0'+seconds : seconds;
                var strTime = hours + ':' + minutes+ ':' + seconds; 
                timer = timer + 1000;
               var now_time = currentYear+'/' + month+'/' + currentDate + ' ' + strTime ;











        var now = new Date(now_time);


        var distance = end - now;

        if (distance < 0) {
             if (distance>-3) 
                {
                    location.reload(true); 
                    return;
                };

            clearInterval(timer);
            document.getElementById('countdown').innerHTML = 'Completed';


            return;
        }
        var days = Math.floor(distance / _day);
        var hours = Math.floor((distance % _day) / _hour);
        var minutes = Math.floor((distance % _hour) / _minute);
        var seconds = Math.floor((distance % _minute) / _second);
       if (days <10)
        {days = '0' + days;}
    if (hours <10)
        {hours = '0' + hours;}
    if (minutes < 10)
       { minutes = '0' + minutes;}
    if (seconds < 10)
        {seconds = '0' + seconds; }
    if(days==00)
    {
                    dytext = '';   

    }
    else if(days==1)
    {
        dytext = '<span class="countdown-text">'+ days +' Day  </span>';   
    }
    else
    {
         dytext = '<span class="countdown-text">'+ days +' Days  </span>';    
    }
    if(hours==00) {
        hrtext='';
    }
    else {
        hrtext = '<span class="countdown-text">'+ hours + '</span>'+ ":";
    }
    if(minutes==00)
    {
        mintext='';
    }else {
              mintext = '<span class="countdown-text">'+ minutes +'</span>'+ ":";

    }
        sectext = '<span class="countdown-text">'+ seconds +'</span>';
        document.getElementById('countdown').innerHTML = dytext + hrtext +  mintext + sectext;
       flag_time = false;
    }


}
16
  • Is i required to replace my attribute code in your code ? or is any other changes i need to do ? – Baby in Magento May 10 '16 at 7:19
  • just add your end data and time in this variable $end_datetime='your end date and time'; – Qaisar Satti May 10 '16 at 7:21
  • i addedd like this : <?php $end_datetime='2016/06/10 12:15:15'; here click here 2nd time to open link – Baby in Magento May 10 '16 at 7:27
  • add js function too at the end of page – Qaisar Satti May 10 '16 at 7:30
  • i already added, please check. – Baby in Magento May 10 '16 at 7:30
1

I used this code to show the counter in the product page, and it works fine. I set the same code to show the counter in the list of products for a specific category, but shows only the first product while others do not show them. Is there a solution to show the counter on all the products set?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.