Jump to content

HOW TO: Autoscroll Ajaxcart order template


Recommended Posts

Hey all, we are using the Ajaxcart order form in the new WHMCS 4.5 system, and we just modified a little bit of code to automatically scroll the page to the next input when the continue button is pressed. We did this because the way we listed our products had a pretty long height to it. So basically here are the modifications we did. BE SURE TO BACK UP YOUR AJAXCART DIRECTORY.

 

(add this to your template header.tpl underneath the jQuery link)

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
{literal}
<script type="text/javascript">			
function scrollTo(selector) {
       var targetOffset = $(selector).offset().top;
       $('html,body').animate({scrollTop: targetOffset}, 1500, 'swing');
}
{/literal}

 

(orderforms/ajaxcart/configureproductdomain.tpl)

Change:

function completedomain() {
   jQuery("#loading2").slideDown();
   jQuery.post("cart.php", 'ajax=1&a=add&pid={/literal}{$pid}{literal}&'+jQuery("#domainfrm").serialize(),
   function(data){
       if (data=='') {
           signupstep();
       } else {

           jQuery("#configcontainer2").html(data);
           jQuery("#configcontainer2").slideDown();
           jQuery("#loading2").slideUp();
       }
   });
}

 

to

 

function completedomain() {
   jQuery("#loading2").slideDown();
   jQuery.post("cart.php", 'ajax=1&a=add&pid={/literal}{$pid}{literal}&'+jQuery("#domainfrm").serialize(),
   function(data){
       if (data=='') {
           signupstep();
       } else {

           jQuery("#configcontainer2").html(data);
           jQuery("#configcontainer2").slideDown();
           [color="Red"]scrollTo('#configcontainer2');[/color]
           jQuery("#loading2").slideUp();
       }
   });
}

 

(orderforms/ajaxcart/js/main.js)

change

 

function signupstep() {
   jQuery.post("cart.php", 'a=checkout&ajax=1',
   function(data){
       jQuery("#signupcontainer").html(data);
       jQuery("#signupcontainer").slideDown(); 
       jQuery("#prodconfloading").slideUp();
       jQuery("#domainconfloading").slideUp();
   });
}

 

to

 

function signupstep() {
   jQuery.post("cart.php", 'a=checkout&ajax=1',
   function(data){
       jQuery("#signupcontainer").html(data);
       jQuery("#signupcontainer").slideDown();
      [color="Red"] scrollTo('#signupcontainer');[/color]
       jQuery("#prodconfloading").slideUp();
       jQuery("#domainconfloading").slideUp();
   });
}

 

and change

 

function selectproduct(pid) {
   jQuery("#loading1").slideDown();
   jQuery("#configcontainer1").fadeOut();
   jQuery("#configcontainer2").fadeOut();
   jQuery("#configcontainer3").fadeOut();
   jQuery("#signupcontainer").fadeOut();
   jQuery.post("cart.php", 'ajax=1&a=add&pid='+pid,
   function(data){
       if (data=='') {
           signupstep();
       } else {
           jQuery("#configcontainer1").html(data);
           jQuery("#configcontainer1").slideDown();
       }
       jQuery("#loading1").slideUp();
       recalcsummary();
   });
}

 

to

 

function selectproduct(pid) {
   jQuery("#loading1").slideDown();
   jQuery("#configcontainer1").fadeOut();
   jQuery("#configcontainer2").fadeOut();
   jQuery("#configcontainer3").fadeOut();
   jQuery("#signupcontainer").fadeOut();
   jQuery.post("cart.php", 'ajax=1&a=add&pid='+pid,
   function(data){
       if (data=='') {
           signupstep();
       } else {
           jQuery("#configcontainer1").html(data);
           jQuery("#configcontainer1").slideDown();
[color="Red"]	    scrollTo('#configcontainer1');[/color]
       }
       jQuery("#loading1").slideUp();
       recalcsummary();
   });
}

 

Now if your screen resolution is high enough, you won't see the change, but if you look at your page on a laptop, or actually change your resolution to let's say 800 x 600, then you'll see the difference. If you have any questions, let me know! Hope this helps out some people, just a nice useful effect.

Link to comment
Share on other sites

  • 2 weeks later...

Thanks, seems to work nice! :)

 

But there is a little mistake in your code

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
{literal}
<script type="text/javascript">			
function scrollTo(selector) {
       var targetOffset = $(selector).offset().top;
       $('html,body').animate({scrollTop: targetOffset}, 1500, 'swing');
}
{/literal}

 

change to

 

{literal}
<script type="text/javascript">			
function scrollTo(selector) {
       var targetOffset = $(selector).offset().top;
       $('html,body').animate({scrollTop: targetOffset}, 1500, 'swing');
}
</script>
{/literal}

 

</script>

was missing.

Link to comment
Share on other sites

This is good. I wish someone would do something like this for the slider cart. Customers click to search for a domain and have to scroll up to see the results (which isn't obvious) and when they click continue they have to scroll down the page, which again isn't obvious. Deal breaker issues for many sales I fear.

Link to comment
Share on other sites

  • 3 weeks later...

I was trying to look for this post to see if anyone had problems, sorry, I forgot to add the </script> at the end.. lol

 

I am going to look into the slider thing, because we actually moved from the ajax order form to the slider, and I will be adding some features to it. Once I get it nailed, I will definitely post something on here.

 

 

Thanks for reading!

Link to comment
Share on other sites

Hi,

I implemented the modifications you mentioned and it seemed to work - but for some reason the pages no longer auto-scroll to the next configurable section.

 

Anyone else seeing this with the ajaxcart ? I really need this to work due to order changes made on the site for customers.

 

Si

Link to comment
Share on other sites

Hi,

I implemented the modifications you mentioned and it seemed to work - but for some reason the pages no longer auto-scroll to the next configurable section.

 

Anyone else seeing this with the ajaxcart ? I really need this to work due to order changes made on the site for customers.

 

Si

 

What is the URL to your page, so I can check it out.

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated