Stock Managment
Previous  Top  Next

This page does not apply to the Lite version of the cart.

This section will walk you thought adding stock management to the site, Begin by adding a "InStock" field to the tblProducts table in the database, the "data type" should be set to "number" and the "Field Size" should be set to "Long Integer", this is shown in the following image:

clip0123


Next run the table in Access and input some initial stock levels for each product as shown in the following image:

clip0125


After you have defined the InStock value for all the products you will have to add the InStock field to the "web_Products" query, select the query in Access and click the clip0102 button and then add the InStock field to the query as shown in the following image:


clip0124

Save the query and close the database, now we can start modifying the pages.

Open the "AddFromDB.aspx" page and edit the "AddFromDB" server control tag, change currently the cart "ID" field gets its value from the "PartNo" database field, change this so the carts "ID" field comes from the "ProductID" database field.

clip0126

Next click the clip0122 button on the insert bar to insert a StockManager server control, the following dialog will appear:

clip0127

Set this dialog with the following properties:

ID: StockManager1
ConnectionString: ConStr
DBtable: tblProducts
DataBaseType: OleDb
StockCountField: InStock
ProductSelectionDBField: ProductID
ProductSelectionCartField: ID
Cart: Cart1

Leave the 2 checkboxes unchecked.

That's all that's required for this page, now when a product is added to the cart its associated stock field will decreased by the value of the quantity ordered.

Next open "cart.aspx" and add the same StockManager tag as you just inserted in "AddFromDB.aspx", this will then track each change that the user makes to their cart contents and update the stock counts in real-time.

The StockManager tag should be inserted into any page that allows the user to change the carts contents, otherwise changes could be made to the carts contents without updating the stock count.

Another improvment you could make is to the add to cart link on the "Product.aspx" page, the current tag is:

<a href="AddFromDB.aspx?ProdID=<%# DataSet1.FieldValue("ProductID", Container) %>">
<img src="../images/Cart.gif" width="100" height="22" border="0">  
</a>


If you change it to:

<a
Visible='<%# (Convert.ToInt32(DataSet1.FieldValue("InStock", Container)) > 0) %>'
href='<%# "AddFromDB.aspx?ProdID=" + DataSet1.FieldValue("ProductID", Container) %>' runat="server">
<img src="../images/Cart.gif" width="100" height="22" border="0">  
</a>


The add to cart button for each product will only display if the InStock field has a value more than zero.

There are potential problems associated with stock management in a website, rather than cover this here you can read about them in the main cart documentation under the following location:

 
WebXelCart NameSpace > Server Controls > StockManager > About Stock Management