Multiple Add to Cart
I am trying to create multiple add to cart interface where multiple items are added to a cart that have a checkbox.
I have added the add to cart from recordset server behavior and I have created a filter using search wizard to create recordset of the checked items. The problem I am having is that the filter is not working and it is adding everything in the database to the cart.
Here is the filter:
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: AddToCartItems;
//Searchpage: ;
//Form: ;
$WADbSearch1_DefaultWhere = "";
if (!session_id()) session_start();
if (isset($_POST["WA_Store_Cart_1_ATC_x"])) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations
//comparison list additions
$WADbSearch1->addComparisonFromList("pn","addtocart[]","AND","=",0);
//save the query in a session variable
if (1 == 1) {
$_SESSION["WADbSearch1_ProductsDetail"]=$WADbSearch1->whereClause;
}
}
else {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//get the filter definition from a session variable
if (1 == 1) {
if (isset($_SESSION["WADbSearch1_ProductsDetail"]) && $_SESSION["WADbSearch1_ProductsDetail"] != "") {
$WADbSearch1->whereClause = $_SESSION["WADbSearch1_ProductsDetail"];
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = '';
?>
Here is add to cart
<?php
// WA eCart Get Info From RS
if (isset($_POST["WA_Store_Cart_1_ATC_x"]) && isset($totalRows_AddToCartItems) && $totalRows_AddToCartItems > 0) {
$Redirect_redirStr="cart.php";
do {
$WA_Store_Cart_itemID = "".$row_AddToCartItems['pn'] ."";
$WA_Store_Cart_itemName = "".$row_AddToCartItems['medium_description'] ."";
$WA_Store_Cart_itemDescription = "".$row_AddToCartItems['color_code'] ."";
$WA_Store_Cart_itemWeight = floatval("0");
$WA_Store_Cart_itemQuantity = floatval("1");
$WA_Store_Cart_itemPrice = floatval("".$row_AddToCartItems['Price'] ."");
$WA_Store_Cart_itemThumb = "".$row_AddToCartItems['thumbnail'] ."";
$WA_Store_Cart_itemSKU = "".$row_AddToCartItems['brand_name'] ."";
$WA_Store_Cart->AddToCart(1, "", $WA_Store_Cart_itemID, $WA_Store_Cart_itemName, $WA_Store_Cart_itemDescription, $WA_Store_Cart_itemWeight, $WA_Store_Cart_itemQuantity, $WA_Store_Cart_itemPrice, $WA_Store_Cart_itemThumb, $WA_Store_Cart_itemSKU);
} while ($row_AddToCartItems = mysql_fetch_assoc($AddToCartItems));
if ($Redirect_redirStr != "") {
$WA_Store_Cart->redirStr = $Redirect_redirStr;
}
mysql_data_seek($AddToCartItems, 0);
$row_AddToCartItems = mysql_fetch_assoc($AddToCartItems);
}
?>
Here is recordset:
mysql_select_db($database_localhost, $localhost);
$query_AddToCartItems = "SELECT Product_Base.pn, Product_Base.brand_name, Product_Base.color_code, Product_Base.medium_description, Product_Base.thumbnail, Product_Base.Price FROM Product_Base";
setQueryBuilderSource($query_AddToCartItems,$WADbSearch1,false);
$AddToCartItems = mysql_query($query_AddToCartItems, $localhost) or die(mysql_error());
$row_AddToCartItems = mysql_fetch_assoc($AddToCartItems);
$totalRows_AddToCartItems = mysql_num_rows($AddToCartItems);
Here is checkbox:
<td valign="bottom" width="110px"><form name="related"><input type="checkbox" name="addtocart[]" id="addtocart" value="<?php echo $row_rsRelated['AccessoryItem']; ?>" align="top"/><a href="ProductsDetail.php?SKU=<?php echo $row_rsRelated['AccessoryItem']; ?>"><?php echo $row_rsRelated['AccessoryItem']; ?></a><input name="posted" type="hidden" value="1" /></form></td>
<td valign="bottom"><?php echo $row_rsRelated['short_description']; ?></td>
<td valign="bottom" width="120" align="right">$<?php echo $row_rsRelated['price']; ?></td>
<td><form name="WA_Store_Cart_2_ATC_<?php echo $row_rsRelated['AccessoryItem']; ?>" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>">
Can you tell me what I am doing wrong here?