Post by hfinlay10 » Mon Jan 14, 2013 8:14 pm

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.

New member

Posts

Joined
Thu Apr 12, 2012 8:20 am
Location - Australia

Post by hfinlay10 » Thu Jan 24, 2013 8:17 pm

Surprised no-one else has an interest in doing this too!

New member

Posts

Joined
Thu Apr 12, 2012 8:20 am
Location - Australia

Post by granddaddy » Thu Jan 24, 2013 11:16 pm

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.

Active Member

Posts

Joined
Sat Feb 18, 2012 5:48 pm

Post by hfinlay10 » Fri Jan 25, 2013 8:12 am

Hi grandaddy,

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

Cheers.

New member

Posts

Joined
Thu Apr 12, 2012 8:20 am
Location - Australia

Post by granddaddy » Fri Jan 25, 2013 6:21 pm

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

Active Member

Posts

Joined
Sat Feb 18, 2012 5:48 pm

Post by hfinlay10 » Tue Feb 05, 2013 3:39 pm

Ok, thanks, I'll give that a try. :)

New member

Posts

Joined
Thu Apr 12, 2012 8:20 am
Location - Australia
Who is online

Users browsing this forum: Amazon [Bot], jp1077 and 73 guests