View Single Post
Old 09-19-2002, 02:49 PM
  shan's Avatar 
shan shan is offline

Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163


I took this from the old forum. you can see it in full here -->

It isn't as hard as it sounds to add a button (or text link) to the /customer/main/products.tpl (Product Listing) so a customer can add a product to their cart without having to first view it in greater detail.

First thing we need to do is figure out how the /customer/main/product.tpl (Product Detail) is calling the add to cart. Once we know that we can put the Add To Cart in the Product Listing page any which way we like.

In the Product Detail page I see we need a form tag (<form name=orderform method=post action="cart.php?mode=add">). We also will need to assume the customer only wants one of that item, for simplicity's sake, so we create a hidden form field indicating that (<input type=hidden name=amount value=1>). I don't see the point of redundancy, but for the sake of arguement let's go ahead and reitterate to the PHP script what mode we want for the cart (<input type=hidden name=mode value=add>).

Now for the fun part. We need to tell the cart which item to add (<input type=hidden name=productid value="{$products[product].productid}">) and from which category it is in (<input type=hidden name=cat value="{$}">). Then we add another hidden field to tell the script where we came from for the location.tpl (<input type=hidden name=page value="{$}">). The second to last thing we do is add the button (or text or whatever) so the user can just click it from the Product Listing page ({include file="buttons/add_to_cart.tpl"}). The final thing of course is to close the form (</form>).

Your form should look like this as a minimum:

<form name=orderform method=post action="cart.php?mode=add">
<input type=hidden name=amount value=1>
<input type=hidden name=mode value=add>
<input type=hidden name=productid value="{$products[product].productid}">
<input type=hidden name=cat value="{$}">
<input type=hidden name=page value="{$}">
<a href="javascript: orderform.submit()">
{include file="buttons/add_to_cart.tpl"}</a>

This should be sufficient for adding an Add To Cart button/link to the Product Listing. Hopefully this will clear up alot of the questions going around about this. If you need any further help then please let me know, I will help where I can.

- Ken

* Note: This has been edited from the original post to reflect the correct code to create an Add To Cart button to your Product Listing page. *

Last edited by eclipsboi on Mon Sep 02, 2002 3:42 am, edited 1 time in total

Hope that helps
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote