Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Age Calculation for 4.4.x

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 01-15-2012, 07:13 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Age Calculation for 4.4.x

Based on this thread from the the 4.3.x forum http://forum.x-cart.com/showthread.php?t=53578

My client now has me building another web page. Instead of calculating how old the dog is based on the day/month/year. He now wants to plug in how it will before the dogs are old enough to be delivered.

So then the customers know when the dog will be available for delivery.

I need it to say something like: "Wally will be available for delivery on 3/1/2012"

I tried plugging in this code in the product_details.tpl, but I can't get anything to display, but the Extra Field Values.
Code:
<tr> <td class="property-name">{include file="modules/Age_Calculation/age.tpl"}</td> </tr>

I added it in before
Code:
{if $config.Appearance.show_in_stock eq "Y" && $config.General.unlimited_products ne "Y" && $product.distribution eq ""}

Here's the original age.tpl

Code:
{* For http://forum.x-cart.com/showthread.php?t=53578 Call extra fields via this: {$extra_fields.0.field_value} {$extra_fields.1.field_value} {$extra_fields.2.field_value} *} <script type="text/javascript"> var dat = new Date(); var curday = dat.getDate(); var curmon = dat.getMonth()+1; var curyear = dat.getFullYear(); var calday = {$extra_fields.1.field_value}; var calmon = {$extra_fields.0.field_value}; var calyear = {$extra_fields.2.field_value}; {literal} function checkleapyear(datea) { if(datea.getYear()%4 == 0) { if(datea.getYear()% 10 != 0) { return true; } else { if(datea.getYear()% 400 == 0) return true; else return false; } } return false; } function DaysInMonth(Y, M) { with (new Date(Y, M, 1, 12)) { setDate(0); return getDate(); } } function datediff(date1, date2) { var y1 = date1.getFullYear(), m1 = date1.getMonth(), d1 = date1.getDate(), y2 = date2.getFullYear(), m2 = date2.getMonth(), d2 = date2.getDate(); if (d1 < d2) { m1--; d1 += DaysInMonth(y2, m2); } if (m1 < m2) { y1--; m1 += 12; } return [y1 - y2, m1 - m2, d1 - d2]; } function calage() { var curd = new Date(curyear,curmon-1,curday); var cald = new Date(calyear,calmon-1,calday); var diff = Date.UTC(curyear,curmon,curday,0,0,0) - Date.UTC(calyear,calmon,calday,0,0,0); var dife = datediff(curd,cald); if (dife[0]<1) { document.getElementById('dAge').innerHTML = dife[1]+" months, and "+dife[2]+" days"; } else { document.getElementById('dAge').innerHTML = dife[0]+" years, "+dife[1]+" months, and "+dife[2]+" days"; } } $(document).ready(function(){ calage(); }); {/literal} </script> <span class="puppyCust">{$product.productcode} is <span id="dAge"> not </span> old</span>
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #2  
Old 01-17-2012, 01:25 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default Re: Age Calculation for 4.4.x

Do you see the code when you view the page source? Did you see any errors in Error Console (Firefox) or Firebug Console? Those are the two places I would start.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #3  
Old 01-17-2012, 05:25 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Age Calculation for 4.4.x

Thanks Cherie, I keep forgetting about that. I'll give it try tonight.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:06 PM.

   

 
X-Cart forums © 2001-2020