close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Web development tutorial

Inventory management shopping cart IV

Tutorial created by Kate Ford

Categories: Data Bridge, eCart, Dreamweaver, PHP

rating

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.

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 experience previously generated with eCart 5 or higher.

arrow downUpdate cart page I

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.

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

  2. Paste the snippet into your cart page code (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 downUpdate cart page II

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.

  1. Copy (Ctrl or Cmd + C):
    <?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
    }
    ?>

  2. Paste (Ctrl or Cmd + P) the snippet above the cart in the code:


  3. Now the "One or more items were removed from your cart because of lack of inventory. Please carefully review your cart contents before continuing." error message is above the shopping cart as an alert to customers.

arrow downUpdate cart page III

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.

  1. Copy (Ctrl or Cmd + C):
    <?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
    }
    ?>

  2. Paste into the Quantity column (Ctrl or Cmd + P):


  3. Now the "maximum available" error message is in the quantity column as an alert to customers.


  4. Go to File > Preview in Browser to view your cart page.

arrow downWhere do you go next?

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.

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.