The item category page handles displaying all items in a given category or displaying results from a search query in a list you can choose from.

Url Example: Itemlist.wws?Category=Web+Connection

The page displays a list of all the items that match a given category and is also used to display the results from a search query:

To reach this page you can click any of the Category links from the left hand frame of the application. You can also arrive here when you run a Search query - the same page is used to display items that match the search filter provided.

Behind the scenes this method is fairly simple - it calls into the cItem business object and uses its GetCategoryList() method to retrieve all the items that match the category specified on a URL such as this:

ItemList.wws?Category=Web+Tools

The code in the class that handles this looks like this:

FUNCTION ItemList
LOCAL oSC, loItem
PRIVATE pcCategory, pcBannerText

*** Add Cookie Check session var - in case people jump directly
*** to the list page as their first page
Session.SetSessionVar("CookiesOn","True")

pcCategory = Request.QueryString("Category")

loItem = Create([WWS_CLASS_ITEM])

#IF WWSTORE_USE_SQL_TABLES
loItem.SetSQLObject(Server.owwStoreSQL)
#ENDIF

loItem.cSQLCursor = "TItemList"

*** Get only Web items
IF loItem.nDataMode = 0
   loItem.GetCategoryList(pcCategory,"sku,descript,price,stock","!noweb")
ELSE
   loItem.GetCategoryList(pcCategory,"sku,descript,price,stock","noweb=0")
   IF loItem.lError
      THIS.ErrorMsg(loItem.cErrorMsg,loItem.oSQL.cSQL)
      RETURN
   ENDIF
ENDIF

*** Handle XML Result
IF THIS.nResultMode = 2
   THIS.ReturnCursorXML("items","item")
   RETURN
ENDIF

*** Reformat the cursor for display with showcursor
SELECT PADR([<a href="item.wws?sku=] + TRIM(sku) + [">] + ;
       TRIM(descript) + [</a>],100) as Description,Price,;
       PADR([<a href="additem.wws?sku=] + TRIM(sku) + [&qty=1">] + ; 
       [Add</a>],60) as Buy ;
   FROM TItemList ;
   INTO Cursor TItemList2

LOCAL loSc as wwWebStoreShowCursor
loSC = CREATE("wwWebStoreShowCursor")

IF RECCOUNT() > 15
   loSC.nPage_ItemsPerPage=15
   loSC.cPage_PageURL="ItemList.wws?Category=" + pcCategory + "&"
ENDIF

loSC.ShowCursor()
pcItemList = loSC.GetOutput()

USE IN TITEMLIST
USE IN TITEMLIST2

Response.ExpandTemplate( Request.GetPhysicalPath() )
ENDFUNC
* wwStore :: ItemList

Couple of interesting things happen here. First off the business object in this case returns a VFP cursor to use that contains the selected items. Notice the code that checks for nResultMode = 2 (XML response). If the user typed:

ItemList.wws?Category=Web+Tools

he can get an XML result that returns XML as follows:

<?xml version='1.0'?>
<wwstore>
<items>
	<item>
		<sku>WWIPSTUFF</sku>
		<descript>West Wind Internet Protocols</descript>
		<price>99</price>
	</item>
	<item>
		<sku>WEBSTUDIO</sku>
		<descript>Web Connection  Visual WebBuilder Builder Bundle</descript>
		<price>699</price>
	</item>
</items>
</wwstore>

An external application could thus easily query what items are available for each category.

If we're not using XML output we need to format the table shown in the figure above and the easiest way to do this is to use the Web Connection ShowCursor object which builds an HTML table from a VFP cursor. In order to display the cursor nicely another SELECT statement is run to reformat the output from the cursor so it includes hyperlinks and also the Add button which lets you directly add an item to your shopping cart.

ShowCursor in this case is used to generate a string of the table to display with:

loSC.ShowCursor()
pcItemList = loSC.GetOutput()

and <%= pcItemList %> is then embedded into the HTML template. Also the value of <%= pcCategory %> is used to display the header for the page.

Notice that I'm using a custom subclass of ShowCursor called wwWebStoreShowCursor. I'll use this version for each and every showcursor display in the store in order to achieve a common look and feel for all lists. The colors and alternating colors and other setup values are all pre-configured in this object so I don't have to set them in multiple places. This makes it easy to change the look and feel of the app quickly. Using Stylesheet tags for each of the tags too helps to make this more consistent.

DEFINE CLASS wwWebStoreShowCursor as wwShowCursor

cTableBorder = "2"
cCellPadding = "3"
cExtraTableTags = [ class="tablebody"]
cHeaderColor = "White"
cHeaderBGColor = "Navy"
cTableWidth = "95%"
lAlternateRows = .T.
cALTERNATINGBGCOLOR = "#CCCCFF"

ENDDEFINE

Searching uses the same concept


The itemlist.wws HTML template is also used by the wwStore::Search method which work very similar to the Itemlist method. It uses the business object a little differently by building a filter string from the Search input field (on the left frame of the store).

lcFilter = '[' + lcSearch + '] $ lower(descript) OR [' + lcSearch + '] $ lower(ldescript) '

loItem = Create("cItem")
loItem.cSQLCursor = "Tquery"

*** Get a category list for all cats and add the search filter
loItem.GetCategoryList("","sku,descript,price",lcFilter)

The rest of the code is almost identical to that in ItemList except that the pcCategory PRIVATE variable is set to "Search Results".



Next: The Item Display Page


Last Updated: 06/02/03 | Send topic feedback