Magento Forum

   
Add to cart doesn’t work on Home Page only
 
cstreit
Jr. Member
 
Total Posts:  10
Joined:  2012-07-18
 

My add-to-cart button works fine everywhere on the website but on my home page.

I’m stumped.  The link from home page seems like it should work.  It works for other magento sites we’ve created.  ...but this one, not so much.  I took this link:  http://www.mydomain.com/magento/index.php/checkout/cart/add/product/158/qty/1/ and pasted it into the browser, no joy. 

When I look at the source of the page here is what I see:

Home Page:  (doesn’t work)

<button class="button" onclick="setLocation(’http://www.mydomain.com/magento/index.php/checkout/cart/add/product/158/qty/1/’)">
<span><span>Add to Cart</span></span>
</button>

Product Page: (works)

<button type="button" title="Add to Cart” class="button btn-cart” onclick="productAddToCartForm.submit(this)">
<span><span>Add to Cart</span></span>
</button>

Category Product Listing (works)

<button class="button" onclick="setLocation(’http://www.mydomain.com/magento/index.php/checkout/cart/add/uenc/aHR0cDovL3d3dy5tb3RvLWRlbHRhLmNvbS9tYWdlbnRvL2luZGV4LnBocC9jYXRhbG9nL2NhdGVnb3J5L3ZpZXcvcy9wZXJpcGhlcmFscy9pZC8zNC8,/product/162/form_key/vXMCwqifRVDzdm9W/’)">
<span><span>Add to Cart</span></span>

</button>

Please help!  We need to be live in 3 weeks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
BytesConsulting
Jr. Member
 
Avatar
Total Posts:  12
Joined:  2012-05-13
Manchester
 

Perhaps if you were to link to the development site in question it might help.

There is simply not enough information to say whats wrong with what you have specified.

What does your console show? Javascript errors?

Does it go somewhere ?

It is likely that it is something relatively trivial that is causing your problem - like it might have an unset mandatory field and your not displaying error messages on the home page for example.

If you require development support I do have availability. PM me with details if you like.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cstreit
Jr. Member
 
Total Posts:  10
Joined:  2012-07-18
 

Hi,

I will PM you the development site URL.

In short, pushing the \"Add to Cart\” button takes me to the cart, but the product is not added in.

Not sure what information you would need but appreciate any leads.  Not sure if this was a common issue, hoping it is!

Thanks!

Chris

 
Magento Community Magento Community
Magento Community
Magento Community
 
tdo700
Jr. Member
 
Total Posts:  2
Joined:  2013-12-12
 

i have the same problem right now.  anyone have a solution?  ive been stuck for 3 days now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cstreit
Jr. Member
 
Total Posts:  10
Joined:  2012-07-18
 

I did end up fixing it.  What I found was that in community there were at least 3 different lines of code, depending on where you were, for adding a product to a cart.  2 work.  One doesnt.

So I found them and copied one of the working ones into the non-working ones.

I’ll see if I can find it but an very short on time.  In case I don’t IIRC it was in some of the catalog/cart code and related to the button iteself.

 
Magento Community Magento Community
Magento Community
Magento Community
 
provenms
Jr. Member
 
Total Posts:  2
Joined:  2013-02-17
 

if you could point me in the right direction i would appreciate it.  thank you!

 
Magento Community Magento Community
Magento Community
Magento Community
 
cstreit
Jr. Member
 
Total Posts:  10
Joined:  2012-07-18
 

Hi.  I actually spent about 15 minutes trying to find WHERE I changed the code but struck out.  Sorry.  If you were my client I\\\\\\\’d spend a little more lol.

That said, I can tell you what I did.

I found the code that was this:

<button class=\\\\\\\"button\\\\\\\" onclick=\\\\\\\"setLocation(’http://www.mydomain.com/magento/index.php/checkout/cart/add/product/158/qty/1/’)\\\\\\\">
<span><span>Add to Cart</span></span>
</button>

and changed it to the button code that was working in the product listings.

I think if you search for the code snippets I have documented above (or the pieces of them) and then replace that section with the code from another php file that is working you should get there.  This is what I did and I\\\\\\\’m just a php hack.  ...but it worked.

Hope this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
provenms
Jr. Member
 
Total Posts:  2
Joined:  2013-02-17
 

this is kind of weird but when i disable my cache, the add to cart button works.

anyone know what the problem is?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tdo700
Jr. Member
 
Total Posts:  2
Joined:  2013-12-12
 

ok i found the files.

home page/new products
<button type=\"button\" title=\"<?php echo $this->__(\'Add to Cart\') ?>\” class=\"button btn-cart\” onclick=\"setLocation(\’<?php echo $this->getAddToCartUrl($_product) ?>\’)\"><span><span><?php echo $this->__(\'Add to Cart\') ?></span></span></button>

category page
<button type=\"button\" title=\"<?php echo $this->__(\'Add to Cart\') ?>\” class=\"button btn-cart\” onclick=\"setLocation(\’<?php echo $this->getAddToCartUrl($_product) ?>\’)\"><span><span><?php echo $this->__(\'Add to Cart\') ?></span></span></button>

Product Page
<button type=\"button\" title=\"<?php echo $buttonTitle ?>\” class=\"button btn-cart\” onclick=\"productAddToCartForm.submit(this)\"><span><span><?php echo $buttonTitle ?></span></span></button>

the code on the home page is the same as category page, but the category page works and not the home page.  anyone have any clues as to whats wrong?

Also if i disable cache the add to cart on home page works.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top