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

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Add to cart from recordset

Thread began 6/18/2009 1:57 am by danjen | Last modified 6/18/2009 5:01 pm by danjen | 3220 views | 3 replies |

danjenBeta Tester

Add to cart from recordset

I have 3 add to cart buttons on one page. 2 of them were created using add to cart from recordset.

These 2 only allow me to add one item to the cart. If I click add to cart once it adds it to the cart. If I go back to the page and click another item it will not add it to the cart. The redirect takes me to the cart , but only the first item is there.

Here is the code:
<?php
// WA eCart Get Info From RS
if (isset($_POST["WA_Store_Cart_2_ATC"]) && isset($totalRows_rsRelated) && $totalRows_rsRelated > 0) {
$Redirect_redirStr="cart.php";
do {
$WA_Store_Cart_itemID = "".((isset($_POST["addtocart[]"]))?$_POST["addtocart[]"]:"") ."";
$WA_Store_Cart_itemName = "".$row_rsRelated['RelatedItem'] ."";
$WA_Store_Cart_itemDescription = "".$row_rsRelated['short_description'] ."";
$WA_Store_Cart_itemWeight = floatval("0");
$WA_Store_Cart_itemQuantity = floatval("".((isset($_POST["WA_Store_Cart_2_Quantity_Add"]))?$_POST["WA_Store_Cart_2_Quantity_Add"]:"") ."");
$WA_Store_Cart_itemPrice = floatval("".$row_rsRelated['price'] ."");
$WA_Store_Cart_itemThumb = "".$row_WADAProduct_Base['pn'] ."";
$WA_Store_Cart_itemSKU = "".$row_WADAProduct_Base['pn'] ."";

$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_rsRelated = mysql_fetch_assoc($rsRelated));
if ($Redirect_redirStr != "") {
$WA_Store_Cart->redirStr = $Redirect_redirStr;
}
mysql_data_seek($rsRelated, 0);
$row_rsRelated = mysql_fetch_assoc($rsRelated);
}
?>
<?php
// WA eCart Get Info From RS
if (isset($_POST["WA_Store_Cart_3_ATC"]) && isset($totalRows_RelatedModel) && $totalRows_RelatedModel > 0) {
$Redirect_redirStr="cart.php";
do {
$WA_Store_Cart_itemID = "".((isset($_POST["addtocartmodel[]"]))?$_POST["addtocartmodel[]"]:"") ."";
$WA_Store_Cart_itemName = "".$row_RelatedModel['RelatedItem'] ."";
$WA_Store_Cart_itemDescription = "".$row_RelatedModel['medium_description'] ."";
$WA_Store_Cart_itemWeight = floatval("0");
$WA_Store_Cart_itemQuantity = floatval("".((isset($_POST["WA_Store_Cart_3_Quantity_Add"]))?$_POST["WA_Store_Cart_3_Quantity_Add"]:"") ."");
$WA_Store_Cart_itemPrice = floatval("".$row_RelatedModel['price'] ."");
$WA_Store_Cart_itemThumb = "".$row_RelatedModel['thumbnail'] ."";
$WA_Store_Cart_itemSKU = "".$row_rsRelatedModel['pn'] ."";

$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_RelatedModel = mysql_fetch_assoc($RelatedModel));
if ($Redirect_redirStr != "") {
$WA_Store_Cart->redirStr = $Redirect_redirStr;
}
mysql_data_seek($RelatedModel, 0);
$row_RelatedModel = mysql_fetch_assoc($RelatedModel);
}


Can you tell me what I did wrong?

Sign in to reply to this post

Ray BorduinWebAssist

You used the wrong argument to the method:

AddToCart()

the first argument you have set to: 1

That value determines what to do if the item is in the cart:

0 = increment quantity
1 = ignore add to cart
2 = add as a new item
3 = no longer used (formerly used as redirect, but now redirect is an option for all)
4 = replace

Sign in to reply to this post

danjenBeta Tester

Thanks a lot Ray. I appreciate your help. That fixed part of the issue. It now adds it to the cart. The problem now is that it seems it is treating it as one recordset. The code shows 2 different recordsets, but if I click either add to cart button it adds to value of the other items in the cart.

I changed the code to 0 so it adds to the value if it is in the cart.

Thanks for your help

Sign in to reply to this post

danjenBeta Tester

I figured out the last part of the question. I had the same name used in both tables. So I have that working now.

Next issue is: I have the add to cart button in a repeating table. It lists all of the accessories in a table. If I click the add to cart button it adds the model of the fist item and the quantity of all of the items. So if the first accessory is abc and there are 4 accessories listed. If I click on the last add to cart button(item xyz) it adds abc to the cart with quantity of 4

Here is the code for the add to cart

<table>
<?php do { ?>
<tr>
<td><table width="100%" border="0">
<tr>
<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"]:""; ?>">
<input type="hidden" name="WA_Store_Cart_2_ID_Add" value="<?php echo $row_rsRelated['RelatedItem']; ?>" >
<input type="text" name="WA_Store_Cart_2_Quantity_Add" value="1" size="1" >
<input type="submit" value="Add to Cart" name="WA_Store_Cart_2_ATC">
</form></td>
</tr>
</table>
</td>
</tr>
<?php } while ($row_rsRelated = mysql_fetch_assoc($rsRelated)); ?>
</table>
<?php } // Show if recordset not empty ?>
<?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>
<?php do { ?>
<hr/>
<table>
<tr>
<td>
<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"]:""; ?>"><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"><?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>
<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">
</form></td>
</tr>
</table>
</td>
</tr>
</table>

Sign in to reply to this post

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...