| QWK | QwkTIF |
Documentation for version 2.001001.
Copyright © 2004-2005, QwkSoft. Licensed to 4TheBest eCommerce Solutions.
QwkTif enables you to output text/html/javascript on the invoice screen with tokens being substituted for dynamic data, including all global and system Miva script variables, all of the shipping or billing information for the shopper, and other select values related to the order such as the order total and order number. This is very useful for generating dynamic links to external applicaitons and passing dynamic data to them, this can be done both as a link the shopper has to click on, or as an automatic an transparent link using html script tags and other similar tecniques.
The QwkSoft Tokenized Invoice Footer distribution contains 2 files: qwktif.mvc and qwktif.html (this documentation file). Install the *.mvc file in your domain and store as usual for Miva Merchant modules. Please refer to the documentation for your version of Miva Merchant for more information.
note: if you are using a non-compiled version of Miva Merchant you will need the non-compiled version of this module. That distribution contains *-nc.mv files in place of *.mvc files.QwkSoft Tokenized Invoice Footer is a Order Fulfillment module. Order Fulfillment Configuration Screen
This module places 2 tabs on the Order Fulfillment Configuration Screen. This screen can be reached from the left navigation bar by selecting Stores->your store name->Order Fulfillment Configuration
(Some tabs may not be visible at all times)
This is the text and HTML that you want to appear at the bottom of the invoice screen when a customer has placed an order. There are a number of available tokens listed below. Tokens are delimited by percent signs, so if you want to put a percent sign in the text you must escape it using a second percent sign. For example, to show the text "All products 10% of in May" you would type "All products 10% off in May"
Enter licensing information here. Please note that once you have entered your license information this tab will no longer be visible.
Enter the license number that you were issued when you purchased this software.
Check this box if you have read and and agree to the EULA. You must agree to the EULA to use this software.
Some fields are tokenized. This means that some of the text will be replaced with dynamic values. The text that gets replaced is called a token and is identified by percent signs. For example, if the token "replacement" had a current value of "Token" this: Example of a in text would display like this: Example of a Token in text.
50% off as an attempt to used the token " off". Instead type 50%% off which the parser sees correctly. If you had a token called "percent_off" and you wanted to display it's value followed by a percent sign you would type something like this: Buy now and get %percent_off%%% off.
There are five types of tokens: System Variable Tokens, Global Variable Tokens, Database Variable Tokens, Internal Variable Tokens, and Command Tokens.
System Variable Tokens
These are tokens that have a name exactly the same as an existing Miva script system variable, and always start with "s." ( you can also use "system." ). These are usually values that are either generated on the server or sent by the user agent (usually a browser) in the HTTP request headers. For example to display the ip address of the person visiting the store you can use a token like %s.remote_addr%. Below are some examples of Miva script system variables but for a full list you should review the Miva script reference manual in the documentation section of Miva's website.
| s.server_name | The server name for the server. This may be the same as the domain name for your website, but it may not. |
| s.remote_addr | The ip address for the current shopper. |
| s.remote_host | The host name the browser sent a request from, if available. |
| s.request_method | The http request method used to communicate to the server, usually POST or GET. |
| s.query_string | The string of name value pairs on the url after the question mark, if any. |
| s.http_Referer | The url for the web page the shopper was on right before the current page. |
| s.http_User_Agent | The user agent, usually a web browser, that the shopper is using. |
| s.http_Host | The domain name the browser thinks it is communicating to. |
| s.http_Cookie | The cookies made available to the server. |
| s.tm_hour | the current hour of the day. |
| s.tm_min | The current minute within the current hour. |
| s.tm_sec | The current second within the current minute. |
| s.tm_mday | The numerical day of the current month. |
| s.tm_mon | The numerical month of the current year. |
| s.stm_mon | The short string version of the current month (e.g. Jan, Feb, etc.) |
| s.tm_year | The decimal current year. |
| s.tm_wday | The decimal day of the week. |
| s.stm_wday | The short text day of the week (e.g. Mon, Tue. etc.) |
Global Variable Tokens
These are tokens that have a name exactly the same as an existing Miva script global variable, and always start with "g." ( you can also use "global." ). These are usually values that are passed in to Miva Merchant on the url or from a form post. This would include things like the product code added to the basket %g.product_code%, or it's quantity %g.quantity%. Or a special value you are passing to a new screen, or a value being set by another module, or a value being set internally in Miva Merchant such as the current cookie value. Here are some examples of global variables you can use as tokens.
| g.Session_ID | The cookie based session string that is used to identify a visitor, and also used passed on the url when switching to a secure server using a different domain name than the normal server. |
| g.sessionurl | The current full url to the store. |
| g.secure_sessionurl | the current full secure url to the store. |
| g.baseurl | The base url for graphics used in the store. |
| g.secure_baseurl | The secure base url for graphics used in the store. |
| g.Affiliate | The affiliate code passed to the system from an affiliate linking in. |
| g.Basket_ID | The internal basket id number used by Miva Merchant for the current shopper. |
Database Variable Tokens
These are tokens that have a name exactly the same as the name of a valid database variable name. These tokens start with the alias of the table then have a ".d." then the field name. The table must be opened at the moment the token is used, and have been opened by the alias you are referencing it by and the value you will get will be from the current record that the Miva engine is pointing to. These constraints make these tokens have a fairly limited use, but one example of a safe use is to call any data of the records for the current store in the stores table. For example to get the current store name you could simply do %stores.d.name%. Below is a list of all the valid database variables from the stores table. This table is always open and always pointed to the current store.
Internal Variable Tokens
The most important tokens you can use though are the tokens that the software makes available to you. These are more complex than simple tokens because they are often lists of values, such as all the items in the current order, or all products in the store. These tokens don't always start with any particular value but are grouped into named groups and the format of these tokens is usually %group:token% where "group" is the name of a valid token and "token" is the name of a sub token of that token. For example you can use %basket:ship_zip% to get zip code the shopper has entered, if any. A full list of all Internal Variable Tokens can be found in the section of this document titled Internal Variable Tokens List.
Cascading Variable Tokens
You can cascade variable tokens by listing multiple variable names. This will display the value of the first token with a value. For example, %image thumbnail% with display the value of image if image has a value, or the value of thumbnail if image does not have a value. There is no limit to the number of token names that can be used in a cascade.
The last value in a cascade can be a quoted string. If none of the variables in the cascade has a value, the string is used instead. Either single or double quotes may be used, but the same type of quote must be used at the end of the string. Double quotes can appear within single quotes, and vice verse. If you need to use a single quote inside a single quoted string, then use two single quotes in a row to signal the parser that it's not the end of the string. The same works with double quotes. For example %image thumbnail 'didn''t find an image'% will display didn't find an image if there is no value for image or thumbnail. %image thumbnail "didn't find an image"% would do the same
Command Tokens
The power of Internal Variable Tokens becomes more obvious once you understand command tokens. Command tokens bound text and other tokens. Command tokens have a starting token and an ending token and everything inside the two is constrained in some way by the command token. The starting command token is prefixed with a "#" and the ending command token is prefixed with "#/". Thus a simple command token looks like this %#command%command area%#/command% where "command area" contains text and tokens that are affected by the command token. The only command token that can stand alone is the block command token, all other command tokens must be contained inside the command area of a block command. Here is a list of command tokens: block, head, foot, body, first, last, body_pre, body_post, body_alt, body_alt_pre, body_alt_post and alt.
The block command token
The block command token is special among all command tokens in numerous ways. It is the only command that can stand on its own without any other commands, and it is the only command that can contain any command token in it's command area and can be contained in the command area of any other command token's command area. That is, you can place a block in a block, an alt in a block, and a block in an alt, and all are meaningful, but placing an alt directly in a head, or a head directly in an alt is meaningless. The block command determines the data available to tokens inside it by reading a token name that is passed to it as a parameter. If the token has a value then the body of the command area is displayed, otherwise nothing is displayed, unless an alt command tag was used in the command area in which case the contents of the alt command token's command area is displayed. If that token happens to be a list of values, then the body of the command area gets displayed once per item in the list. Inside the command area for a block command the token that the block command read can be referenced as %:% and any sub tokens can be reference as %:subtoken%. For Example:
%#block basket%
-- Displays the same data as --
%#/block%
Using multiple colons backs up to the parent variable, like so:
%#block basket%
%#block :item%
%#block :option%
%basket:item:code% -- Displays the same data as -- %::code%
%#/block%
%#/block%
%#/block%
For example if you did %#block basket:ship_zip%This is being shipped to the zip code %:%.%#/block%, if there was a value to the shipping zip code for the current shoppers basket the contents of the command area would be displayed, otherwise nothing would be displayed. Additionally you could have added an optional alt command token into your block command area and anything inside the alt command area will only be displayed if the body of the block command area is not displayed. Note that if the only command tokens used inside the command area are alt, head, foot, or another block, you don't have to place the body contents inside an actual body command token because the system will assume anything not nested in one of the other command tokens is part of the body. But if you are using body, first, last, body_pre, or body_post, the contents not inside a command token command area will be ignored.
Here is another example that demonstrates the use of the alt command.
%#block basket:ship_state%
This is being shipped to %basket:ship_city%, %:% %basket:ship_zip%.
%#alt%
We don't know where this will be shipped yet.
%#/alt%
%#/block%
The token name used to control the block can be cascaded, but a terminating quoted literal can not be used ( that's what the alt tag is for ). For example, this code will display an image using either the source specified by the
%#block image thumbnail% Multiple Alt Commands
%#block image thumbnail% Displaying Lists. Here is an example of a token code that would display the full-size images for all products.
%#block products%
But what if some of the products don't have a full-size image? how do you stop it from displaying a broken image? You do that by using another block command inside the first block Like this.
%#block products%
If you wanted to you could place an alt command token inside the inner block so that a default image was displayed if there was no image, or a bit of text could be displayed, or whatever you wanted.
Lists In Lists.
%#block basket% Body_Alt
%#block products%
The alternations can be at any frequency. For example, to display product names in 5 columns, you could do something like this:
%#block products% The pattern repeats, so in the above example the 1st, 6th, 11th, etc. products will be displayed using the format specified by The parser assumes that the cycle repeats at frequency equal to the largest pre and post
%#block products%
For completeness, there is a #body_pre and #body_post which are used around the body when no alt applies.
First, last
Remember
Token blocks do not have to be on separate lines so if you want your final output to contain no line breaks or extra space you can run it all together with no gaps and the token parser will understand it just fine. For example if you were trying to dynamically generate a url that had a comma separated list of product codes ordered you could do it like this:
%#block invoice%http://www.4thebest.com/miva-script-examples/echo.mvc?order=%:id%&products=%#block :item%%#first%%:code%%#/first%%#body%,%:code%%#/body%%#/block%%#/block%
Formating
The various pad commands take one required and one optional argument. The first argument is the size, and the second is the pad character. The pad character defaults to spaces. This example pads each product line to a size of 80 characters, with the extra characters being added to the right:
%#block product #padr 80%Put a bunch of stuff here%#/block%
This example pads the price to a size of 10 with zeros to the left:
%price #padl 10 0%
image or thumbnail token, of the text "no image available" if there is no image or thumbnail
<img src="%:%">
%#alt%
no image available
%#/block%
The alt command can be conditioned in much the same way as a block command, and multiple alt commands used. For example, the following code displays the image specified by the image or thumbnail token, or the text specified by the text token, or the literal "there is no image or text"
<img src="%:%">
%#alt text%
%:%
%#alt%
there is no image or text
%#/block%
If the token past to the block command is a token that represents a list of values then the command area is used for each item in the list. Further you can use the head and foot command tokens to display something before and after the list if there is something in the list, first and last, to control display of the first item or last item in the list, body_pre, and body_post to control the display of something before and after each item in the list. Note: if you are using the first command the body_pre and body_post won't display for the that item, and if you are using the last command the body_pre and body_post won't display for the that item.
<img src="%:image%">
%#/block%
%#block :image%
<img src="%:%">
%#/block%
%#/block%
Some tokens that are lists will also contain sub tokens that are lists. a good example of this is the basket token which contains a token called item which is a list of items in the basket, and each item has a token called option that contains the options for the item. Here is a complex example of displaying the basket contents
%#body%
<table>
<tr>
<td>
<b>Code</b>
</td>
<td>
<b>Name</b>
</td>
<td align="right">
<b>Price</b>
</td>
<td align="right">
<b>X Price</b>
</td>
<td align="right">
<b>Quantity</b>
</td>
<td align="right">
<b>Total</b>
</td>
</tr>
%#block :item%
<tr>
<td>
%:code%
</td>
<td>
%:name%
</td>
<td align="right">
%:price%
</td>
<td align="right">
%:item_price%
</td>
<td align="right">
%:quantity%
</td>
<td align="right">
%:line_price%
</td>
</tr>
%#block :option%
<tr>
<td>
</td>
<td>
%:data_long, :data, :opt_code, :attr_code%
</td>
<td align="right">
%:price%
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
%#/block%
%#/block%
<tr>
<td align="right" colspan="5">
Sub Total:
</td>
<td align="right">
%:subtotal%
</td>
</tr>
%#block :charge%
<tr>
<td align="right" colspan="5">
%:desc%:
</td>
<td align="right">
%:disp_amt%
</td>
</tr>
%#/block%
<tr>
<td align="right" colspan="5">
Total:
</td>
<td align="right">
%:total%
</td>
</tr>
</table>
%#/body%
%#alt%
Couldn't find session id %g.session_id%
%#/alt%
%#/block%
The #body_alt allows you to display alternate code on a cyclic basis. For example, if you wanted to display alternate lines of a table differently, you could do something like this:
%#head%<table>%#/head%
%#body%<tr class = "plain"><td>%:name%</td></tr>%#/body%
%#body_alt 2%<tr class = "tinted"><td>%:name%</td></tr>%#/body_alt%
%#foot%</table>%#/foot%
%#/block%
%#head%<table>%#/head%
%#body%<td>%:name%</td>%#/body%
%#body_alt 1%<tr><td>%:name%</td>%#/body_alt%
%#body_alt 5%<td>%:name%</td></tr>%#/body_alt%
%#foot%</table>%#/foot%
%#/block%
body_alt 1, while the 5th, 10th and 15th products will be displayed using the format specified by body_alt 5.
body alt specified. You can explicitly set a higher frequency using body_alt_max, for example %#body_alt_max 7%.
If your #body is at all complicated, entering the #body_alt can be tedious and error-prone. The body_alt_pre and body_alt_post allow you to specify extra formating that appear before and after the body on some lines. The above example could be rewritten as follows:
%#head%<table>%#/head%
%#body%<td>%:name%</td>%#/body%
%#body_alt_pre 1%<tr>%#/body_alt_pre%
%#body_alt_post 5%</tr>%#/body_alt_post%
%#foot%</table>%#/foot%
%#/block%
#first and #last replace the formating on #body for the first and last item.
%#alt%Data inside an alt only appears if there is no body data to display for the block%#/alt% and you can explicitly declare what should be in the body by wrapping it in a %#body%body command%#/body%, and if you use the body command you can then specify what is output in only certain cases such as %#body_pre%This will appear before each body is displayed, except the first/last one if you are using the first/last command.%#/body_pre% and %#body_post%This will appear after each body is displayed, except the first/last one if you are using the first/last command.%#/body_post%, and %#first%this will appear for the first record only%#/first%, and %#last%this will appear for the last record only%#/last%, and %#head%this appears before all the body data appears.%#/head%, and %#foot%this appears after all the body data appears%#/foot%.
Any token, commands included, can accept formatting directives. These give the parser special instructions on how to format the displayed data. Formating commands are listed after the token name(s) and literals. For example: %image #att% displays the value of image attribute encoded. The available formatting options are:
#att - attribute encode
#ent - entity encode
#padl - pad the result to the left
#padr - pad the result to the right
#padc - pad the result to the center
%code #padl 30 #att%
Cascading works with formating. This will display image, thumbnail, or 'no image' centered in a space 100 characters wide with 5 dashes at either end:
%image thumbnail 'no image' #padc 90 #padc 100 -%
Here is a list of all available tokens.
| Token | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| affiliate | This is the token group with all information regarding the currently logged in affiliate, if any. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| basket | This is the token group containing all the data on the current basket contents. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customer | customer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| order | This is the token group containing all the data on the order that has an ID equal to the current value of the global variable g.order_id. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| invoice | This is the token group containing all the data on the order for the current invoice. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| products | products | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| product | product | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|