close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Multiple Add to Cart

Thread began 6/24/2009 3:30 am by danjen | Last modified 6/29/2009 12:15 pm by Ray Borduin | 2433 views | 14 replies |

danjenBeta Tester

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?

Sign in to reply to this post

Ray BorduinWebAssist

Don't include the brackets in this line:

$WADbSearch1->addComparisonFromList("pn","addtocart[]","AND","=",0);

should be:
$WADbSearch1->addComparisonFromList("pn","addtocart","AND","=",0);

Sign in to reply to this post

danjenBeta Tester

Hi Ray - Thanks for the reply. I removed the brackets and tested it and it still didn't work. It is still adding the entire database. Then I removed the brackets from the checkbox and same problem. Filter still not grabbing just the checked items.

Thanks for your help.

Sign in to reply to this post

Ray BorduinWebAssist

Leave the brackets in the checkbox name... just not in the search reference.

What button are you clicking to submit the form? Have you tried adding debug statements to see if the recordset query is updated or if the search where clause code is set?

I would try writing the sql query and where clause values and make sure the trigger is correct.

Sign in to reply to this post

danjenBeta Tester

I put an echo of the query on the page. It is not getting to the filter. The select is for the items and nothing is being filtered

Sign in to reply to this post

danjenBeta Tester

I am missing a step somewhere to get the checked items only into the recordset. I either have the filter in the wrong place or something.

Sign in to reply to this post

Ray BorduinWebAssist

It may be a problem with the trigger if you have changed the button name.

The code that should build the filter is:

$WADbSearch1->addComparisonFromList("pn","addtocart","AND","=",0);

maybe add:
die("filter: ".$WADbSearch1->whereClause);

after that line and see A if it is called and B what the where clause it thinks it should use is.

Sign in to reply to this post

danjenBeta Tester

ok if I add that to the code, the page doesn't load. Just dies with filter:

I have not changed the name of the button and the main product is added to the cart. Now just the accessory items are not added with it.
Is there any kind of training recipe for add multiple items to cart. I am so close on this, but am getting frustrated that I am getting no where.

Here is my filter at the beginning of the page.

<?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","addtocartmodel","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 recordset:
$MMColParam_AddToCartItems = "-1";
if (isset($_POST['addtocartmodel[]'])) {
$MMColParam_AddToCartItems = (get_magic_quotes_gpc()) ? $_POST['addtocartmodel[]'] : addslashes($_POST['addtocartmodel[]']);
}
mysql_select_db($database_localhost, $localhost);
$query_AddToCartItems = sprintf("SELECT CartItems.pn, CartItems.brand_name, CartItems.color_code, CartItems.medium_description, CartItems.thumbnail, CartItems.Price FROM CartItems WHERE %s = CartItems.pn", GetSQLValueString($MMColParam_AddToCartItems, "text"));
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);

Sign in to reply to this post

Ray BorduinWebAssist

Are the checkboxes in the form?

Did you have any checked?

What does the checkbox code look like when you view the source? Do you have a sample url?

Sign in to reply to this post

danjenBeta Tester

Yes - checkboxes are in a form and they are checked.
Here is URL: ProductsDetail.php?SKU=EIFLW55HMB
I am only wokring on Recommended models right now. Then I will do warranties and accessory items
Here is form code:
<?php if ($totalRows_RelatedModel > 0) { // Show if recordset not empty ?>
<h2 style="background-color: #D3E1FB;width:680px;height:20px;padding-top:10px;"> Recommended models:</h2>
<form name="relatedmodel" method="post">
<?php do { ?>
<hr/>
<table>
<tr>
<td><table width="100%" border="0">
<tr>
<td align="left" valign="bottom"><img src="<?php echo $row_RelatedModel['thumbnail']; ?>" height="50" width="50" /></td>
<td width="100" valign="bottom" >
<input type="checkbox" name="addtocartmodel[]" id="addtocartmodel" value="<?php echo $row_RelatedModel['ModelItem']; ?>" align="top"/>
<a href="ProductsDetail.php?SKU=<?php echo $row_RelatedModel['ModelItem']; ?>"><?php echo $row_RelatedModel['ModelItem']; ?></a>
</td>
<td valign="bottom" width="200"><?php echo $row_RelatedModel['brand_name']; ?><br />
<?php echo $row_RelatedModel['medium_description']; ?></td>
<td valign="bottom" align="right" width="100">$<?php echo $row_RelatedModel['price']; ?></td>
<td valign="bottom" align="right" width="200"><form name="WA_Store_Cart_3_ATC_<?php echo $row_RelatedModel['ModelItem']; ?>" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>">
<input type="hidden" name="WA_Store_Cart_3_ID_Add" value="<?php echo $row_RelatedModel['ModelItem']; ?>" >
<input type="text" name="WA_Store_Cart_3_Quantity_Add" value="1" size="1" >
<input type="submit" value="Add to Cart" name="WA_Store_Cart_3_ATC" align="absmiddle">
</form></td>
</tr>
</table></td>
</tr>
</table>
<?php } while ($row_RelatedModel = mysql_fetch_assoc($RelatedModel)); ?> </form>
<?php } // Show if recordset not empty ?>

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...