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

jQuery mod on Xcart (countdown for special offers)

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 04-27-2012, 08:14 AM
 
ricardomz ricardomz is offline
 

Senior Member
  
Join Date: Jun 2007
Posts: 111
 

Smile jQuery mod on Xcart (countdown for special offers)

Dear friends,

I did a modification on store/skin/common_files/customer/service_head.tpl to include a counter for products with disccount.. The idea is that when the customer open a product with a special offer avilable the page shows a countdown and the user can buy that product on the desired time. For this mod I also change store/skin/common_files/customer/main/product.tpl

The modification using PHP is ready, and the countdown is a jQuery script I bought on codecanyon. But the issue is that when I'm include the jQuery files on the .tpl the javascript code doesnt work properly. In fact it seems that it doesnt recognize the divs to show the countdown. I did the same modification on a litecommerce store and it works properly.

Do you have some ideas or is a known issue that jQuery can not be included on the .tpl files of X-cart??..

Let me show you the code:

store/skin/common_files/customer/service_head.tpl
PHP Code:
{php}
        
session_start();
        
$_SESSION['bandera']=1;
        
//$bandera=1;
if(isset($_GET['productid'])){
    
$id_contador=$_GET['productid'];
    
$conexion = new MySQLi("...","...","...","...");
    
$sql="SELECT conditionid, param_id FROM xcart_offer_condition_params WHERE param_id LIKE '$id_contador'";
    
$resultado=$conexion->query($sql);
    if(
$resultado->num_rows0){
        
$parametro=$resultado->fetch_array();
        
$condicion=$parametro[0];
        
$resultado->close();
        
$sql="SELECT conditionid, offerid, avail FROM xcart_offer_conditions WHERE conditionid LIKE '$condicion'";
        if(
$resultado_dos=$conexion->query($sql)){
            
$oferta=$resultado_dos->fetch_array();
            
$ofer=$oferta[1];
            
$resultado_dos->close();
            
$sql="SELECT offerid, offer_end FROM xcart_offers WHERE offerid LIKE '$ofer'";
            
            if(
$resultado_tres=$conexion->query($sql)){
                
$termina=$resultado_tres->fetch_array();
                
$fec=date("d/m/y",$termina[1]);
                
$fecha explode("/"$fec);
                
$resultado_tres->close();
                }else{
                    echo 
"error en tercer if";
                    }
        
            
            
            }else{
                echo 
"error en el segundo if";
                }
                    }else{
                        
$_SESSION['bandera']=0;
                        
//echo "error en el primer if";
                        
}
     
$conexion->close();            
    
    }else{
        
$_SESSION['bandera']=0;
        
        }

        
      {/
php}
    
    {
php}
    
$actual=time();
    if(
$_SESSION['bandera']==&& $termina[1]>$actual){
    {/
php}
    
        {
literal}
       <
script type="text/javascript">
        $(function(){
        $(
"#test").fliptimer({year:20{/literal}{php} echo $fecha[2]; {/php}{literal},month:{/literal}{php} echo $fecha[1]; {/php}{literal},days:{/literal}{php} echo $fecha[0]; {/php}{literal},hours:0,minutes:0});
        });
        </
script>
        {/
literal}
        
    
    {
php} }else{ {/php}
        
        {
literal}
        <
script type="text/javascript">
        
document.counter_tlapalero.style.display="none";
        </
script>
        {/
literal}
        

    {
php} } {/php}
    
    <
script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <
link rel="stylesheet" type="text/css" href="http://www.mysite.com/catalogo/assets/css/flip.css" />
    <
script type="text/javascript"  src="http://www.mysite.com/catalogo/assets/js/fliptimer.js"></script>
    {* 
        
// Termina codigo para instalacion del contador ////////////////////////
     
*} 

store/skin/common_files/customer/main/product.tpl

Here is the div #test where the countdown have to be loaded.
PHP Code:
{php}
    
$actual=time();
    if(
$_SESSION['bandera']==1){
    {/
php}
              <!--
countdown -->
     
             <
div id="counter_tlapalero" >
                <
div id="test"> </div>
             </
div>
    
            <!--/
coutdown -->
            
    {
php} } {/php

Hope someone could helpme!!.. I need to get this mod asap.

Regards
__________________
X-Cart 4.5.5
Litecommerce Version: 2.2.45
MИxico
Reply With Quote
  #2  
Old 04-27-2012, 09:26 AM
 
ricardomz ricardomz is offline
 

Senior Member
  
Join Date: Jun 2007
Posts: 111
 

Default Re: jQuery mod on Xcart (countdown for special offers)

S.o.s.
__________________
X-Cart 4.5.5
Litecommerce Version: 2.2.45
MИxico
Reply With Quote
  #3  
Old 04-27-2012, 10:16 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: jQuery mod on Xcart (countdown for special offers)

Don't use {php} in template files - not a good practice.
What are you trying to accomplish with the second piece of code? The php code there will not do anything - the div will still show just the way you have it - empty. The first part posted is similar
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #4  
Old 04-27-2012, 10:42 AM
 
ricardomz ricardomz is offline
 

Senior Member
  
Join Date: Jun 2007
Posts: 111
 

Default Re: jQuery mod on Xcart (countdown for special offers)

Steve thanks for your reply,

The second part of the code shows the div whether the product has special offer or not. That's the idea. Initially I tried using css but it doesn't work...

And yes, I know that use {php} is not a good practice but by the moment I need to get this done asap. The issue is that the countdown it simply does'nt work. I don't know exactly if the jQuery library <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> casuses conflict with X-cart.


__________________
X-Cart 4.5.5
Litecommerce Version: 2.2.45
MИxico
Reply With Quote
  #5  
Old 04-27-2012, 11:10 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: jQuery mod on Xcart (countdown for special offers)

<!--countdown -->

<
div id="counter_tlapalero" >
<
div id="test"> </div>
</
div>

<!--/
coutdown -->

will load no matter what you have in the {php} since this code is not part of the {php} code but part of the template. And since you are using similar code in the first part there is nothing to load - the php 'if/else' you are putting out there will not do anything for the template - you have the html code as part of the template not as part of the php code
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #6  
Old 04-29-2012, 04:15 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: jQuery mod on Xcart (countdown for special offers)

You shouldn't be including the jquery library, jquery is used in current versions of X-cart already. I suspect you are including jquery twice.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #7  
Old 04-30-2012, 06:38 AM
 
ricardomz ricardomz is offline
 

Senior Member
  
Join Date: Jun 2007
Posts: 111
 

Default Re: jQuery mod on Xcart (countdown for special offers)

Mike

Thanks for your reply.. I'm not an expert on jQuery, thats the reason why I buy the countdown. I just have a question. It doesnt matter the jQuery version I load??. The gallery will always works?.

Thankyou!!
__________________
X-Cart 4.5.5
Litecommerce Version: 2.2.45
MИxico
Reply With Quote
  #8  
Old 04-30-2012, 06:46 AM
 
ricardomz ricardomz is offline
 

Senior Member
  
Join Date: Jun 2007
Posts: 111
 

Default Re: jQuery mod on Xcart (countdown for special offers)

Mike I've remove the line where I load jQuery and the issue is the same. The contdown it doesnt work.
__________________
X-Cart 4.5.5
Litecommerce Version: 2.2.45
MИxico
Reply With Quote
  #9  
Old 04-30-2012, 08:05 AM
 
ricardomz ricardomz is offline
 

Senior Member
  
Join Date: Jun 2007
Posts: 111
 

Default Re: jQuery mod on Xcart (countdown for special offers)

Hey.. I found the error. If I remove the line <script type="text/javascript" src="http://store.com/var/cache/_c036329c826190c5a2b1124219029131.js"></script> where X-cart loads jQuery I mean, the count down works properly.

At the same time I need to load
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

What do you recommend me to do?.. Could somebody helpme?

Regards!!
__________________
X-Cart 4.5.5
Litecommerce Version: 2.2.45
MИxico
Reply With Quote
  #10  
Old 04-30-2012, 08:34 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: jQuery mod on Xcart (countdown for special offers)

Do not remove the line with the cached file - all js code needed for the cart to function is in there. You can try to turn off the Spped up tools in admin settings and see if it works. If XC loads jQuery version lower than the one required by your plugin then it will not work. You may need to replace it with your jQuery call
__________________
Steve Stoyanov
CFLSystems.com
Web Development
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 04:57 AM.

   

 
X-Cart forums © 2001-2020