This tutorial will guide you through the process of manually creating an add to cart page for your ecommerce website which will allow you to select multiple products using checkboxes then submitting this selection to the shopping cart.
Dreamweaver
eCart
Databridge
This tutorial assumes you have an understanding of the the basic features of ecart and databridge and that you have already created/using an apppropriate database for your shopping cart as well as created a cart page. As this tutorial is more for customising the actual product page where the add to cart button would be located on.
Once at the end of this tutorial the basic framework of the server behaviours will look like this:
1. ecart(WebCart)
2. DataAssist Search (rsATC)
3. Recordset (rsItems)
4. Recordset (rsATC)
5. eCart Get From Recordset (WebCart, rsATC)
6. Your HTML code and PHP bindings
Also make sure that when applying the server behaviours that the below comes before anything else in the page:
<?php require_once('Connections/websitedb.php'); ?>
<?php require_once("WA_eCart/WebCart_PHP.php"); ?>
<?php $WebCart->GetContent(); ?>
<?php require_once("webassist/database_management/wada_search.php"); ?>
The layout table and form structure I will be using for this tutorial is as follows:
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="200"><input name="itemchecked[]" type="checkbox" value=""> </td>
<td width="200" align="right">Quantity:<input name="qty_" type="text" value="1" size="3" ></td>
<td width="200" align="right"></td>
</tr>
</table>
<br>
<input name="WebCartATC" type="submit" value="Add to Cart">
</form>
A few points I would like to make at this point...
We will require 2 recordsets for this tutorial.
The first being the main recordset that will contain any filters you require (such as filtering for categories if its a last catelogue of items in your store)
The second recordset will contain an un-filtered version of the above (this will be required for the search filter that will be explained futher on)
Next we need to add the bindings to the layout and form.
rsItems - this recordset is used for display output, so it is this we will be creating the bindings of the table and form in the code provided previously.
rsATC - (ATC just stands for Add to Cart so its just a reference for this tutorial) This recordset will be used to filter the checkboxes using the DataAssist Search server behaviour.
So using the bindings panel and making sure you only use the bindings for the rsItems recordset set up your display, making sure specifically you bind the following form elements as well...
1. Bind the ID of the rsItems recordset for the value of the input checkbox
2. Bind the ID of the rsItems recordset to 'qty_' which forms the name of the quantity input box.
Since you will have have multiple items you will need to add a repeat region inside the <table> and </table> tags
Your final code should look like this:
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>"><table width="600" border="0" cellspacing="0" cellpadding="0">
<?php do { ?>
<tr>
<td width="200"><input name="itemchecked[]" type="checkbox" value="<?php echo $row_rsItems['ItemID']; ?>"> <?php echo $row_rsItems['ItemName']; ?></td>
<td width="200" align="right">Quantity:<input name="qty_<?php echo $row_rsItems['ItemID']; ?>" type="text" value="1" size="3" ></td>
<td width="200" align="right"><?php echo WA_eCart_DisplayMoney($WebCart, $row_rsItems['ItemPrice']); ?></td>
</tr>
<?php } while ($row_rsItems = mysql_fetch_assoc($rsItems)); ?>
</table>
<br>
<input name="WebCartATC" type="submit" value="Add to Cart">
</form>
Before the items are added to the shopping cart, we need someway of filtering the checkboxes on the form..,this can be done by using the DataAssist Search server behaviour.
From the Dreamweaver Server Behaviours Panel, locate and select the DataAssist Search server behaviour.
WebAssist -> DataAssist -> DataAssist Search
1. Set the Trigger to the Button (However its not really necessary since you can just simple select any form post (However I always make it good practice to be specific with form submits buttons)
2. For the recordset select the rsATC recordset.
3. For the Default WHERE clause - make sure you enter 0=1
4. Now click on the + icon
5. Seperate - Leave on default
6. Column - Select ItemID
7. Column Type - Leave on default (Number/Boolean)
8. Comparison - Leave on default (=)
9. Filter Type - Make sure you have selected List
10. List field name - The name of the input checkbox on the HTML form, in this case the name being, 'itemchecked'.
11. Click Finish
Now the custom part which replaces the initial 'Add To Cart ' server behaviour that you would have normally used.
From the Server Behaviours panel click on the + to add a new server behaviour and navigate to:
eCart -> Add to Cart -> Get Contents From Recordset
As before as a code of practice I would select the button as the Trigger and again making sure you use the rsATC recordset for this server behaviour's recordset.
Then using the lightening bolt and making sure you use the bindings from the rsATC recordset fill in each of the Values for the corrisponding Cart Columns.
When you get to Quantity you will need to enter the form input binding, however as this has no named value you will need to manually enter it in rather then selecting it..so copy and paste this for the Value of the Quantity Cart column:
<?php echo ((isset($_POST["qty_".$row_rsATC['ItemID']]))?$_POST["qty_".$row_rsATC['ItemID']]:""); ?>
For the 'After operating' Redirect - Enter the page that will display the shopping cart (Usually cart.php)
Now click on OK and your done!
Comments will be sent to the author of this tutorial and may not be answered immediately. For general help from WebAssist, please visit technical support.
Sign in to add commentsYour friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
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.
CraigR: 10 Years, 9 Months, 1 Week, 1 Day, 14 Hours, 57 Minutes ago
Hi Christopher,
Have you ever tried achieving the same result, but instead of using checkboxes, check that the value of the quantity field is > 0 ?