Getting Started with Microsoft Merchant Server

Doing business on the Internet is tricky. To keep up with the competition, you need an online store displayed in attention-grabbing Web pages. You need to continually update product information at minimal cost and with little down time. You need a secure payment system. To do all these things and more, Microsoft offers Merchant Server.

Merchant Server is a complete system for doing business on the Internet with flair. Merchant Server is a Windows NT Server-based management product that lets you create compelling Web sites for marketing products and use a relational database to offer personalized service. Although Merchant Server does not magically create an online store overnight, it offers example stores to help you set up your site quickly and easily. Let's look at some of Merchant Server's advantages, its components, setup and installation, the included example stores, and a Web page designed with Merchant Server's directives.

The Merchant Server Store Merchant Server lets you create a responsive online store for your company. It offers a convenient shopping experience for your customers and a secure credit card payment system. One of Merchant Server's greatest advantages to sellers is its ability to target customers. Merchant Server's extensive order tracking system lets you offer special bargains to your customers based on their past purchases, and suggest items related to your customers' current purchases (cross-selling) or suggest similar items of better quality (up-selling). For example, if someone buys a hard disk, you can suggest other items needed to install it--a Y power cable, extra ribbon cables, and so forth. Because you can develop customer profiles, you can target specific markets for sales or other marketing efforts. Merchant Server has several other attractive features:

Support for Java and ActiveX technology--You can take advantage of today's technology. For example, you can use Merchant Server's Page Generator (pgen) features to combine several Web pages into one.

Multiple stores on a single server--You can develop a virtual shopping mall by leasing space to smaller companies that can't afford Merchant Server and the equipment to run it.

Scalable and extensible--You can keep the store on one server or distribute it over several servers to provide load balancing for heavy hitters. Like most other Microsoft products, Merchant Server is extensible through Open API. This API is valuable for integrating Merchant Server with in-house systems (such as inventory fulfillment) and other software vendor components.

Instant changes--You can change information dynamically so that price changes in the database are online instantly, without rebooting the system. You can create sales and promotional offers on the fly.

Flexible data schema--You can reference your products from various formats, such as Microsoft Word or Microsoft Excel. You can generate product pages from your existing database.

Open data interfaces--You can access product information from current databases via the Open Database Connectivity (ODBC) standard or use a separate database for Internet products.

Microsoft doesn't tie Merchant Server's payment mechanisms to any specific online payment system (such as the included software from VeriFone). Instead, Microsoft continues to work with third-party online payment providers so you have a choice of providers. Payment provision is a separate service; if you choose direct online payments, you need to set up a system with a third-party company and your financial institution.

Setup and Installation To install Merchant Server, you need to be familiar with NT Server, Microsoft Internet Information Server (IIS), relational databases and database management systems such as Microsoft SQL Server and ODBC, and configuration management with the Registry Editor. Merchant Server requires NT Server 3.51 or 4.0, IIS 1.0C or later, an ODBC-compliant database, 64MB of RAM, 55MB of available hard-disk space, and TCP/IP networking protocol. If you don't install and run SQL Server during Merchant Server setup, Merchant Server will not install the starter stores. You can install the starter stores later, but doing everything at the same time is easier and less confusing.

Before you install Merchant Server, create a database device and a database on your SQL Server for each of your stores (using SQL Server Enterprise Manager) and create a data source name (DSN) for the database (using the Control Panel ODBC32 Item). Keep the data device names and DSNs simple, short, consistent, and handy.

Installations are either single server or distributed on many machines. Some distributed installations require additional licenses, depending on your intended use. In a multisystem installation, Merchant Server Setup initially installs the starter store content (templates and element files) and the system assets (images and ActiveX controls) on the system. The assets contain the Controller, which stores Registry information for all Merchant Server components, and the Router, which communicates with IIS. Then systems administrators copy the content and the assets onto the Store Server. (The Merchant Server documentation provides complete details and suggestions for the best ways to perform each type of installation.)

Installations are custom or complete. In a custom installation, you select only the starter store and the merchant components that you designate. In a complete installation, you install all Merchant Server options. Complete installations are great training for beginners on development servers.

Installing Merchant Server is easier than installing a Microsoft Office application. You need to keep handy the names of the database devices you created for your starter stores and the DSNs you've designated for database connectivity. Merchant Server prompts you to match the DSNs and database device names to the stores. After you install Merchant Server, you can copy the starter stores and modify them to create your stores, in a fraction of the time you could create stores from scratch. If you have space, install all the starter stores on your development server. When you create your production server, copy only the code you plan to publish on the Web. This code will be your live store.

Example Stores To save time when you design your first Merchant Server site, use one of the starter stores that Microsoft includes with the software. Starter stores are partly templates and partly operational samples that you can modify to fit your site. These example sites include Clockpeddler--a clock store--which is a very simple store and a great site for getting started. Adventure Works--a store for the rock climber--is a more advanced site for the intermediate to advanced Merchant site engineer; this site gives you a good feel for the product.

Adventure Works contains many features that most businesses use in a standard department or class-type product environment. For example, a department store has departments, such as accessories, and the departments have classes of goods, such as hats, belts, gloves, and so on. In this environment, a customer selects the department, the class within the department, and specific items within the class.

The Volcano Coffee site is more complex; it contains many robust features of HTML and the Merchant System and provides quite a challenge. The Microsoft Press Online Bookstore site is amazingly similar to the real Microsoft Press Online Store (http://www.microsoft.com/mspress/books/b.htm). Take advantage of these examples as patterns to help you design your store quickly.

Registry Keys Installing Merchant Server sets certain keys in your system Registry. If you have to alter the Registry key values that the Merchant System uses, you need to know where to find them. (See the program documentation for information about all the keys that Merchant Server uses.)

Store Registry keys represent the installed example stores. Open the Registry Editor (regedit), and go to an example store site. Start looking from the root key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MerchantServer\Stores. The next level of keys contains keys that represent specific example stores, such as ClockPed and AdvWorks. Look under the store name you want for the example key settings. All key settings are in the Merchant Server documentation.

You can use the ADD STORE feature of the Merchant Administrator tool (a Control Panel applet) to automatically generate a new store based on an existing store. An alternative is to manually copy a store; if you do, be sure to copy (export using regedit) the Registry keys for that store starting with the top-level key, which includes the store's name. You also need to create a DSN entry in your NT Server's ODBC setup.

Setting Up Your First Site Start by reading through all the documents in the Merchant Server CD-ROM, noting areas that interest you and then printing the code for an example site. Read through the code with the technical reference document handy to understand how Merchant tags are similar to and different from HTML. Gradually replace the references to the starter store with references to your store and its products. Then modify backgrounds and artwork, and jazz up the site with animation and sound. (Always make backups before you make changes--you knew that, right?)

Once you get through the example sites, you'll find Merchant-tagging (my term for writing Merchant code) a snap. As with HTML, you use tags to implement Merchant directives and commands. Unlike HTML code, which is static, Merchant tags in brackets tell pgen what to dynamically transform into the HTML code that clients see at their browsers. Merchant tags automatically update pages when Merchant Server retrieves new data (e.g., inventory changes).

Although tagging gets easier with practice, you can make simple mistakes. To avoid mistakes, make templates for pages that you write frequently and make element pages (such as headers, footers, or common pieces of HTML and Merchant tags) to store until you need them. Template refers to a page that Merchant processes; a template is the Merchant Server pgen source code.

Several code tags, elements, and components are important to Merchant Server and to each Merchant site. The major components of Merchant Server include

The pgen component, which dynamically generates HTML pages in response to HTTP POST or GET instructions from a browser

Action Manager (xt), which executes actions (such as functions) that perform tasks such as database modification

Order Processing Component System, which handles order checking, initialization, price adjustments, shipping, handling, taxes, payment, acceptance--anything that has to do directly with the order

The pgen component uses directives (Merchant tags) to dynamically generate the content of the target HTML page. (Directives are case sensitive.) For example, a directive to create a link to another HTML page might look like \[link "newproducts.html"\]Go to new Products\[/link\]

From that code, pgen produces an HTML line <A HREF="newproducts.html">Go to new Products</A>

Directives fall into six categories: value display, for generating text for inclusion on a Web page (e.g., \[date\]); conditional, for flow control (e.g., \[if\] \[else\] \[/if\]); convenience, for creating value references for a later time (e.g., \[include\]); navigational, for navigating the site (e.g., \[xform\]); database access, for using a database (e.g., \[fetchrows\]--a personal favorite); and order, product, shopper, receipt access, for transactions (e.g., \[fetchorders\]). These categories contain roughly 45 directives (knowing Microsoft, more are probably on the way). Some example tag lines will give you an idea of how to implement directives.

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.

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.