Today's New Content
Search CMX

Advanced Search

Latest Free Content
View All
Free Content
Accessibility

Cartweaver Admin Hints and Mods Part 1: Creating a Low Stock Warning for PHP

By: Tom Muck

Page 1 of 2

Set for printing

Next

Cartweaver is an online shopping cart system available from cartweaver.com for PHP, ColdFusion, and ASP. It is intended as an easy-to-use solution for building an online store. It doesn't have all the bells and whistles of some of the more pricey carts available, but with a little coding, many new features can be added. Part 1 will show how to add a low-stock warning to the Cartweaver admin.

There is no warning for stocks getting low in supply in Cartweaver, however, you can create a simple query and display it in the admin home page showing a warning about low-stock products. First, create a new configuration item in the Cartweaver config section—this is the key to adding any new feature to Cartweaver. Follow these steps:

  1. Login as "sa" (super admin)
  2. Click Store Settings > Config Groups
  3. Add a new Config Group called "Admin Settings" (type it in and press the button to enter it)
  4. Click on the new Admin Settings link on the Config Group page, as shown in Figure 1. You'll be adding a new item here:
    • Friendly name: Low Stock Check
    • Variable name: LowStockCheck (make sure case is correct here)
    • Sort Order: 0
    • Form Field: Text Field
    • Initial Value: 5
    • Possible Values: (not used)
    • Description: Number left in stock to trigger low-stock warning
    • Show Merchant: checked


    Figure 1: Adding a new configuration item to the Cartweaver store

That gives your store a new store-wide setting called LowStockCheck, which is now available as a session variable to use in your code:

$_SESSION["LowStockCheck"]

Next, create a PHP page called LowStockProducts.php in the cw3/admin/ folder. On that page, use this code:

<?php
// Fill in the value that you want to use for the low-stock warning
$stockCheck = isset($_SESSION["LowStockCheck"]) ? $_SESSION["LowStockCheck"] : 5;

$query_rsCWGetSKUs = "SELECT DISTINCT P.product_ID
, P.product_Name
, S.SKU_ID
, S.SKU_MerchSKUID
, S.SKU_Price
, S.SKU_Stock
FROM tbl_products P
INNER JOIN tbl_skus S
ON P.product_ID = S.SKU_ProductID
WHERE P.product_OnWeb = 1
AND P.product_Archive = 0
AND S.SKU_Stock <= $stockCheck";
$rsCWGetSKUs = $cartweaver->db->executeQuery($query_rsCWGetSKUs,"rsCWGetSKUs");
$rsCWGetSKUs_recordCount = $cartweaver->db->recordCount;
$row_rsCWGetSKUs = $cartweaver->db->db_fetch_assoc($rsCWGetSKUs);
if($rsCWGetSKUs_recordCount > 0) {
?>
<h2>Low Stock Products Alert</h2>
<h3>Products where stock has reached a quantity of <?php echo($stockCheck);?> or less</h3>
<table class="tabularData" id="tableSearchResults">
<tr>
<th>Item Name</th>
<th>SKU ID</th>
<th>Price</th>
<th>Stock</th>
<th>View</th>
</tr>
<?php
$recCounter = 0;
do {
?>
<tr class="<?php cwAltRow($recCounter++);?>" style="vertical-align: top">
<td><?php echo($row_rsCWGetSKUs["product_Name"]);?></td>
<td><?php echo($row_rsCWGetSKUs["SKU_MerchSKUID"]);?></td>
<td><?php echo(cartweaverMoney($row_rsCWGetSKUs["SKU_Price"]));?></td>
<td><?php echo($row_rsCWGetSKUs["SKU_Stock"]);?></td>
<td><a href="ProductForm.php?product_ID=<?php echo($row_rsCWGetSKUs["product_ID"]);?>"><img src="assets/images/viewdetails.gif" alt="View Product" width="15" height="15" border="0"></a></td>
</tr>
<?php
} while ($row_rsCWGetSKUs = $cartweaver->db->db_fetch_assoc($rsCWGetSKUs)); ?>
</table>
<?php } /* end if($rsCWGetSKUs_recordCount > 0) */?>

The code is essentially saying "give me all the SKUs that have stock counts less than or equal to 5."

Page 1 of 2 1 2 Next


download
Download Support Files


Keywords
cartweaver,php,e-commerce,ecommerce,e-store,cart,shopping,admin,administration