Hi Matthew,

I wanted to know if you or any other user might need the button to change status upon the expiration of the product. This would be a great add-on and would benefit the UI of the module and more user friendly.

Right now if the user/buyer/visitor went to an expired product they just won't see the button. It would be great to show a message to the user instead of just disappearing, it can be replaced by a text/image that says Sold Out, Sale Expired, Sale Now Over, etc.

Comments

aquaphenix’s picture

Assigned: Unassigned » aquaphenix

I was able to get this done by making my own uc_lto.js file and placing inside the theme folder of the site.

I added the following line to my own 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) {
        var that = $(this),
          now = new Date(),
          delta = Drupal.settings.ucLTO.expiration - now.getTime() + (now.getTimezoneOffset() * 60000);
        if (delta <= 0) {
          that.text(Drupal.t('expired')).stopTime('countdown');
          $('.node-add-to-cart').remove();
		  $('.time-left-2-buy').remove();
		  $('.node-add-to-cart-sold-out').show(); /* <-- Added this line */
        }
        else {
          that.text(Drupal.formatInterval(Math.floor(delta / 1000), Drupal.settings.ucLTO.timeGran));
          if (delta < 60000 && !that.hasClass('uc-lto-expiration-min')) {
            that.addClass('uc-lto-expiration-day').addClass('uc-lto-expiration-hour').addClass('uc-lto-expiration-min');
			that.addSpan('time');
			$('.node-add-to-cart-sold-out').remove(); /* <-- Added this line */
          }
          else if (delta < 3600000 && !that.hasClass('uc-lto-expiration-hour')) {
            that.addClass('uc-lto-expiration-day').addClass('uc-lto-expiration-hour');
			$('.node-add-to-cart-sold-out').remove(); /* <-- Added this line */
          }
          else if (delta < 86400000 && !that.hasClass('uc-lto-expiration-day')) {
            that.addClass('uc-lto-expiration-day');
			$('.node-add-to-cart-sold-out').remove(); /* <-- Added this line */
          }
        }
      });
    }

  $('body').addClass('ucLTO-processed');
  $('.node-add-to-cart-sold-out').remove();	/* <-- Added this line */
  }
};

Drupal.formatInterval = function(timestamp, granularity, langcode) {
  granularity = parseInt(granularity, 10) || 2;
  langcode = langcode || null;
  var units = [
   
    {
      'singular' : '01  ',
      'plural' : '@count  ',
      'secs' : 86400
    },   
    {
      'singular' : '  01 ',
      'plural' : '  @count ',
      'secs' : 3600
    },
    {
      'singular' : ' 01 ',
      'plural' : ' @count ',
      'secs' : 60
    },
    {
      'singular' : ' 01 ',
      'plural' : ' @count ',
      'secs' : 1
    }
  ],
    output = '';
  $.each(units, function(i, val) {
 
    if (granularity > 0) {
	
	   if(Math.floor(timestamp / val.secs)<10){	      	 
        if 	(val.secs ==1){    
		  val.plural = ' 0@count  ';
		}
		else{
		  val.plural = ' 0@count  ';
		}
	   }
	   if(Math.floor(timestamp / val.secs)==0){	      	 
		   if 	(val.secs ==1){   
		  val.plural = ' 00 ';
		}
		else{
		  val.plural = ' 00 ';
		}
	   }
          output += (output ? ' ' : '') + Drupal.formatPlural(Math.floor(timestamp / val.secs), val.singular, val.plural, {}, langcode);
      timestamp %= val.secs;
	  
      granularity--;
    }
    if (granularity === 0) {
      return false;
    }
  });
  return output ? output : Drupal.t('0 sec', {}, langcode);
};

I also added the following to my own node-product.tpl.php file

<div class="node-add-to-cart-sold-out"><?php print yourthemename_sold_out_text_function($content); ?></div>

This was also added to my template.php file

// This text is used by the UC LTO module to display instead of the buy button and its translatable
function yourthemename_sold_out_text_function(&$content){
    $content = t('Expired');
    return $content;
}

Be sure to change yourthemename_sold_out_text_function(&$content) to your actual theme name.

Given that its time of the essence to get my project done, I was able to do this temporarily. UC LTO is a good module, but needs for others to build upon it to make it better. The User Interface needs a lot of work and integration with Views is a must on the list.

haysuess’s picture

Nicely done! This was very helpful thanks!