Implementing Inventory Control
Example
- Adding inventory control to a database-driven shopping basket.
(Note: Inventory control cannot be used with Static Shopping
Baskets.)
MGI Tags
- mgiButton
- mgiConditional
- mgiFieldContent
- mgiGet
- mgiShoppingBasket
- mgiSendOrder
- mgiSet
- mgiToken
Steps
- Add an inventory field to the database.
- Populate the inventory field in the database.
- Open the order processing page in a text editor.
- Add inventory control parameters to the mgiSendOrder tag.
- Save the order processing page.
- Create an inventory error page.
- Save the inventory error page.
- Open the inventory error page in a text editor.
- Insert inventory errors, the mgiShoppingBasket tag, and mgiToken
tags.
- Save the inventory error page.
- FTP the order processing page and inventory error page to
the web server running MGI.
- Search the database and purchase a product.
Step 1: Add an inventory field to the database.
- Whether you are creating a new database or adding inventory
control to an existing database, add an "Integer" type
field in your database structure to hold the current inventory
of each product. See the Creating
Databases tutorial for instructions on adding fields to a
database.
Step 2: Populate the inventory field in the database.
- Access the database record administration page and enter
the current inventory for each product in the inventory database
field. See the Populating
Databases tutorial for instructions on adding and updating
database records.
Step 3: Open the order processing page in a text editor.
- Open the order processing page in a text editing program
that allows you to view and modify HTML.
Step 4: Add inventory control parameters to the mgiSendOrder
tag.
- Insert the productDatabaseFileLocation parameter, productTableName
parameter, inventoryFieldName parameter, and inventoryErrorURL
parameter in the mgiSendOrder tag. In the productDatabaseFileLocation
parameter, enter the path to the database file that contains
the inventory and product information relative to the root level
of the web site. For example, if a database is at the root level
of the site, the value of the productDatabaseFileLocation parameter
will be the database name (e.g., "Clothing"). If the
database is within a folder, the value of the productDatabaseFileLocation
parameter will be the folder name, a forward slah and the database
name (e.g., "Catalog/Clothing"). The database name
is case-sensitive. In the productTableName parameter, enter the
name of the table that contains the inventory and product information.
The table name is case-sensitive. In the inventoryErrorURL parameter,
enter the full path to the inventory error page (e.g., "http://www.domain.com/inventoryerror.html").
The inventory error page should reside on a non-secure server.
<mgiSendOrder to="sales@tshirtstore.com"
from="webmaster@tshirtstore.com" mailServer="mail.tshirtstore.com"
subject="Online Order" taxRate=".06" state="North Carolina"
productDatabaseFileLocation="Clothing" productTableName="Tshirts"
inventoryErrorURL="http://www.domain.com/inventoryerror.html"
inventoryFieldName="quantity">
Step 5: Save the order processing page.
- Save the changes you have made to the order processing page.
Step 6: Create an inventory error page.
- Create a new page to display inventory errors and a modifiable
shopping basket to customers. You can add a header and description
for the inventory error page such as:
Inventory Error
An inventory error has occurred with the following products.
Please adjust the quantities that you have ordered and re-submit the
order
Step 7: Save the inventory error page.
- Save the inventory error page and name it "inventoryerror.html".
Step 8: Open the inventory error page in a text editor.
- Open the inventory error page in a text editing program that
allows you to view and modify HTML.
Step 9: Insert inventory errors, the mgiShoppingBasket tag,
and mgiToken tags.
- On the inventory error page, display the inventory errors,
a modifiable shopping basket, a link to the check out page and
tokens.
-
- To display the inventory errors, set each potential error
product and error quantity in a variable. Enter a beginning mgiSet
tag, name parameter, and ending mgiSet tag for each error. In
the name parameter, enter the name of the variable. In the body
of the mgiSet tag, enter an mgiFieldContent tag and name parameter.
In the name parameter, enter the name of the product error or
quantity error. You should anticipate a maximum number of errors
and include a variable for each. Name each product error in sequence
(mgiInventoryErrorProductID1, mgiInventoryErrorProductID2...
mgiInventoryErrorProductIDX).
Name each quantity error in sequence (mgiInventoryErrorQuantity1,
mgiInventoryErrorQuantity2... mgiInventoryErrorQuantityX).
-
- Only display the errors that occur for each customer by performing
a conditional comparison with each variable value. If the variable
is not empty, then display the product error and quantity error.
Enter a beginning mgiConditional tag, lhs parameter, relationship
parameter and ending mgiConditional tag for each comparison.
In the lhs parameter, embed the value of the product error variable.
In the relationship parameter, enter "isNotEmpty".
In the body of the mgiConditional tag, enter an mgiGet tag for
the product error and quantity error associated with the variable.
-
- Allow customers to update their shopping basket. Enter an
mgiShoppingBasket tag and modification button as it appears on
the shopping basket display page. Enclose the mgiShoppingBasket
tag and button with HTML <FORM> tags whose action posts
to the inventory error page.
-
- Allow customers to re-submit their order. Enter an mgiButton
tag and name parameter. In the name parameter, enter the name
of the button ("Check Out"). Enclose the Check Out
button with HTML <FORM> tags whose action posts to the
check out page.
-
- To tokenize the URLs on the inventory error page, enter a
beginning mgiToken tag after the <BODY> tag and an ending
mgiToken tag before the </BODY> tag.
-
- The following is a complete inventory error page:
-
<html>
<head>
<title>Inventory Error</title>
</head>
<body bgcolor="#ffffff">
<mgiToken>
An inventory error has occured. Please modify your shopping
basket and check out again.
<p>
<!--Set Each Inventory Error in a Variable-->
<mgiset name="id1">
<mgiFieldContent name="mgiInventoryErrorProductID1">
</mgiset>
<mgiset name="id2">
<mgiFieldContent name="mgiInventoryErrorProductID2">
</mgiset>
<mgiset name="id3">
<mgiFieldContent name="mgiInventoryErrorProductID3">
</mgiset>
<!--Display Inventory Errors-->
<table border="1">
<tr><th><b>Product ID</b></th>
<th><b>Quantity in Stock</b></th></tr>
<mgiConditional lhs={mgiGet name="id1"} relationship="isNotEmpty">
<tr><td align="center">
<mgiFieldContent name="mgiInventoryErrorProductID1"></td>
<td align="center">
<mgiFieldContent name="mgiInventoryErrorQuantity1"></td></tr>
</mgiConditional>
<mgiConditional lhs={mgiGet name="id2"} relationship="isNotEmpty">
<tr><td align="center">
<mgiFieldContent name="mgiInventoryErrorProductID2"></td>
<td align="center">
<mgiFieldContent name="mgiInventoryErrorQuantity2"></td></tr>
</mgiConditional>
<mgiConditional lhs={mgiGet name="id3"} relationship="isNotEmpty">
<tr><td align="center">
<mgiFieldContent name="mgiInventoryErrorProductID3"></td>
<td align="center">
<mgiFieldContent name="mgiInventoryErrorQuantity3"></td></tr>
</mgiConditional>
</table>
<p>
<!--Display the Customer's Current Shopping Basket-->
<!--and Modify Shopping Basket Button for Changes-->
<FORM ACTION="inventoryerror.html" METHOD="Post">
<mgiShoppingBasket productDatabaseFileLocation="Clothing"
productTableName="Tshirts" productIDFieldName="ProductID">
<mgiSBPrice name="Price" pricefieldname="Price">
<mgiSBShippingCost name="Shipping" method="BasePlusPerItem"
baseShippingCost="2.00">
</mgiShoppingBasket>
<mgiButton name="Modify Shopping Basket">
</FORM>
<!--Display the Checkout Button to Re-Submit Order-->
<FORM ACTION="checkout.html" METHOD="Post">
<mgiButton name="Check Out">
</FORM>
</mgiToken>
</body>
</html>
Step 10: Save the inventory error page.
- Save the changes you have made to the inventory error page.
-
Step 11: FTP the order processing page and inventory error
page to the web server running MGI.
- Upload the order processing page and inventory error page
to the web server using an FTP program.
Step 12: Search the database and purchase a product.
- Search the database and purchase a product. If the quantity
of products that you order are in stock (according to the inventory
database field), then the order is sent and the ordered quantities
are subtracted from the inventory database field. If an inventory
error occurs when you send the order (i.e., a product quantity
exceeds the amount in inventory) then you are redirected to the
inventory error page where. The errors are displayed and you
have the opportunity to update the shopping basket and re-submit
the order.
-
- To update the inventory, update the database with new inventory
amounts.
|