close ad
 
Important WebAssist Announcement
open ad
View Menu

Web development tutorial

Inventory management checkout V

Tutorial created by Ray Borduin, WebAssist

Categories: Data Bridge, eCart, Dreamweaver, PHP

rating

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.

arrow downWhat do you need to start?

  1. Site defined with Dreamweaver CS4 or higher.
  2. Product and admin pages built with DataAssist. For more assistance, view tutorials: Create a product catalog I and Create a product catalog II.
  3. A Checkout Wizard generated checkout experience previously generated with eCart 5 or higher.

arrow downUpdate confirm 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.

  1. Copy the following snippet of code (Ctrl or Cmd + C):
    <?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;
    }
    }
    ?>

  2. In code view, paste the snippet into your confirm page as indicated (Ctrl or Cmd + P):


  3. Copy the following snippet of code (Ctrl or Cmd + C):
    <?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();
    ?>

  4. In code view, paste the snippet into your confirm page following "<?php$eCart1->GetContent();?>" (Ctrl or Cmd + P) :


  5. Use Find and Replace (Ctrl or Cmd + F) to rename the cart if your cart is NOT named eCart1. (Place your actual cart name in Find.)


  6. If the database connection referenced in the snippet of code differs from YOUR connection's name, the Recordset will need to be repaired, as indicated by a red exclamation mark next to Recordset (WADAProducts) in the Server Behaviors panel.

    1. Double-click on Recordset (WADAProducts) from the Server Behaviors panel.

    2. In the Recordset window, select your connection's name.

    3. Click Test.



  7. You should see a single column named RemainingInventory and that there are no errors.


  8. Click OK and OK once again.

arrow downUpdate pp_confirm page

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.

  1. Copy the following snippet of code (Ctrl or Cmd + C):
    <?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();
    ?>

  2. In code view, paste the snippet into your pp_confirm page as indicated (Ctrl or Cmd + P):


  3. Use Find and Replace (Ctrl or Cmd + F) to rename the cart if your cart is NOT named eCart1. (Place your actual cart name in Find.)


  4. If the database connection referenced in the snippet of code differs from YOUR connection's name, the Recordset will need to be repaired, as indicated by a red exclamation mark next to Recordset (WADAProducts) in the Server Behaviors panel.

    1. Double-click on Recordset (WADAProducts) from the Server Behaviors panel.

    2. In the Recordset window, select your connection's name.

    3. Click Test.



  5. You should see a single column named RemainingInventory and that there are no errors.


  6. Click OK and OK once again.

arrow downWhere do you go next?

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.

arrow downWebassist inventory management series

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.

  1. Inventory management series: A summary of six in-depth tutorials which walk you through the steps of managing inventory on your eCommerce site using administrative pages as well as product detail, shopping cart and confirm pages.

  2. Inventory management introduction I: Learn about inventory control for eCommerce sites and how to set up your database to manage product stock.

  3. Inventory management administration II: Learn how to set up inventory control so that an Administrator can track and update the amount of stock carried in an eCommerce site.

  4. Inventory management product detail III: Learn how to alert online customers to insufficient inventory on the product detail page for the product they wish to purchase.

  5. Inventory management shopping cart IV: Learn how to alert online customers to insufficient inventory in the shopping cart for the product they wish to purchase.

  6. Inventory management checkout V: Learn how to alert online customers during checkout to insufficient inventory for the product they wish to purchase.

  7. Inventory management workflow VI: In this final tutorial, you will be walked through the inventory management workflow process from start to finish.


For further inventory management help, check our Community Forums or post comments to this tutorial.

arrow downReviews and comments

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 comments
rating

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.