Page 1 of 1

"Add to Cart" button in product description

Posted: Mon Jan 14, 2013 8:14 pm
by hfinlay10
Hi,

I would like to add an "Add to Cart" button in the product description, so from the product Admin page rather than when editing the product.tpl file. Is this possible, and if so can anyone tell me the code I need?

I have tried the following (without really knowing what I am doing, I must admit), and it adds the button but throws a "page not found" error:

Code: Select all

<form action="<?php echo $action; ?>" enctype="multipart/form-data" id="product" method="post">
	<input name="quantity" size="3" type="hidden" value="1" /> <a class="button" id="add_to_cart" onclick="$('#product').submit();"><span>Add to Cart</span></a> <input name="product_id" type="hidden" value="<?php echo $products[$j]['id']; ?>" /></form>
Cheers.

Re: "Add to Cart" button in product description

Posted: Thu Jan 24, 2013 8:17 pm
by hfinlay10
Surprised no-one else has an interest in doing this too!

Re: "Add to Cart" button in product description

Posted: Thu Jan 24, 2013 11:16 pm
by granddaddy
Try this:
Where you have:
<input name="product_id" type="hidden" value="<?php echo $products[$j]['id']; ?>" />
Change it to:
<input id="product" type="hidden" value="<?php echo $products[$j]['id']; ?>" />

See if that fixes it.

Re: "Add to Cart" button in product description

Posted: Fri Jan 25, 2013 8:12 am
by hfinlay10
Hi grandaddy,

Thanks for the reply. Your suggestion made no difference--I'm still getting the page not found error.

Cheers.

Re: "Add to Cart" button in product description

Posted: Fri Jan 25, 2013 6:21 pm
by granddaddy
Here's another possibility. The category listing has quite simple buttons for 'add to cart'. The product page is a lot more complex. So, the idea is to simply copy the code from the category page and use it in the product page.
The code is:
<div class="cart"><a onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button"><span><?php echo $button_cart; ?></span></a></div>

The necessary variables appear to be available in the product.tpl. And the classes and script call are external calls anyway. I'm not in a position to test this for you, and it might possibly need some tweaking, but in theory it should work. It won't work if you have options attached to the product, and it will only add a quantity of 1, but it's a start.

This is based on code from OC 1.5.1.3. I don't know if the later versions have changed, but you could check by looking in category.tpl

Re: "Add to Cart" button in product description

Posted: Tue Feb 05, 2013 3:39 pm
by hfinlay10
Ok, thanks, I'll give that a try. :)