Attribute Import and Export
Copyright © 2000, William Weiland
Overview
Import attributes into your Merchant store directly from a flat file.
Initial Setup and Usage
Use the Merchant admin upload feature to upload the modules attrimpt.mv and attrexp.mv. As each are uploaded, click the Add button to add them to the mall/domain.

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 image to the left of the word Utilities under the store. Then click on the image 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.

Import: Click on the image to the left of the word Utilities under the store. Then click on the image 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 (attrexp.mv) 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 put it in the data directory under your store. It will be the same directory that your products.dbf and products.dbt are in. 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 9 fields. With deletions, only 2 fields are needed.
A|product_code|code|type|prompt|price|cost|required|image
O|product_code|attribute_code|option_code|prompt|price|cost|default|image
CA|category_code|code|type|prompt|price|cost|required|image
CO|category_code|attribute_code|option_code|prompt|price|cost|default|image

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
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|
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 four types of attributes used by Miva Merchant; radio, select, checkbox, and text. The radio and select both require option lines. The checkbox and text do not use option lines. Be sure the type is entered as lower case.

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|
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|
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|
to
A|1AA00004|version|text|Card Message:|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.

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.

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.