Designing a Merchant Server Page
Suppose you are writing a page to display items of a selected brand that are available from your
store. You include your common header and footer, common images (such as your logo on the page), and
product images. The page looks like Listing 1. Let's go over this code.
First, pgen inserts the header file by finding header.html and inserting it in the include
file. The Merchant tag shown in callout A is a SQL Server directive to get information from your
database. The fetchrows tag grabs data from your SQL Server database and places it into the
productinfo object. You can use the powerful fetchrows tag in several ways. The syntactical format
for using fetchrows is:
[fetchrows nameForReference valRQuery valRArg1...valRArgN]
Using this syntax, nameForReference is the variable name that will contain the returned
data result set, and valRQuery is the reference name of the query in the SQL data table (the
table name is defined in the Registry; the ADD STORE feature in the Control Panel applet created the
table name for you if you used ADD STORE). The valRArg1...valRArgN terms are arguments
Merchant Server will pass to the SQL Server in the query.
In your database, in the SQL table that you defined (in the Registry key Database, Value
Db_table_sql) to store predefined SQL statements, the name column contains the reference name for
the query in the sql_text column. For example, the name selected-brand in the SQL table
refers to select * from me_brand where brand_id = convert(numeric,:1) in the sql_text
column.
In this example, you can use
[fetchrows brands "selected-brand" 2]
to call the brands object, which contains all the information from the me_brand table, where
brand_id = 2. To reference variables passed in the SQL table, use the :N argument in the
table (where N is the argument being passed). Use this variable for each argument you want to send,
incrementing by one for each argument you want Merchant Server to process (e.g., :1, :2, :3). Use
this variable only in the sql_text entry in your sql table. Also note that the Merchant System sends
all variables using the fetchrows tag as text, so you have to use the convert(numeric,:1) function.
You won't need that function if you want to match a text variable.
Now that I've explained the fetchrows tag, I need to talk about args.brand_id in the example.
The args object contains all the variables from the page that called this page and posted values to
this page. If you were on the previous page and you need to send the brand_id value to this page,
you can use the Merchant link tag to send the value easily. For the link to the next page, you can
write
[form "thebrands.html" brand_id=brands]
<select name="brands">
[option "NCR"] 1
[option "Compaq"] 2
</select>
[/form]
Or you can write
[link "thebrands.html" brand_
id=2]Go to brands page for Brand
2[/link]
This directive not only sends you to the page "thebrands.html," but it also includes
the value for brand_id.
The args.object and the var.object differ in that a posting form passes the args.object, and
the Merchant let tag creates the var.object. For example,
[let cool_brand 2]
assigns the value 2 to var.cool.brand. When tagged such as
Sally uses brand [value var.cool_brand].
pgen outputs
Sally uses brand 2.
Now, back to the code. The directive [if brandinfo.img_file !="none"] applies a bit
of logic to the code. In this example, if brandinfo.img_file is not equal to "none,"
Merchant Server executes the first part of the if statement:
<IMG SRC="[simg]/products/[value brandinfo.img_file]" BORDER=0>
After pgen gets through with this line, it looks like
<IMG SRC="imagepath/products/
cool_brand.gif" BORDER=0>
Merchant Server is doing two things here. First, it is expanding the simg tag that represents
the path to your server's shared image directory. Second, it is expanding value brandinfo.img_file
to equal the value stored in the brandinfo recordset item named img_file. In this case, the
value is the name of the corresponding image file for this brand.
Notice the code at B in Listing 1. This code uses the xlink directive, which has syntactical
format
[xlink action argName1=value
RArg1...argNameN=valueRArgN]
The xlink directive is similar to the link tag with an important difference. When you click the
output text between [xlink] and [/xlink], Merchant Server performs an action instead of going to a
page directly. In this case, that action is order.additem, and I am sending that action a named
argument--in this case, sku=productinfo.sku. This code will generate a list of products, each with a
unique xlink to the order.additem action, adding the product selected to the order. Merchant Server
will execute whatever the action order.additem defines in the Registry. This function is handy,
especially if you perform the same functions frequently. In this example, the argument passed is the
sku of the product you want to add to the current order.
The eachrow tag syntax,
[eachrow NameForReference valueRStart valueREnd]
tells pgen to take the object that NameForReference references (starting at row 1 or a
select row range, hence valueRStart valueREnd), usually a recordset of some type, and flip
through each row of data it contains, one at a time, until the end of the recordset is reached.
Think of this process as a loop for your data, or if you are familiar with DAO, a Do loop for your
recordset with a built-in MoveNext command. This example displays a list of products.
At the end of B in Listing 1, you see the money value display tag:
[money productinfo.list_price]
The syntactical format for this tag is
[money valueRAmount valueRLocale valueRScale]
You use this tag for converting a value (valueRAmount) into money. Using the optional
arguments valueRLocale and valueRScale, you can override the Registry defaults for
money location and scale to that of any country that Merchant Server supports. Although using the
Merchant Server directives might seem complicated at first, you'll soon catch on. The results are
worth the initial effort. Screen 1 is an example of a page created with Merchant Server.
From Mom and Pop to a Mall
Merchant System is a scalable product. You can use it to start a small store, and it will grow
with you, with almost no growing pains. For example, my mother can use Merchant Server to display
her needlepoint patterns in an online craft store--a small business. This exposure will be great for
her company. At the rate she generates patterns, she'll want to continually update the online
catalog to keep her customers interested. When she makes it as big as Trudy & Jenny's Stitch
Patch, she can easily migrate to a distributed system to keep the Web site running smoothly, without
delays. She can even open a virtual mall and rent space to anyone--from Rhoda next door to Crabtree
and Evelyn. The possibilities are virtually endless (pun intended). Best of all, Merchant Server is
easy to maintain. Once it's up and running, it's up to stay. Merchant Server's stability is a good
thing: I hate to think what would happen if my mother's server went down.