RO CSVI

Import XML with same node names

When it comes to XML file we remember nodes and it is possible that these XML files have same node names but with different node values. CSVI can read these XML files and the nodes values to import them in to the database. In this document we are going to explain with an example on how a parent product and child products defined in same node names are imported but with different values.

Consider the following XML example

<?xml version="1.0" encoding="UTF-8"?>
<products>
   <product id="1227654" product_sku="sku-23-012860">
    <description>
      <name><![CDATA[Sample product]]></name>
      <long_desc><![CDATA[Sample product description]]></long_desc>
   </description>
     <price gross="322.22" net="251.97" vat="33.0"/>
    <childs>
       <child id="3" size_name="S" product_mpn="1227654-1" weight="200">
          <stock id="1" quantity="10"/>
       </child>
       <child id="5" size_name="L"  product_sku="sku-17-C4-161" product_mpn="1227654-2" weight="600">
         <stock id="1" quantity="10"/>
      </child>
      <child id="6" size_name="XL" product_sku="sku-17-C1-161" product_mpn="1227654-3" weight="800">
         <stock id="1" quantity="15"/></child>
     </childs>
    </product>
   </products>

As per the above XML we have one parent product and two child products.  The first <child> node is for parent product details and the next two <child> nodes are for children. We need three different import templates with different template settings to import these products. Frst step is to import the parent product.

 Import parent product

1. Create an VirtueMart product import template for parent product. In the template settings, select the Component as VirtueMart, Operation as product and Action as import. Save the template. Also make sure that you set User file for configuration option on File tab to No, this option will use template fields instead of column headers in import file as fields.

vm import parent product create template

2. Set the template fields according to the XML node and as shown below. Since we are going to use the first <child> node for parent we can ignore the rest of the child nodes.

vm parent product create templatefields

3. Now go to Import page, select the parent product import template and run the import.

 vm import parent product run import

 

Import first child product

1. Create a new import template to import first child product. In the template settings, select the Component as VirtueMart, Operation as product and Action as import. Save the template. Note that the template settings are same as of parent product but the template field settings are going to be different.

vm import child product create template

2. Create template fields and set the XML nodes. We need to use the second <child> node for the first child product so we are going to set the first <child> to Skip field so CSVI ignores them during import.

vm import first child product create templatefields

3. Go to CSVI import page, select the template created for first child product and run the import.

 vm import child product run import

Import second child product

1. Create VirtueMart product import template for second child product. As we did for parent and first child product in the template settings, select the Component as VirtueMart, Operation as product and Action as import. Save the template. The template field settings are going to be different from parent and first child product.

vm import second child product create template

2. Create template fields so we skip the first two <child> nodes and use the third child note for the product. We are going to use Skip field for ignoring the first two child nodes and tell CSVI to use the third node.

vm import second child product create templatefield

3. Select the second child import template and Run the import from CSVI import page.

vm import second child product run import

More articles on this subject