| West Wind Web Store |
| Custom Item Sub-Types |

When you select a color here this information is then passed forward into the LineItem and shows in the shopping cart as follows:

To add this sort of functionality involves two steps:
Let's see how to do this.
Change the TYPE field to a type that makes sense. In this case I'll call this SHIRT. Then change the lDescript field to include some HTML that will actually be used in the page and add HTML input fields that have names that start with shirt<fieldname>:
Please select the size for the shirt: <SELECT name="shirtSize"SIZE="1"> <option>Large <option>X-Large <option>Medium </SELECT> <br> Please select a color for the shirt: <SELECT name="shirtColor"SIZE="1"> <option>White <option>Gray <option>Yellow </SELECT> <hr> <img src="itemimages/tshirtfront.jpg" align=left> Show your support for Web Connection with a styling Web Connection T-Shirt. Front and back design with a pocket Web Connection logo on the front and a "Making Waves on the Web with Visual FoxPro" slogan on the back. Available as T-Shirt, Girl's T-Shirt, Long Sleeve T-Shirt and Sweat Shirt. <img src="itemimages/tshirtback.jpg" align=Right> Please specify size (M,L,XL) in the notes field when placing the order.
Web Connection automatically parses the fields that match the SHIRT prefix in this case and creates a string that fills the 'extraText' field in the new lineitem. The actual data for the fields captured is stored as a property in the XML field which can be retrieved with oLineItem.GetProperty("shirtSize") and oLineItem.GetProperty("shirtColor").
The code to accomplish this is actually quite simple and handled by the Web front end code in AddItem.wws:
IF !EMPTY(loItem.oData.Type)
DIMENSION laVars[1,2]
lnItems = Request.aFormVars(@laVars,loItem.oData.Type)
FOR x=1 TO lnItems
loItem.SetProperty(laVars[x,1],laVars[x,2])
loItem.oData.ExtraText = loItem.oData.ExtraText + ;
"<br>" + STRTRANC(laVars[x,1],TRIM(loItem.oData.Type),"") + ": " + laVars[x,2]
ENDFOR
ENDIF
Note that if you allow editing this stuff, there's more work involved as you have to have some knowledge of what fields are available up front in order to display UI for this. The Web Store Offline application does this actually when editing items of this kind. The following code demonstrates how the editing ui handles these custom types.
IF loLItem.oData.Type = "SHIRT"
lcSize = loLItem.GetProperty("shirtSize")
IF ISNULL(lcSize)
lcSize = ""
ENDIF
lcSize = InputForm(PADR(lcSize,5),"Enter Size for this order",WWSTORE_APPNAME,,,,"*CANCEL*")
IF lcSize # "*CANCEL*"
loLItem.SetProperty("shirtSize",lcSize)
IF !EMPTY(lcSize)
lcExtraText = lcExtraText + "<br>Size: " + lcSize
ENDIF
ENDIF
ENDIF
This sort of thing can become extensive if you have more than a few different of these types, but it's worth it for the flexibility it provides.
Last Updated: 06/02/03 |
Send topic feedback