In the fifth tutorial of the Inventory Management series, you will learn how to add code to the confirm pages to inform your online customers during checkout when the quantity of the product they wish to purchase is no longer available. When you are finished, follow the link to complete the inventory management overview. A list of Inventory Management tutorials is also found at the bottom of this page.
Next you will update the confirm page if you are using a payment gateway other than PayPal Express Checkout to let your customers know when the quantity of the product they wish to purchase is no longer available.
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
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
header("location: cart.php");
die();
}
// prevent DW from showing a broken Recordset
mysql_free_result($WADAProducts);
$eCart1->MoveNext();
// End Of Intentory Check
}
$eCart1->MoveFirst();
?>
Lastly, you will update the pp_confirm page if you're using PayPal Express Checkout as a payment gateway to let your customers know when the quantity of the product they wish to purchase is no longer available.
<?php
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
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$IDParam_WADAProducts = "-1";
if (isset($_GET['CurCartID'])) {
$IDParam_WADAProducts = $_GET['CurCartID'];
}
mysql_select_db($database_conn_ecommerce, $conn_ecommerce);
$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, $conn_ecommerce) 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
header("location: cart.php");
die();
}
// prevent DW from showing a broken Recordset
mysql_free_result($WADAProducts);
$eCart1->MoveNext();
}
$eCart1->MoveFirst();
?>
Now that you have finished setting up your inventory control, let's walk through the process from start to finish so that you know what to expect from and how to best use inventory management at Inventory management workflow VI.
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.