X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   ADD TO CART ???? (https://forum.x-cart.com/showthread.php?t=35)

CrazyLou 09-19-2002 01:53 PM

:?: I would like to have an add to cart option on the full product catagory listing or in search results.

Is this possible :?:

shan 09-19-2002 02:49 PM

I took this from the old forum. you can see it in full here --> http://mysitedesigns.com/XcartForum/viewtopic.php?t=8


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="{$smarty.get.cat}">). Then we add another hidden field to tell the script where we came from for the location.tpl (<input type=hidden name=page value="{$smarty.get.page}">). 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="{$smarty.get.cat}">
<input type=hidden name=page value="{$smarty.get.page}">
<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

All times are GMT -8. The time now is 05:25 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.