I am use active javascript as countdown, it work fine in home page with tease view, but jump to the node page, countdown is broken.

Comments

WebNewCastle’s picture

Will you describe further in what way it doesn't work?

iSheng’s picture

at the node page with LTO, it show up Expires time correct at the very begining, then Expires in time jump to 0 immediately.

WebNewCastle’s picture

This is confusing if the issue is on the full node view. Do you have a URL you feel comfortable posting? I don't have the bandwidth to try to help troubleshoot this week, but I can try to do so soon.

vidichannel’s picture

I have same problem here had to put it back to the non-counting version.

Flashes for a second on the countdown clock and goes straight to 0. I played with switching the JS source to my theme folder, but it made no difference. Also tried to remove it from the Catalog; no change. I am using Boost.

Expires in:
0 sec

WebNewCastle’s picture

Hi,

Thanks for the report and information. So given the "flash" and that you've tried different JS files, there's something in the main part of the JS that is conflicting. Unfortunately, that could probably be a considerable number of things. And I don't know if using Boost is a conflict with this - I thought I had tested this on a site with Boost installed, but I'll have to double check on that.

When you were working on this, were there a variety of expiration times that you tried? And are you using user configurable timezones on the site?

- Matt

gakshay’s picture

Having the same problem but in only occurs when there are more than one Active Expiration Timers on single page view => then it renders 0sec.

If the page view is having single Active Countdown timer on a single node (with all other content having Active Countdown = False) then it works fine...What shall be the fix in former case??

WebNewCastle’s picture

Currently, that it doesn't display correctly where there is more than one timer on a page is "as designed". Not in the sense that such was the goal, but in the sense that the way the Javascript is put together it would get confused by more than one timer on a page.

So really this is an aspect that needs to be improved when it works out to have a completely different javascript mechanism for the module - which is a goal that hasn't quite reached the point of a "schedule and plan of action".

vidichannel’s picture

I have only one and still have the issue

andrews501’s picture

VidiChannel,

Check this link, I was having the same problem and solved it.

http://drupal.org/node/821260#comment-3611722

arski’s picture

Hey guys, just a hint - I was having similar issue when trying to add the countdown timer to a block that gets displayed on the same page as the actual product node. The problem turned out to be that the LTO JS settings were set twice.

What helps is to check the source of your page and look for a line like jQuery.extend(Drupal.settings in the very beginning.. then look to the right and you should see something like "ucLTO": { "expiration": 1288946820,. If instead of a proper timestamp you're seeing something like "expiration": [ 1288946820 , 1288946820 ], or if you're not seeing those settings at all, then that's a good debugging start already :)

Cheers

vidichannel’s picture

Here is a fix that worked for me. In line 374 of uc_lto.module change the "LTO" to lower case. Also works for number 9 above without having to add the path name for the theme.

if ($open && !$teaser && $node->lto_type == 9) {
drupal_add_js(array(
--- Original Code: 'ucLTO'
+++ 'uclto' => array(
'expiration' => $node->expiration + variable_get('date_default_timezone', 0),
'timeGran' => intval(variable_get('uc_lto_time_gran', 2)),
'doCountdown' => TRUE,
),
), 'setting');

WebNewCastle’s picture

Very peculiar.

I'm glad to hear it's working for you, and thanks for taking the time to post again. At the moment, I don't quite understand why that made a difference, but it certainly isn't an issue to patch the module if this is going to work for more people.

I still want to explore changing the javacript overall, hopefully in a couple weeks.

If anyone else tries this and finds it solves an issue, please post as well. Thanks!

- Matt

vidichannel’s picture

Rather bizarre solution, I admit. I was guessing it must have been an issue for how the variable was defined originally. Just to provide platform specifics, I am running Windows Server 2008R2 and IIS. Since many are running Linux and Apache this may suggest some hint. From my experience this case-sensitive conclusion seems quite backward since Linux tends to be more case-sensitive than Windows, but it seems to work. The code issues are over my head.

Thanks for a great module.

WebNewCastle’s picture

Wow, I'm confused because I could have sworn I circled back and responded to this. Thanks again, and yes, that does seem weird as I would have guessed the same thing in regards to platforms and case sensitivity.

seancorrales’s picture

I was battling with this some and have some information to share.

As someone else pointed out, the case here is the JS variables are getting set under drupal.settings more than once. The result is the settings look like

"expiration": [ 1294419600, 1294419600 ], "timeGran": [ 3, 3 ], "doCountdown": [ true, true ]

When the calculation is attempted on the expiration date, the "," and space cause an error resulting in a NaN JS error henceforth the "0 Secs" error that everyone is getting.

The error seems to specifically tie back to this function in the module file: uc_lto_status_form(). This function adds the JS. I put in some statements to see when this function was being called and, sure enough, it was being called twice.

In my case, I have a single product being loaded twice because it's in separate views so I suspect that's part of my problem. That being said, going to the individual product page produces three calls to the function instead of two.

I'm currently working on a solution to be sure that these items aren't inserted multiple times. I'll post my solution back here if it's worth sharing.

ktleow’s picture

I think I may have a fix for the 0 sec countdown bug.

Let me know if this works for you guys. Its basically a dirty hack to rely on form ID of the countdown and look for the correct index in expiration settings array.

Edit uc_lto.js file:

/**
 * Start and control the LTO countdown timer.
 */
Drupal.behaviors.ucLTO = function(context) {
  if (!$('body').hasClass('ucLTO-processed')) {
    //Drupal.settings.ucLTO.expiration *= 1000;
  
    if (Drupal.settings.ucLTO.doCountdown) {
      $('.uc-lto-expiration').everyTime(1000, 'countdown', function(i) {

        // BEGIN: Added by ktleow, fix multiple timer bug
        var formId = $(this).parents('form').attr('id');
        formId = formId.replace('uc-lto-status-form', '');
        formId = formId.replace('-', '')
        if (formId == '') {
          formId = 0;
        }
        var expirationSettings = Drupal.settings.ucLTO.expiration;
        var expiration = '';
        if (typeof expirationSettings.length != 'undefined') {
          expiration = expirationSettings[formId];
        }
        else {
          expiration = expirationSettings;
        }
        expiration *= 1000;
        // END: Added by ktleow, fix multiple timer bug

        var that = $(this),
          now = new Date(),
          delta = (expiration) - now.getTime() + (now.getTimezoneOffset() * 60000);
        if (delta <= 0) {
          that.text(Drupal.t('expired')).stopTime('countdown');
          $('.node-add-to-cart').remove();
        }
        else {
          that.text(Drupal.formatInterval(Math.floor(delta / 1000), Drupal.settings.ucLTO.timeGran));
          if (delta < 60000 && !that.hasClass('uc-lto-expiration-min')) {
            that.removeClass('uc-lto-expiration-day').removeClass('uc-lto-expiration-hour').addClass('uc-lto-expiration-min');
          }
          else if (delta < 3600000 && !that.hasClass('uc-lto-expiration-hour')) {
            that.removeClass('uc-lto-expiration-day').addClass('uc-lto-expiration-hour');
          }
          else if (delta < 86400000 && !that.hasClass('uc-lto-expiration-day')) {
            that.addClass('uc-lto-expiration-day');
          }
        }
      });
    }

  $('body').addClass('ucLTO-processed');
  }
};

But there MAY be a situation whereby the order of the expiration settings is different from the form IDs.

Feel free to use it, improvise and post here your solution if you have a better one.

ktleow’s picture

Ok I posted my solution too soon.

It doesnt work when a product has expired.

Will find a workaround and share here.

ktleow’s picture

Anyone who needs a quick fix:

Look at uc_lto.module function uc_lto_status_form()

  //if ($open && !$teaser && $node->lto_type == 9) {
    drupal_add_js(array(
      'ucLTO' => array(
         'expiration' => $node->expiration + variable_get('date_default_timezone', 0),
         'timeGran' => intval(variable_get('uc_lto_time_gran', 2)),
         'doCountdown' => TRUE,
      ),
    ), 'setting');
    drupal_add_js(drupal_get_path('module', 'uc_lto') . '/uc_lto_timers.js', 'module');

    $check_js_style = variable_get('uc_lto_js_style', '1');
    if ($check_js_style == 1) {
      drupal_add_js(drupal_get_path('module', 'uc_lto') . '/uc_lto.js', 'module');
    } 
    else {
      global $theme_key;
      drupal_add_js(drupal_get_path('theme', $theme_key) . '/' . variable_get('uc_lto_js_custom_path', FALSE));
    }
  //}

Just follow what I did and uncomment the if-else condition.

Because my previous workaround editing the JS relies on the array indexes, what this does is simply output the expiration timestamp even though the product has already expired.

WebNewCastle’s picture

Hi Everyone,

Sorry for the delay and thank you to all of you who have posted information.

I can work on making updates, but I'm at a bit of a fork in the road as I try to set aside time in 2011 to catch up. Primarily, I think the entire Javascript mechanism right now is too limited both for tackling a few issues and extending further for feature requests. One of the primary issues I've seen is language/translation related.

I think the entire mechanism actually just needs to be re-written entirely. I'll post further when I sit down and have thought through this further. I've drastically slowed down the number of projects I'm accepting, so I'm hoping this will allow some more time for contributed module development.

- Matt

beautifulmind’s picture

My issue was little different, I was not able to get the count down timer working on the node teasers, so I followed #18 and re-wrtitten the condition as
if ($open && $node->lto_type == 9) {

And that worked for me.

I really appreciate posting your solutions here.

Thank you very much.

Regards.

brian brovelli’s picture

I achieved this by simply changing JS Style from Default to custom at /admin/store/settings/lto. No other changes.

lynx1976’s picture

Hi folks! I had the same problem during last days.. I fixed (temporary) downloading and installing jQuery countdown module and changing a bit the function theme_uc_lto_status into the .module file like this:

function theme_uc_lto_status($form) {
  	
  #drupal_add_css(drupal_get_path('module', 'uc_lto') . '/uc_lto.css');
  $mytime=format_date($form['nid']['#exp'], 'custom', 'F d, Y g:i a', $langcode='en');
  $rows=theme('jquery_countdown', array(
			'until' => $mytime,
			'description' => t('to the expiration'),
  		));
  /*$rows = "<div class='uc-lto-expiration-wrapper'>";
  $rows .= "<div class='uc-lto-expiration-label'>";
  $rows .= $form['expiration']['#title']; 
  $rows .= "</div><div class='uc-lto-expiration'>"; 
  $rows .= "</div></div>";*/
  return $rows;
}

and adding a variable into $form array:

/**
 * Form embedded into node to display expiration status.
 */
function uc_lto_status_form(&$form_state, $node, $teaser) {
  $form = array(
    '#node' => $node,
    '#teaser' => $teaser,
    '#theme' => 'uc_lto_status',
    'nid' => array(
      '#type' => 'value',
      '#value' => $node->nid,
      '#exp' => $node->expiration, // new item
    ),
  );

Seems it works succesfully.
Anyway I am waiting for a cleanest solution.

roman_l’s picture

Thanks lynx1976!

#22 makes the JS countdown work, but with the code above it displays "NaN" (not a number) in the countdown div.

Just had to edit a few lines and all is ok with D6 / Ubercart 2.4 / uc_lto 6.x-1.1

<?php
function theme_uc_lto_status($form) {
     
  #drupal_add_css(drupal_get_path('module', 'uc_lto') . '/uc_lto.css');
  $mytime= $form['nid']['#exp'];
  $mytime2 = $mytime - time(); // seconds left to feed jquery_countdown
  $mytime3 = date( 'd-m-Y H:i:s', $mytime ); // 'Expires on ' date format
  
  $rows=theme('jquery_countdown', array(
            'until' => $mytime2, //we take the time left
            'description' => t('to the expiration'),
          ));
  /*$rows = "<div class='uc-lto-expiration-wrapper'>";
  $rows .= "<div class='uc-lto-expiration-label'>";
  $rows .= $form['expiration']['#title'];
  $rows .= "</div><div class='uc-lto-expiration'>";
  $rows .= "</div></div>";*/
  return 'Expires le: '.$mytime3.' '.$rows;
}
?>
jasonabc’s picture

The fix in #21 worked for me. Thanks!