X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Add to cart button on product listing (https://forum.x-cart.com/showthread.php?t=816)

funkydunk 11-28-2002 10:48 PM

Add to cart button on product listing
 
Just wanting to do what it says - in the main product list, I would like an add to cart button rather than having to click on see details before doing this.

Has anyone done this already before I try and figure it out?

Cheers

leed 11-29-2002 01:27 PM

FD

We did ours this way. Here is the code for our products.tpl (skin1/customer/main). As our products show in 2 columns, 2 rows, so you may have to juggle around with the placement of the code (form/endform>) to get it to work.

Good Luck

LeeD
Code:

{* $Id: products.tpl,v 1.16 2002/09/25 10:12:05 zorg Exp $ *}

<table border=0 width=100%><tr><td>

  <table border=0 width=100%>

{section name=product loop=$products}

{if $smarty.section.product.index is div by 2}
    </tr><tr valign="top">
  {/if}

  <td valign="top">

<table border=0 width=100%>
<tr><td width=90 align=center valign=top>
<a href=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}>{include file="product_thumbnail.tpl" productid=$products[product].productid image_x=70 product=$products[product].product}
{ $lng.lbl_see_details }</a>
</td>
<td valign=top>
{$products[product].productcode | escape} - {$products[product].product|escape}</font> <font class=TableCenterProductTitleOrange></font>
<font size=1>




{$products[product].descr|truncate:300:"...":true}


</font>
<hr size=1 noshade width=230 align=left>
{if $active_modules.Subscriptions ne "" and $products[product].catalogprice}
{include file="modules/Subscriptions/subscription_info_inlist.tpl"}
{else}
{if $products[product].price ne 0}
{if $products[product].discount ne 0}
<font class=MarketPrice>{$lng.lbl_market_price}: <s>{math equation="(price/(100-discount))*100" price=$products[product].price discount=$products[product].discount format="%d.00" assign=unformatted}{include file="currency.tpl" value=$unformatted}</s></font>

{/if}
<font class=TableCenterProductTitleOrange>{$lng.lbl_our_price}: {include file="currency.tpl" value=$products[product].price}</font><font class=MarketPrice>{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$products[product].price}</font>{if $products[product].discount ne 0}, save {$products[product].discount}%{/if}
{else}
<font class=TableCenterProductTitleOrange>{$lng.lbl_enter_your_price}</font>
{/if}
{/if}
</td>
<tr><td>
[b]<form name=orderform_{%product.index%} method=post action="cart.php?mode=add">
<td align=left> <a href="javascript: document.orderform_{%product.index%}.submit[/i]()">
{include file="buttons/add_to_cart.tpl"}</a>
<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=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}>{include
file="buttons/moreinfo.tpl"}</a>
</td>
</form>[/b]
</td>
</tr>

</tr>
</table>
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
</tr>
</table>






</td>

{/section}
</td></tr></table>
</td></tr></table> [b][/b]


leed 11-29-2002 01:28 PM

Ooops ..just noticed a [/i] in the 2nd line of bold code....remove it ..

funkydunk 11-29-2002 10:58 PM

Presumeably the morinfo.tpl is a button template that you have created?

Will try this - thanks.

leed 11-30-2002 03:34 AM

yep it is ..you can just ignore it

funkydunk 11-30-2002 11:10 AM

Perfect - work a treat

cheers

John7 01-11-2003 02:44 PM

Okay I've installed this script to ad item to cart from product listing and it works like a charm.

But one small problem. I also need to have the color selections display on the product listing page with the ad item to cart button.

Thanks

John

FishBookStore 01-11-2003 07:25 PM

In Stock?
 
You should check to see if it is in stock before displaying the Add to Cart button.

John7 01-11-2003 09:28 PM

Actually you see its the code itself. I think it needs to be modified to be able to do more than just display the ad buttom it needs to display the choice of which color.

Do you understand?

mgraffix 01-14-2003 09:44 PM

LeeD, Just wanted to say thanks, I was looking for help with something else, came across this, - a little cutting and pasting, and Wa La, it works like a charm. :lol:

Blackhawk 01-15-2003 06:30 AM

Thanks
 
This code took 2 items of my TODO list at one time!! Thanks LeeD!!

John7 01-15-2003 04:49 PM

Okay I'm gonna start a new thread with my question then.

movienett 02-17-2003 03:08 PM

would anyone be so kind and paste in the code for 3 columns layout ?

thx !!!

ajaycg 03-07-2003 04:08 AM

fantastic, but one slight bug??;o(
 
Hi LeeD

I've implemented the addtocart to show up in the main product list, however whenever I press the addtocart for the first top most product listed, I get an error and it doesn't work, however it works for all the products that follow beneath it.

Any ideas?

I tried it in Netscape and it works fine..

the url for the first product is document.orderform_0.submit

is it something to do with it being Zero?

Cheers

Aj..

machnhed1 03-07-2003 05:48 AM

Excellent Work
 
leed,

Just wanted to say thanks for the great code. It worked like a charm, kudos to you.

P.S. - You can edit your original post to remove the [/i] so that it doesn't keep tripping people up. Then just delete your "Oops..." post.

aussib 03-08-2003 08:47 PM

Thanks for this code :) I changed it slightly for people who only want one product per row....

Quote:

{* $Id: products.tpl,v 1.21.2.1 2003/01/20 12:57:59 svowl Exp $ *}
{section name=product loop=$products}
<table border=0 width=100%>
<tr><td width=90 align=center valign=top>
<a href=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}>{in clude

file="product_thumbnail.tpl" productid=$products[product].productid image_x=70

product=$products[product].product}
{$lng.lbl_see_details}</a>
</td>
<td valign=top>
{$products[product].product|escape}</font>
<font size=1>




{$products[product].descr|truncate:300:"...":true}


</font>
<hr size=1 noshade width=230 align=left>
{if $active_modules.Subscriptions ne "" and $products[product].catalogprice}
{include file="modules/Subscriptions/subscription_info_inlist.tpl"}
{else}
{if $products[product].price ne 0}
{if $products[product].discount ne 0}
<font class=MarketPrice>{$lng.lbl_market_price}: <s>
{math equation="price/(1-(discount/100))" price=$products[product].price discount=$products[product].discount

format="%d.00" assign=unformatted}{include file="currency.tpl" value=$unformatted}
</s></font>

{/if}
<font class=ProductPrice>{$lng.lbl_our_price}: {include file="currency.tpl"

value=$products[product].price}</font><font class=MarketPrice>{include

file="customer/main/alter_currency_value.tpl" alter_currency_value=$products[product].price}</font>{if

$products[product].discount ne 0}, save {$products[product].discount}%{/if}{if $config.General.use_vat eq "Y"},

{$lng.lbl_including_vat} {$products[product].vat}%{/if}
{else}
<font class=ProductPrice>{$lng.lbl_enter_your_price}</font>
{/if}
{/if}


</td></tr>
<tr><td>
<form name=orderform_{%product.index%} method=post action="cart.php?mode=add">
<td align=left> <a href="javascript: document.orderform_{%product.index%}.submit()">
{include file="buttons/add_to_cart.tpl"}</a>
<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=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}>Mor e info...</a>
</td>
</form>

</td>
</tr>

</table>






{/section}

Works a treat ;)

ajaycg 03-09-2003 01:48 AM

1st item in list to cart
 
Hi Aussieb

Cheers for that.. much cleaner than I one I fudged, Im still getting the same problem though, I cant seem to add the first item, comes up with error, it doesnt submit, yet all the ones below all add to cart perfectly.

Any ideas..

Cheers

-Aj..

aussib 04-06-2003 12:32 AM

sorry I can't be of help - I didn't have that problem when I made the change - all products were working fine.,
I have actually just done a total re install so am back to square one myself - teach me for hurrying and not making backup copies won't it?! ;)

aussib 04-06-2003 05:14 AM

ok - I have added this code again and I am not not sure what you mean. Do you mean the first listed product won't add? Mine will so not sure what the prob you are having is?
I have tested all the products on all the pages and they work a treat?

Is it skin1/customer/main/products.tpl that you changed?

ajaycg 04-06-2003 07:51 AM

Hey, cheers for responding.

I blew away the db, reimported, and it works fine now.. bizarre!!!

thanks matey

Aj..

poboy 04-06-2003 09:48 AM

Worked good, but my permissions?
 
I am having trouble with my permissions. When I implemented the new products.tpl, the buttons were on there, but when I clicked add to cart, it said access denied, you do not have permission, what folder should I set to what permissions?

aussib 04-10-2003 06:19 AM

Is this happening on the live site? Not sure what you mean - but all the permissions needed are listed in the read me files etc. I don't want to tell you what to do cos I am bad with setting wrong permissions then having to reset them ;)

YuriC 05-27-2003 09:15 AM

How about "remove from cart" button
 
Anyone has an idea how to do it?

I'm making a mod that will display a list of products in the cart right underneath the cart image as such: (2) Product Name ... and when u press add/remove the number inside of parentesis will increase/decrease...


so anyone got remove function.. i'd appreciate if you share (i'll share too)

BoomBoomBap 06-19-2003 02:31 PM

Wow - that was so unbelievably easy to implement I can't believe I didn't do it sooner.

Thanks for the code !

For the record - all that's needed is the addition of this form and button to customer/products.tpl (place where approriate):

Code:

<form name=orderform_{%product.index%} method=post action="cart.php?mode=add">
<a href="javascript: document.orderform_{%product.index%}.submit()">
{include file="buttons/add_to_cart.tpl"}</a>
<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=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}>More info...</a>
</form>


Nice.... :P

shan 06-19-2003 03:07 PM

suppose we should put this in custom templates :idea:

BoomBoomBap 06-19-2003 03:13 PM

Eh? I dont follow you.
Aren't we already in Custom Templates ?

shan 06-19-2003 03:15 PM

we are now :wink:

BoomBoomBap 06-19-2003 03:16 PM

LOL

I get it...

:oops:

barabbas 06-19-2003 10:55 PM

this isnt working for v 3.4.2

shan 06-20-2003 01:56 AM

use the option to add the "buy now" button that is built into v3.4.x branh

DataViking 06-22-2003 01:47 AM

Thanks for the code, works great :lol:

YuriC 06-23-2003 12:01 PM

How about this feature
 
http://www.worldhealthproducts.com/xcart-musclesoft/customer/home.php

DataViking 06-23-2003 04:54 PM

YuriC
 
I like yours a lot. Is any chance that you will share the code?

YuriC 06-24-2003 02:20 PM

I dont see why not
 
Here you go. Replace your products.tpl with this code

Code:

{* $Id: products.tpl,v 1.21.2.2 2003/03/11 10:49:14 svowl Exp $ *}
{* mod by YuriC *}
{section name=product loop=$products}
<table border=0 width=100%>
<tr><td width=90 align=center valign=top>
<a href=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}>{include file="product_thumbnail.tpl" productid=$products[product].productid image_x=70 product=$products[product].product}
{$lng.lbl_see_details}</a>
</td>
<td valign=top>
{$products[product].product}</font>
<font size=1>




{$products[product].descr|truncate:300:"...":true}


</font>
<hr size=1 noshade width=230 align=left>
{if $active_modules.Subscriptions ne "" and $products[product].catalogprice}
{include file="modules/Subscriptions/subscription_info_inlist.tpl"}
{else}
{if $products[product].price ne 0}
{if $products[product].discount ne 0}
<font class=MarketPrice>{$lng.lbl_market_price}: <s>
{math equation="price/(1-(discount/100))" price=$products[product].price discount=$products[product].discount format="%d.00" assign=unformatted}{include file="currency.tpl" value=$unformatted}
</s></font>

{/if}
<font class=ProductPrice>{$lng.lbl_our_price}: {include file="currency.tpl" value=$products[product].price}</font><font class=MarketPrice>{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$products[product].price}</font>{if $products[product].discount ne 0}, save {$products[product].discount}%{/if}{if $config.General.use_vat eq "Y"}, {$lng.lbl_including_vat} {$products[product].vat}%{/if}
{else}
<font class=ProductPrice>{$lng.lbl_enter_your_price}</font>
{/if}
{/if}
<form name="form{$products[product].productid}" method=post action="cart.php?mode=add">
{$lng.lbl_quantity}:{if $product.min_amount gt 1}
<FONT class=ProductDetailsTitle>{$lng.txt_need_min_amount} {$product.min_amount} {$lng.lbl_items}</FONT>{/if}

{if $config.General.show_in_stock eq "Y" and ($product.avail le 0 or $product.avail lt $product.min_amount)}
{$lng.txt_out_of_stock}
{else}
{if $config.General.show_in_stock ne "Y"}
{assign var="mq" value=$config.General.max_select_quantity}
{else}
{math equation="min(maxquantity+minamount, productquantity)+1" assign="mq" maxquantity=$config.General.max_select_quantity minamount=$product.min_amount productquantity=$product.avail}
{/if}
<input type=hidden name=mode value=add>
{if $product.distribution eq ""}
{if $product.min_amount le 1}
{assign var="start_quantity" value=1}
{else}
{assign var="start_quantity" value=$product.min_amount}
{/if}
<input type="text" name="amount" value="{$start_quantity}" size="2">

<font class=FormButton>{$lng.lbl_add_to_cart} [img]{$ImagesDir}/GOboutonWhiteBkg.gif[/img]</font>
{else}
<font class=ProductDetailsTitle>1</font><input type=hidden name=amount value=1> {$lng.txt_product_downloadable}
{/if}
{/if}
<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}">
</form>
</td></tr>
</table>






{/section}

use it under your own consent

pauld 09-05-2003 03:51 PM

OK great job you guys this is exactly what I was looking for.

:)

pauld 09-08-2003 05:49 PM

Quote:

Originally Posted by John7
Actually you see its the code itself. I think it needs to be modified to be able to do more than just display the ad buttom it needs to display the choice of which color.

Do you understand?


Did you ever receive a reply to this??????


All times are GMT -8. The time now is 08:19 AM.

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