In the fourth tutorial of the Inventory Management series, you will learn how to inform your online customers on the shopping cart page when the quantity of a product they wish to purchase is no longer available. When you are finished, follow the link to complete the next step in inventory management. A list of Inventory Management tutorials is also found at the bottom of this page.
Now you will update the cart page to let your customers know that the quantity of a product they wish to purchase is no longer available. This is done by adding three snippets of code. In this section, we will add the first snippet.
<?php
$UpdatedItems = array();
while ( !$eCart1->EOF() ) {// Check to make sure quantities are in line with inventory in case inventory has changed or the user updated the quantity
$_GET['CurCartID'] = $eCart1->DisplayInfo("ID");
// use standard Recordset syntax so that it is editable and found by DW and the connection can be easily edited
?>
<?php
$IDParam_WADAProducts = "-1";
if (isset($_GET['CurCartID'])) {
$IDParam_WADAProducts = $_GET['CurCartID'];
}
mysql_select_db($database_Sample_Connection, $Sample_Connection);
$query_WADAProducts = sprintf("SELECT ProductStock - (SELECT Coalesce(SUM(DetailQuantity),0) FROM orders Inner Join orderdetails ON orderdetails.DetailOrderID = orders.OrderID WHERE OrderDate > ProductUpdateDate AND DetailProductID = ProductID) AS RemainingInventory FROM products WHERE ProductID = %s", GetSQLValueString($IDParam_WADAProducts, "int"));
$WADAProducts = mysql_query($query_WADAProducts, $Sample_Connection) or die(mysql_error());
$row_WADAProducts = mysql_fetch_assoc($WADAProducts);
$totalRows_WADAProducts = mysql_num_rows($WADAProducts);
?>
<?php
// remove the product if it is no longer in inventory, update it if the quantity is over the inventory level.
if ($row_WADAProducts && $row_WADAProducts['RemainingInventory'] < $eCart1->DisplayInfo("Quantity")) {
// if none are left, remove the product, otherwise update the quantity
if (floatval($row_WADAProducts['RemainingInventory']) > 0) {
$eCart1->Items[$eCart1->DisplayIndex]->Quantity = floatval($row_WADAProducts['RemainingInventory']);
$eCart1->Items[$eCart1->DisplayIndex] = $eCart1->ResetCalculations($eCart1->Items[$eCart1->DisplayIndex]);
$UpdatedItems[$eCart1->DisplayIndex] = true;
}
else {
$eCart1->Items[$eCart1->DisplayIndex]->Quantity = 0;
}
$_GET['StockUpdated'] = true;
}
// prevent DW from showing a broken Recordset
mysql_free_result($WADAProducts);
$eCart1->MoveNext();
}
$eCart1->MoveFirst();
?>
<?php
//Save the cart in the session if any inventory levels have been updated
?>
<?php
if ((isset($_GET['StockUpdated'])?$_GET['StockUpdated']:"") == true) {
for ($n=0; $n<sizeof($eCart1->Items); $n++) {
if ($eCart1->Items[$n]->Quantity == 0) {
$eCart1->DeleteFromCart($n, false);
}
}
$eCart1->ReIndexContent();
$eCart1->ResetAll();
$eCart1->SaveCart();
}
?>
Now we will add the second snippet to the shopping cart page which tells customers when one or more items were removed from their cart because of lack of inventory.
<?php
if ((isset($_GET['StockUpdated'])?$_GET['StockUpdated']:"") == true) {
?>
<strong style="color:red;">One or more items were removed from your cart because of lack of inventory. Please carefully review your cart contents before continuing.</strong>
<?php
}
?>
Now we will add the third snippet to the shopping cart page which alerts customers to the maximum available inventory when there is not enough inventory to complete their full purchase.
<?php
if (isset($UpdatedItems) && in_array($eCart1->DisplayInfo("ID"),$UpdatedItems)) {
?>
<p class="eC_FormItem eC_ItemQuantity_Edit"><strong style="color:red;">maximum available</strong></p>
<?php
}
?>
Now that you know how to inform your online customers when the product they wish to purchase is no longer available in the shopping cart, you will learn how to alert your customers to insufficient inventory during checkout at Inventory management checkout V.
In the WebAssist inventory management series for eCommerce sites, you will learn how to track and update inventory as an administrator. Additionally, you will learn how to inform your customers throughout the shopping and purchase process when the quantity of the product they wish to purchase is insufficient or no longer in stock.
For further inventory management help, check our Community Forums or post comments to this tutorial.
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.