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

ajax add to cart button

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 09-13-2012, 01:18 AM
 
xcartukguy xcartukguy is offline
 

Member
  
Join Date: May 2012
Posts: 17
 

Default ajax add to cart button

Hi,

I'm trying to redevelop a skin for a shop and I wanted to change the add to cart buttons.

My issue is regarding the ajax add to cart which now doesn't work even though I'm using the original code.

Does anyone know how to initiate the javascript via an onclick even on an input/a ?

Thanks
__________________
X-Cart 4.3.1
X-Cart 4.5.4
Reply With Quote
  #2  
Old 09-13-2012, 05:09 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: ajax add to cart button

In my experience, the button has to be inside <div class="details">
If you remove the button from this div it will cease to function

Its due to this line of ajax.add2cart.js:
// Get box
this.box = this.form.parents().filter('.details,.product-cell');
__________________
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
  #3  
Old 09-13-2012, 05:13 AM
 
xcartukguy xcartukguy is offline
 

Member
  
Join Date: May 2012
Posts: 17
 

Default Re: ajax add to cart button

is there a way to activate this via an onclick event instead?
__________________
X-Cart 4.3.1
X-Cart 4.5.4
Reply With Quote
  #4  
Old 09-13-2012, 05:48 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: ajax add to cart button

Your welcome.

Assuming your form is named orderform try this:
<a href="javascript:void(0);" onclick="!ajax.widgets.add2cart(orderform)">Add To Cart</a>
__________________
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
  #5  
Old 09-14-2012, 01:09 AM
 
xcartukguy xcartukguy is offline
 

Member
  
Join Date: May 2012
Posts: 17
 

Default Re: ajax add to cart button

Quote:
Originally Posted by totaltec
Your welcome.

Assuming your form is named orderform try this:
<a href="javascript:void(0);" onclick="!ajax.widgets.add2cart(orderform)">Add To Cart</a>

That didn't work. my form is called orderform too.
__________________
X-Cart 4.3.1
X-Cart 4.5.4
Reply With Quote
  #6  
Old 09-14-2012, 06:42 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: ajax add to cart button

Well, here is a link to it working, perhaps you can inspect the source and see what is different. http://trainingpen.com/manufacturers_carousel/product.php?productid=17551 (Look right below the description)

If you provide a link to your page...
__________________
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 09-14-2012, 06:53 AM
 
xcartukguy xcartukguy is offline
 

Member
  
Join Date: May 2012
Posts: 17
 

Default Re: ajax add to cart button

Your site is still using that horrible <button><span><span> mess...
I'm trying to use an input or anchor for this.

All that should be required is the javascript that passes the information to the ajax cart and open up the popup box; surely that's a function somewhere?
__________________
X-Cart 4.3.1
X-Cart 4.5.4
Reply With Quote
  #8  
Old 09-14-2012, 07:35 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: ajax add to cart button

**Edited**
Yes, it is a function somewhere. In /common_files/js/ajax.add2cart.js on line 51:
PHP Code:
// Widget
ajax.widgets.add2cart = function(form) {
  if (!
form || typeof(form.tagName) == 'undefined' || !form.tagName || form.tagName.toUpperCase() != 'FORM')
    return 
false;

  if (!
form.add2cartWidget) {
    new 
ajax.widgets.add2cart.obj(form);
  }

  return 
form.add2cartWidget.add2cart();

You can tell this by looking at the onclick in the example I gave you.

Now, in order to further demonstrate, I have updated (temporarily!) my test site to display exactly what you want in full working order. There is a simple link with onclick to add to cart. Works with Qty and options just fine. http://trainingpen.com/manufacturers_carousel/product.php?productid=17551

**Edited**
__________________
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
  #9  
Old 09-17-2012, 02:38 AM
 
xcartukguy xcartukguy is offline
 

Member
  
Join Date: May 2012
Posts: 17
 

Default Re: ajax add to cart button

Quote:
Originally Posted by totaltec

Now, in order to further demonstrate, I have updated (temporarily!) my test site to display exactly what you want in full working order. There is a simple link with onclick to add to cart. Works with Qty and options just fine.


Thanks very much.
I have finally succeeded! I was missing a class which the javascript was looking for!

**Edited**

My next question is, how do I make the javascript reset...
the standard buttons go "Add to Cart" -> "Added" -> "Add More to Cart" I understand the button text is via smarty and javascript but I cannot reclick the link after I've clicked it once.
__________________
X-Cart 4.3.1
X-Cart 4.5.4
Reply With Quote
  #10  
Old 09-25-2012, 10:44 PM
 
Brett Forsyth Brett Forsyth is offline
 

Newbie
  
Join Date: Jun 2012
Posts: 2
 

Default Re: ajax add to cart button

I am having a similar issue. What class where you missing?
__________________
x-cart 4.5
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 12:33 PM.

   

 
X-Cart forums © 2001-2020