okay.....feeling generous today cos it's friday.
Note this will work for up to 10 products per page.
It is not the most elegant of code but it works and that is what counts really
new customer/main/products.tpl code:
Code:
{* $Id: products.tpl,v 1.16.2.2 2002/11/13 07:17:50 alfiya Exp $ *}
{* multiple add to cart products page by funkydunk.net 2003 *}
<form action="addmultiple.php" method="get" name="orderform">
{section name=product loop=$products}
<table border="0" cellpadding="3" cellspacing="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 width= "300">
{$products[product].product|escape}
{$products[product].descr|truncate:300:"...":true}
{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}
{$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>{/if}
</td>
<td width= "60" align="right">
{include file="currency.tpl" value=$products[product].price}
{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$products[product].price}
{if $products[product].discount ne 0}, save {$products[product].discount}%{/if}
{else}
{$lng.lbl_enter_your_price}
{/if}
{/if}</td>
<td width= "60" align="right">
Quantity: <input type=text name=amount{%product.index%} size=3>
<input type=hidden name=productid{%product.index%} value="{$products[product].productid}">
<a href="javascript: document.orderform.submit()">
{include file="buttons/add_to_cart.tpl"}</a>
</td>
</tr><tr>
<td colspan="4"><hr size="1" noshade></td>
</tr></table>{/section}
<input type=hidden name=cat value="{$smarty.get.cat}">
<input type=hidden name=page value="{$smarty.get.page}">
<input type=hidden name=mode value=add>
</form>
new php file - customer/addmultiple.php
Code:
<?php
// addmultiple.php by funkydunk.net 2003
// adapted copy of x-cart cart.php Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved.
// only works with up to 10 products per page - obviously could be improved
// this was put together to fit the requirements that i had not yours :)
// there are prob bits of code in here that are not needed but hey..
require "../smarty.php";
require "../config.php";
@include "./https.php";
require "./auth.php";
include "./nocookie_warning.php";
session_register("cart");
session_register("intershipper_rates");
session_register("intershipper_recalc");
$intershipper_recalc = "Y";
#
# $order_secureid (for security reasons)
#
session_register("order_secureid");
#
# Register member if not registerred yet
# (not a newbie - do not show help messages)
#
$smarty->assign("register_script_name","addmultiple.php");
require "../include/register.php";
if ($auto_login) {
header("Location: cart.php?mode=checkout®istered=");
exit;
}
if (!empty($login)) $userinfo = func_userinfo($login, $current_area);
if ($mode=="add"){ // get the variables posted from the main page and add them to the array for cart items.
// takes the values from the products.tpl form and adds them into an array to work with for the looping through the add to cart process
if ($amount0) {
$item ["productid"] = $productid0;
$item ["amount"] = $amount0;
$added[] = $item;
}
if ($amount1) {
$item ["productid"] = $productid1;
$item ["amount"] = $amount1;
$added[] = $item;
}
if ($amount2) {
$item ["productid"] = $productid2;
$item ["amount"] = $amount2;
$added[] = $item;
}
if ($amount3) {
$item ["productid"] = $productid3;
$item ["amount"] = $amount3;
$added[] = $item;
}
if ($amount4) {
$item ["productid"] = $productid4;
$item ["amount"] = $amount4;
$added[] = $item;
}
if ($amount5) {
$item ["productid"] = $productid5;
$item ["amount"] = $amount5;
}
if ($amount6) {
$item ["productid"] = $productid6;
$item ["amount"] = $amount6;
$added[] = $item;
}
if ($amount7) {
$item ["productid"] = $productid7;
$item ["amount"] = $amount7;
$added[] = $item;
}
if ($amount8) {
$item ["productid"] = $productid8;
$item ["amount"] = $amount8;
$added[] = $item;
}
if ($amount9) {
$item ["productid"] = $productid9;
$item ["amount"] = $amount9;
$added[] = $item;
}
}
// end of adding products to array - bit rough and ready but then that's me :)
// count how many products in array
$count = count($added);
for ($row = 0; $row < $count; $row++) {
// start of loop through products added..puts all the added prodcust into a multi-dimensional array
$productid = $added[$row]["productid"];
$amount = $added[$row]["amount"];
$mode = "add";
// this is a chunk of code from the original 2.2.x cart.php script built by x-cart Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved.
#
# Add to cart
#
if($mode=="add" && $productid!="") {
$added_product=func_select_product($productid, $user_account['membership']);
#
# Add to cart amount of items that is not much than in stock
#
$amount = array_pop(func_query_first("select least('$amount',avail) from $sql_tbl[products] where productid='$productid'"));
if ($productid && $amount) {
if ($amount < $added_product[min_amount]) {
header ("Location: error_message.php?access_denied");
exit;
}
#
# Do addition to cart
# With options
#
$options=array();
$found = false;
if ($cart["products"]) {
foreach ($cart["products"] as $k=>$v) {
if (($v["productid"] == $productid) and (!$found) and ($v["options"] == $options)) {
$found = true;
$distribution = array_pop(func_query_first("select distribution from $sql_tbl[products] where productid='$productid'"));
if (($cart["products"][$k]["amount"] >=1) && ($distribution))
{$cart["products"][$k]["amount"]=1; $amount=0;}
$cart["products"][$k]["amount"] += $amount;
}
}
}
#
# price value is defined by customer if administrator set it to '0.00'
#
if (!$found)
$cart["products"][]=array("productid"=>$productid,"amount"=>$amount, "options"=>$options, "price"=>$price);
$intershipper_recalc = "Y";
}
}
if (!func_is_cart_empty($cart)) {
$products = func_products_in_cart($cart, $userinfo["membership"]);
/*if($active_modules["Subscriptions"]) {
include "../modules/Subscriptions/subscription.php";
}*/
if (!empty ($cart["products"]) && ($login || !($config["Shipping"]["enable_all_shippings"] == "Y"))) {
$destination_condition = " and destination=".($userinfo["s_country"]!=$config["Company"]["location_country"]?"'I'":"'L'");
}
#
# Fetch real shipping values
#
if($config["Shipping"]["realtime_shipping"]=="Y" && !empty($cart["products"]) && $login) {
if ($intershipper_recalc != "N") {
if ($config["Shipping"]["use_intershipper"] == "Y")
require "../shipping/intershipper.php";
else
require "../shipping/myshipper.php";
$intershipper_rates = func_shipper (func_weight_shipping_products($products));
$intershipper_recalc = "N";
}
}
if (!empty($cart["products"])) {
if (!$login || $config["Shipping"]["realtime_shipping"]!="Y")
$shipping = func_query("select * from $sql_tbl[shipping] where active='Y' $destination_condition order by orderby");
else {
$shipping = array ();
if($intershipper_rates)
foreach($intershipper_rates as $intershipper_rate) {
$result = func_query_first("select * from $sql_tbl[shipping] where subcode='$intershipper_rate[methodid]' and active='Y' order by orderby");
if ($result)
$shipping[] = $result;
}
$result = func_query ("SELECT * FROM $sql_tbl[shipping] WHERE code='' AND active='Y' $destination_condition ORDER BY orderby");
if ($result) {
foreach ($result as $res) {
$shipping [] = $res;
}
}
function array_cmp($a, $b) {
if ($a[orderby] == $b[orderby]) return 0;
return ($a[orderby] > $b[orderby]) ? 1: -1;
}
usort($shipping, "array_cmp");
}
}
if (count($shipping)==0) unset($shipping);
$smarty->assign("shipping", $shipping);
}
#
# If cart is not empty put products details into products array
#
if (!func_is_cart_empty($cart)) {
#
# Calculate all prices
#
$cart = array_merge ($cart, func_calculate($cart, $products, $login, $current_area));
$smarty->assign("cart",$cart);
}
} // end of loop that added the product to the cart - shall we do that again
// assign values to smarty cos I'm feeling generous
// here you go smarty have these
$smarty->assign("userinfo",$userinfo);
$smarty->assign("products",$products);
$smarty->assign("giftcerts",$giftcerts);
$smarty->assign("order",$order);
// Redirect once finished looping through products added to cart
// bored now..can I go to the cart..please?
header("Location: cart.php");
?>
This will take the customer to the cart at the end of the process.
No warranty is given with and PLEASE BACKUP beforehand.