Tom Muck's blog
Make Add to Cart buttons (php)
Friday, May 29, 2009 8:49:09 PM
I get a lot of questions about making an Add to Cart button for Cartweaver. This is not something that is available out of the box, but easily implemented. Cartweaver doesn't work like Paypal, where you need static add to cart buttons to make the cart work. CW is self-contained and database driven, where all products are stored in the database. However, an add to cart button is easily added. I have been using them for years on my own site www.tom-muck.com/extensions. The following can be added to the ProductForm.php file in the Cartweaver admin, right before the closing </div> tag on the Page 1 div. Find this code:
</div>
<div id="page2">
add this:
<p><a href="AddToCartButtons.php?prodId=<?php echo($row_rsCWGetProduct["product_ID"]);?>" target="_blank">Make Add To Cart Buttons</a></p>
</div>
<div id="page2">
Now, create a new page in the /cw3/admin folder called AddToCartButtons.php and put this code on it:
<?php
include("application.php");
$productId = isset($_GET["prodId"]) ? intval($_GET["prodId"]): 0;
/* Get Product Data */
$query_rsCWGetProduct = sprintf("SELECT DISTINCT product_ID,
product_Name,
product_Description,
s.SKU_ID,
s.SKU_MerchSKUID
FROM tbl_products p
INNER JOIN tbl_skus s
ON p.product_ID = s.SKU_ProductID
WHERE product_ID = %d
AND product_Archive = 0
AND product_OnWeb = 1
", $productId);
$rsCWGetProduct = $cartweaver->db->executeQuery($query_rsCWGetProduct, "rsCWGetProduct");
$rsCWGetProduct_recordCount = $cartweaver->db->recordCount;
$row_rsCWGetProduct = $cartweaver->db->db_fetch_assoc($rsCWGetProduct);
do {
?>
<h2><?php echo($row_rsCWGetProduct["product_Name"] .": skuid " . $row_rsCWGetProduct["SKU_MerchSKUID"]);?></h2>
<textarea cols="80" rows="10">
<form action="details.php?prodId=<?php echo($row_rsCWGetProduct["product_ID"]);?>" method="post" name="AddToCart">
<input name="qty" type="hidden" value="1">
<input name="skuid" type="hidden" value="<?php echo($row_rsCWGetProduct["SKU_ID"]);?>">
<input name="prodId" type="hidden" value="<?php echo($row_rsCWGetProduct["product_ID"]);?>">
<input name="submit" type="submit" class="formButton" value="Add to Cart">
</form></textarea>
<br/><br/><hr/>
<?php
} while ($row_rsCWGetProduct = $cartweaver->db->db_fetch_assoc($rsCWGetProduct));
That should do it. Now, when you click the link, the page populates with add to cart button code for each sku for that product.
The add to cart button code looks like this:
<form action="details.php?prodId=31" method="post" name="AddToCart">
<input name="qty" type="hidden" value="1">
<input name="skuid" type="hidden" value="59">
<input name="prodId" type="hidden" value="31">
<input name="submit" type="submit" class="formButton" value="Add to Cart">
</form>
Category tags: Cartweaver, Dreamweaver, PHP
Posted by Tom Muck
Add comment
|
View comments (0) |
Permalink
|
Trackbacks (0)
|
Digg This
Before posting comments or trackbacks, please read the posting policy.
Blog RSS feed