Attribute Import and Export
Copyright © 2000, William Weiland
Overview
Import attributes into your Merchant store directly from a flat file.
Initial Setup and Usage
1) In admin, click Add Modules link (fig 2)
2) Click the file upload button
3) Browse to find the attrimpt.mvc file on your hard drive and upload (fig 3)
4) Click Add to add it to the domain
5) In admin, click Add Modules link (fig 2)
6) Click the file upload button
7) Browse to find the attrexpt.mvc file on your hard drive and upload (fig 3)
8) Click Add to add it to the domain
9) Import and Export modules automatically reside in each store within a domain so there is no need to update them to the store

Export: Click on the plus to the left of the word Utilities under the store. Then click on the plus for Export Data. Then click on the link for Export Attributes and Options to Flat File. The prompt will ask for the flat file name. Only put the file name, no path. For example, attribex.dat

Import: Click on the plus to the left of the word Utilities under the store. Then click on the plus for Import Data. Then click on the link for Attribute and Option Import from Flat File. The prompt will ask for the flat file name. Only put the file name, no path.

Headstart
If your store already has attributes and options associated with your products, use the export module, attrexpt.mvc, to create a flat file in the proper format. This can also serve as a backup (archive) copy of your attributes and options. The default name of the export file is attribex.dat. Keep a copy off-line along with your other backup copies of data.


Understanding the Flat File Format
The data elements which comprise the attributes and options are pulled from the flat file in a specific order. Since there is no artificial intelligence involved in this flat file import, it is imperative that the data be placed in a flat file in the same order that the program expects it to be. Any variance from that is likely to result in corrupt data in your database.

Creating the Flat File
If you are starting from scratch and have no attributes and options in your store yet, you can create the flat file in your text editor. Create the flat file and upload it to the data directory under your store. The default name should be attrib.dat. It must be | delimited. Note that the default name of the export file (headstart above) has "ex" in it. When you are ready to re-import from a previously exported file, you can either rename it or change the spelling at the time you import. I took this precaution to make it more difficult for you to overwrite your archived data.

When importing, be sure that the last line of the flat file is a blank line.

Format the Flat File
The key for each line is dependent on what you want to add/delete. The first field will be A = Attribute, O = Option, CA = Complete (entire) category Attribute, CO = Complete (entire) category Option. You use the D in the first field for deletions.

All of the other fields will contain actual data, not the words you see in the following four lines. These 4 lines represent the exact format. If a data element is blank, you still need to account for it, eg. || In all additions, there must be 13 fields for attributes and 11 fields for options. Note: If your version of Merchant is older than PR7 you will only need 12 fields in the attributes. The inventory field (13) can be included but will be ignored in the older versions. With deletions, only 2 fields are needed.
A|product_code|code|type|prompt|price|cost|required|image|template code|display order|weight|inventory
O|product_code|attribute_code|option_code|prompt|price|cost|default|image|display order|weight
CA|category_code|code|type|prompt|price|cost|required|image|template code|display order|weight
CO|category_code|attribute_code|option_code|prompt|price|cost|default|image|display order|weight

As examples, consider the following 6 lines from a flat file:
A|1AA00004|version|radio|Merchant Version:|0|0|1|graphics/en-US/mmui/blades.gif||||0
O|1AA00004|version|2X|2.xx|0|0|1|||
O|1AA00004|version|1X|1.xx (add $1.00)|1|1|0|||
CA|1AA|version|radio|Merchant Version:|0|0|0|||||0
CO|1AA|version|2X|2.xx|0|0|1|||
CO|1AA|version|1X|1.xx|0|0|0|||

1st - Adds a required, radio attribute with code "version" to product 1AA00004
2nd - Adds the 1st option to this attribute, this is default option
3rd - Adds the 2nd option to this attribute, this adds $1 to price
4th - 6th are similar but slightly different. For example, in the 1st line there is a 1 at the 8th field, meaning "required". In the category (CA) attribute, the 8th field is a 0, so we want it to be an optional attribute. Likewise, line 3 shows added cost; 6 does not. These will be applied to every product in the category with code 1AA. If the previous attribute (lines 1-3) happen to be in the same category (1AA), the attributes will be updated to match the category. However, if you want a certain product to be different from the rest of the category, then assign attributes to the category first, then do individual products.

The 4th field in the attribute lines is "type". There are five types of attributes used by MIVA Merchant; radio, select, checkbox, text, memo. The radio and select both require option lines. The checkbox, text and memo do not use option lines. There is a sixth type, template, which is not really a type. It is template. Be sure all types are entered as lower case. You can import the template type IF 1) you have enabled templates in your store, 2) you have already created the template in admin and 3) if you include the template code (which IS CASE SENSITIVE) as the 10th field in the Attribute entry line. If you are using template, it will override your other settings (eg prompt, price).

The 13th field in the attribute lines is "inventory". It is included in Merchant version PR7 which is a January 2010 streaming update. If you leave it blank, no change in the inventory setting will be made. If you enter a 0 then inventory will not be tracked at the attribute level for this product. This is the normal setting. If you enter a 1, then that attribute is tracked for inventory. That means that immediately after importing these settings you will need to go to each of those products which were set to 1 and update/add their actual inventory. If they are set to 1 and you do not have any inventory included in those product records, the product cannot be ordered as it will be considered out of stock.

If for some reason you want to delete attributes or options, you can include the D action for a product.
D|1AA00006

This line would delete ALL of the attributes and options associated with product code 1AA00006. Only two fields are used in deletions; D and the product code, separated with a | delimiter. Let's say you want to remove an option from your existing attribute for a product.
A|1AA00004|version|radio|Merchant Version:|0|0|1|||||0
O|1AA00004|version|2X|2.xx|0|0|1|||
O|1AA00004|version|1X|1.xx (add $1.00)|1|1|0|||
O|1AA00004|version|3X|3.xx|0|0|0|||

Example: I want to remove the 1X and modify the 2X and 3X. I would put the following in the flat file.
D|1AA00004
A|1AA00004|version|radio|Merchant Version:|0|0|1|||||0
O|1AA00004|version|2X|3.xx|0|0|1|||
O|1AA00004|version|3X|2.xx|0|0|0|||

If all you want to do is change data in the line, you do not need to delete the group first. For example, if you want to change:
A|1AA00004|version|text|Gift Message:|0|0|0|||||0
to
A|1AA00004|version|text|Card Message:|0|0|0|||||0
then you don't need to delete first, just modify the line and import.

Note: Simple modifications without deletion first can be made as long as you are NOT changing the attribute or option CODE. Changing the code requires removal of the old code or you will end up with two sets of attributes and options doing the same thing for a product.

Templates give you the ability to enter an attribute/option template which can be used by many products. A change to the template makes that change available to all products using it. When the customer views a product record, the program checks to see if the attribute record type is a template or not. If it is, it uses the global template for that code. Consider the line from our previous example. I've added the template code as the 10th field in the line and changed the type from radio to template. As long as you have previously created a template with the corresponding code through your admin interface, you can import the template from a flat file and the product display will use the template. You do not even need to include the lines for options in the flat file because it will use the options previously setup in the template.
A|1AA00004|version|template|Merchant Version:|0|0|1|graphics/en-US/mmui/blades.gif|version|||0

When you import, each product code is checked to see if the attribute codes and option codes already exist with that product code. If they do, it updates the store databases from the flat file. If they do not, it adds them to the databases.

If you are importing many attributes, you may need to break your attrib.dat flat file up into smaller files to prevent the MIVA Engine from timing out. This is particularly true with Merchant 5.x as the SQL is slower than the previous xbase files with adding records.

If you are having time-out problems with exporting, you may need to run that using MIVAMia on your hard drive (where you have control of time-out settings).

I highly recommend adding only a few attributes in the flat file until you are sure you thoroughly understand the flat file format. Since an attribute and option export module is supplied with this system, it would be best if you export your existing attributes and options to a flat file before you add any. Then you can study that file and add to it.

Fig 1: Main admin screen

Fig 2: Add a new module

Fig 3: Upload the module to the server