1) In the main part of the INVC page template you can add lines like below. The order_customer and
order_contents items are already on the page. You are adding toolkit items before and after the
existing items.
The exportxmlbegin initializes the export file and must occur only once and is before any of the
exportxml items.
The exportxmlend item is run after all of the exportxml items have completed. It accumulates
the exportxml and makes the actual export to the designated file (2nd parameter in the item).
As you can see in this example, it sends the content to the basket.dat file (you can use any
name you want) if this was a real order as a result of the AUTH Action being run. It sends
the content to a dummy file if this was simply a display of the invoice page by a module that
has a feature to redisplay the invoice. Make sure any module you have that does invoice
screen redisplay does not use Action=AUTH in its url. The first two parameters in the
exportxmlend command are required. Parameters 3, 4 and 5 are HIGHLY recommended. These
parameters check the target file to make sure that element tags and content do not already exist
in the file. Therefore these parameters should be unique to each order. Thus you will
probably use the order number and its element tags. In the below example, if the order number
was 1234, the exportxmlend command would look for 1234 in the
basket.dat. If it was already there, it would mean that order content had already been written
to the file so it would not write it a second time. It would also send the store a warning
email that a duplicate order content had attempted to write to the file. This is an
important security feature that should be implemented. There may be a case where you would
not want the content included in failed write emails. If that is the case, put the word nosend
in the 6th parameter. You will get the warning email, but the lost content will not be included.
The exportxml is the item that does the actual accumulation of element tags and content and
creates one line in the xml file. This item has four parameters; command, beginning element
tag for the line, content, ending element tag for the line. Some lines do not have content
and may only have the beginning or ending element tags. As example the opening element
tag is created by putting the word "ORDER" in the second parameter and leaving the third and fourth
blank. The closing element tag is created by leaving second and third parameters
blank and putting the word "ORDER" in the fourth parameter.
You can add attributes to the elements, e.g. . To do this you need to tokenize
a variable in the parameter. You also need to include the quote (") character in the element. But
you can't do that directly in store morph items. So I have provided a workaround. If you use the
caret (^) character, it will be changed to the quote before being written to the file. Hence the
following exportxml will produce the element with attribute as you see above.
2) Now click on the Customer Information tab at the top of the INVC page template. In this
template you can collect the customer data. As you can see you have separate opening and
closing CUSTOMER element tags with actual data lines in-between. In this example I included
two of the customer fields. You can use as many of them as you need for your order management
system.
3) Now click on the Order Contents tab at the top of the INVC page template. In this
template you can collect the information on products, coupons, discounts, fees, shipping, and
taxes. Some XML systems require that you number the element tags, e.g. PRODUCT1, PRODUCT2. In
this example, we initialize a variable called "one" just before the existing foreach loop of
order:items. On the line right after the beginning of the foreach loop of order:items, we
save an incremental number (starts as 1) to a variable called "exportcount". Then for each
product, we collect values. Note the opening and closing PRODUCT element tags. They have
an embedded token "%exportcount%" tagged onto the end of the word "PRODUCT". When exportxml
sees the token, it replaces it with the actual value from the math_add function. You can
similarly capture attribute data inside the foreach loop of item:options. In the foreach
loop of order:charges you will find the content for coupons, shipping, and taxes.
****
If you want to include attributes and options, you would include code like this just
below the foreach loop for the options as below. Also, if you do this, you will want to
put the closing PRODUCT element after the options foreach loop instead of where you see it
above.
****
The charges foreach loop would look something like this. While this example is basic,
you could wrap each pair with conditionals to check for the type of charge.
****
You can even export responses to checkout questions like those in the Addendum checkout
questions module.
4) The example code above will produce an XML output file that looks like:
1722
05/28/2008
William
Weiland
SORT CATEGORIES AND PRODUCTS
$19.60
1
Version
4.5
Domain
http://www.emporiumplus.com
Upgrade
1148
($1.60)
Insurance
$1.50
Shipping: SS Free Shipping
$0.00
Category discount over $15.00
($0.20)
Sales Tax
($0.01)
$19.29
Thanks for the memories
5) Retrieving the data. The data is written to the Merchant5/sXX/export/ directory to
a filename you specified in the exportxmlend item. Since this is a real time capture
file, you do not want to tie up the file for several seconds while you FTP it to your PC
or elsewhere. To minimize the time the file is effected, simply rename it. That only
takes a millisecond. As soon as it is renamed, any order that comes in after that will
be written to the original filename designated in the exportxmlend item. The renamed
file will be uneffected and can be downloaded at your leisure. Renaming using FTP only
takes a millisecond but could theoretically clash if an order is being written to the
file at that instant. I have provided an admin utility under admin > store > Utilities.
It has safety features that lock the file so that a clash cannot take place. While
locked, one process runs and the other process loops until the file is unlocked. I
also provided an email feature in the renaming process. You could email the file to
yourself. That said, email is not secure. So, like the merchant and customer
notification emails are not secure, the private data of customers could be exposed to
hackers. If you are currently not sending order emails due to sensitive data, you
probably won't want to email the file to yourself either. Definitely do not include
any financial data in an email. We do not recommend using the email feature. This
process can be run with a cron job using wget. The command line would be
https://YOURDOMAIN/mm5/admin.mvc?Screen=SUTL&Action=SUTL&Store_Code=YOURSTORECODE&Module_Code=toolkit&UserName=YOURADMINLOGIN&Password=YOURADMINPASSWORD&Provision=yes&Submit=Login&FlatToolKit_Origin=basket.dat&FlatToolKit_Destination=.xml&send2email=OPTIONALEMALADDRESSORLEAVEBLANK&SubAction=rename&pass=1
Several variables in upper case in this line need to be changed for your specific
store. You can also change the .xml value of FlatToolKit_Destination if you have a
program that runs this that needs a certain file name. If you leave it as .xml it
will create a unique filename with the .xml at the end.
6) Limitation of this system. If your payment methods do not automatically display
the invoice screen after payment, putting the export code on the INVC page would
not be reliable. For example, some PayPal modules require the customer to click a
"return to store" button before they will see the invoice screen. If the customer
failed to click that button, the order would not get recorded since the invoice screen
would not run these commands. There is a workaround for this if your store uses one
of those payment modules. If you have an email module that lets you assign 3rd party
module items to the email, e.g. our Mail Manager module, you can create an email that
is used for the order export. Below is an example of a special email. The email
sends the store a notice that an order has been exported (first line after the body
item). None of the order content is actually in the email. Instead it is exported
by tool kit just like it does on the invoice screen.
Order &mvte:order:id; exported to Merchant5/s01/export/basket.dat