Product import via XML

May 4, 2010 at 11:57 AM
Edited May 4, 2010 at 11:58 AM

Hi Dave,

I'm trying to import some products into our store, but I'm struggling a bit... Can't really find any good info on XML imports.
First I exported an existing product and I'm using the resulting xml (modified) for import. I finally got this working after several issues.

I can now succesfully load a product with multiple models into the store, but I still have some issues/questions:

  • Which fields in the XML are required to be set? Can I leave out fields with default values (eg Weight will always be 0)?
  • How are the ID's read/created? I noticed the ID of the products and models is different when i export the imported product again. I mean, these are not as I've set them in the import XML.
    Should I give them 'random' numbers, or doesn't this matter? Will the code import the product and assign needed IDs to it (so i can always use -1 in the XML)
    In my test file i used -1 as ProductID in the NB_Store_ProductsInfo section, and I referenced that id in the Product_ID i the 'child' models. Each consecutive model has another ModelID (-1, -2, -3, ...)
  • How should I link a new product to an existing category? I tried adding the <C> block with the CategoryID of the category in which the new product should be and the productID equal to the ProductID I've set in the product, but when the product imports it has no category assigned to it. I guess this is because the product gets another ID than the one I provided?

The XML I used for import:

<root version="1.0">
  <products>
    <nl-NL>
      <P>
        <NB_Store_ProductsInfo>
          <ProductID>-1</ProductID>
          <PortalID>0</PortalID>
          <TaxCategoryID>-1</TaxCategoryID>
          <Featured>false</Featured>
          <Archived>false</Archived>
          <CreatedByUser>-1</CreatedByUser>
          <CreatedDate>2010-05-03T14:00:00.000</CreatedDate>
          <IsDeleted>false</IsDeleted>
          <ProductRef>Kamazan B100</ProductRef>
          <Lang>nl-NL</Lang>
          <Summary></Summary>
          <Description>Bronze &lt;BR/&gt; Trout shrimp &amp; buzzer</Description>
          <Manufacturer>Kamazan</Manufacturer>
          <ProductName>Kamazan B100</ProductName>
          <XMLData />          
        </NB_Store_ProductsInfo>      
	   <M>
          <NB_Store_ModelInfo>
            <ModelID>-1</ModelID>
            <ProductID>-1</ProductID>
            <ListOrder>1</ListOrder>
            <UnitCost>3.5</UnitCost>
            <Barcode />
            <ModelRef>kam_b100_10</ModelRef>
            <Lang>nl-NL</Lang>
            <ModelName>mt 10</ModelName>
            <QtyRemaining>-1</QtyRemaining>
            <QtyTrans>0</QtyTrans>
            <QtyTransDate>2010-05-03T14:00:00.000</QtyTransDate>
            <ProductName>B100 mt 10</ProductName>
            <PortalID>0</PortalID>
            <Weight>0.00</Weight>
            <Height>0.00</Height>
            <Length>0.00</Length>
            <Width>0.00</Width>
            <Deleted>false</Deleted>
            <QtyStockSet>0</QtyStockSet>
            <DealerCost>0.0000</DealerCost>
            <PurchaseCost>0.0000</PurchaseCost>
            <XMLData />
            <Extra />
          </NB_Store_ModelInfo>
		  <NB_Store_ModelInfo>
            <ModelID>-2</ModelID>
            <ProductID>-1</ProductID>
            <ListOrder>1</ListOrder>
            <UnitCost>3.5</UnitCost>
            <Barcode />
            <ModelRef>kam_b100_12</ModelRef>
            <Lang>nl-NL</Lang>
            <ModelName>mt 12</ModelName>
            <QtyRemaining>-1</QtyRemaining>
            <QtyTrans>0</QtyTrans>
            <QtyTransDate>2010-05-03T14:00:00.000</QtyTransDate>
            <ProductName>B100 mt 12</ProductName>
            <PortalID>0</PortalID>
            <Weight>0.00</Weight>
            <Height>0.00</Height>
            <Length>0.00</Length>
            <Width>0.00</Width>
            <Deleted>false</Deleted>
            <QtyStockSet>0</QtyStockSet>
            <DealerCost>0.0000</DealerCost>
            <PurchaseCost>0.0000</PurchaseCost>
            <XMLData />
            <Extra />
          </NB_Store_ModelInfo>
		   <NB_Store_ModelInfo>
            <ModelID>-3</ModelID>
            <ProductID>-1</ProductID>
            <ListOrder>1</ListOrder>
            <UnitCost>3.5</UnitCost>
            <Barcode />
            <ModelRef>kam_b100_14</ModelRef>
            <Lang>nl-NL</Lang>
            <ModelName>mt 14</ModelName>
            <QtyRemaining>-1</QtyRemaining>
            <QtyTrans>0</QtyTrans>
            <QtyTransDate>2010-05-03T14:00:00.000</QtyTransDate>
            <ProductName>B100 mt 14</ProductName>
            <PortalID>0</PortalID>
            <Weight>0.00</Weight>
            <Height>0.00</Height>
            <Length>0.00</Length>
            <Width>0.00</Width>
            <Deleted>false</Deleted>
            <QtyStockSet>0</QtyStockSet>
            <DealerCost>0.0000</DealerCost>
            <PurchaseCost>0.0000</PurchaseCost>
            <XMLData />
            <Extra />
          </NB_Store_ModelInfo>
		   <NB_Store_ModelInfo>
            <ModelID>-4</ModelID>
            <ProductID>-1</ProductID>
            <ListOrder>1</ListOrder>
            <UnitCost>3.5</UnitCost>
            <Barcode />
            <ModelRef>kam_b100_16</ModelRef>
            <Lang>nl-NL</Lang>
            <ModelName>mt 16</ModelName>
            <QtyRemaining>-1</QtyRemaining>
            <QtyTrans>0</QtyTrans>
            <QtyTransDate>2010-05-03T14:00:00.000</QtyTransDate>
            <ProductName>B100 mt 16</ProductName>
            <PortalID>0</PortalID>
            <Weight>0.00</Weight>
            <Height>0.00</Height>
            <Length>0.00</Length>
            <Width>0.00</Width>
            <Deleted>false</Deleted>
            <QtyStockSet>0</QtyStockSet>
            <DealerCost>0.0000</DealerCost>
            <PurchaseCost>0.0000</PurchaseCost>
            <XMLData />
            <Extra />
          </NB_Store_ModelInfo>
        </M>
        <I></I>
        <D></D>
        <C>
			<NB_Store_ProductCategoryInfo>				
				<ProductID>-1</ProductID>
				<CategoryID>72</CategoryID>
			</NB_Store_ProductCategoryInfo>
		</C>
        <options></options>
	</P>
 </nl-NL>
  </products>
 </root>

And the resulting export after the succesfull import of the product:

<products>
  <nl-NL>
    <P>
      <NB_Store_ProductsInfo>
        <ProductID>21</ProductID>
        <PortalID>0</PortalID>
        <TaxCategoryID>-1</TaxCategoryID>
        <Featured>false</Featured>
        <Archived>false</Archived>
        <CreatedByUser>1</CreatedByUser>
        <CreatedDate>2010-05-03T14:00:00</CreatedDate>
        <IsDeleted>false</IsDeleted>
        <ProductRef>Kamazan B100</ProductRef>
        <Lang>nl-NL</Lang>
        <Summary />
        <Description>Bronze&amp;lt;br /&amp;gt;Trout shrimp
        &amp;amp; buzzer</Description>
        <Manufacturer>Kamazan</Manufacturer>
        <ProductName>Kamazan B100</ProductName>
        <XMLData />
        <ModifiedDate>2010-05-03T17:17:29.65</ModifiedDate>
      </NB_Store_ProductsInfo>
      <M>
        <NB_Store_ModelInfo>
          <ModelID>31</ModelID>
          <ProductID>21</ProductID>
          <ListOrder>1</ListOrder>
          <UnitCost>3.5000</UnitCost>
          <Barcode />
          <ModelRef>kam_b100_10</ModelRef>
          <Lang>nl-NL</Lang>
          <ModelName>mt 10</ModelName>
          <QtyRemaining>-1</QtyRemaining>
          <QtyTrans>0</QtyTrans>
          <QtyTransDate>2010-05-03T14:00:00</QtyTransDate>
          <ProductName>Kamazan B100</ProductName>
          <PortalID>0</PortalID>
          <Weight>0.00</Weight>
          <Height>0.00</Height>
          <Length>0.00</Length>
          <Width>0.00</Width>
          <Deleted>false</Deleted>
          <QtyStockSet>0</QtyStockSet>
          <DealerCost>0.0000</DealerCost>
          <PurchaseCost>0.0000</PurchaseCost>
          <XMLData />
          <Extra />
        </NB_Store_ModelInfo>
        <NB_Store_ModelInfo>
          <ModelID>32</ModelID>
          <ProductID>21</ProductID>
          <ListOrder>1</ListOrder>
          <UnitCost>3.5000</UnitCost>
          <Barcode />
          <ModelRef>kam_b100_12</ModelRef>
          <Lang>nl-NL</Lang>
          <ModelName>mt 12</ModelName>
          <QtyRemaining>-1</QtyRemaining>
          <QtyTrans>0</QtyTrans>
          <QtyTransDate>2010-05-03T14:00:00</QtyTransDate>
          <ProductName>Kamazan B100</ProductName>
          <PortalID>0</PortalID>
          <Weight>0.00</Weight>
          <Height>0.00</Height>
          <Length>0.00</Length>
          <Width>0.00</Width>
          <Deleted>false</Deleted>
          <QtyStockSet>0</QtyStockSet>
          <DealerCost>0.0000</DealerCost>
          <PurchaseCost>0.0000</PurchaseCost>
          <XMLData />
          <Extra />
        </NB_Store_ModelInfo>
        <NB_Store_ModelInfo>
          <ModelID>33</ModelID>
          <ProductID>21</ProductID>
          <ListOrder>1</ListOrder>
          <UnitCost>3.5000</UnitCost>
          <Barcode />
          <ModelRef>kam_b100_14</ModelRef>
          <Lang>nl-NL</Lang>
          <ModelName>mt 14</ModelName>
          <QtyRemaining>-1</QtyRemaining>
          <QtyTrans>0</QtyTrans>
          <QtyTransDate>2010-05-03T14:00:00</QtyTransDate>
          <ProductName>Kamazan B100</ProductName>
          <PortalID>0</PortalID>
          <Weight>0.00</Weight>
          <Height>0.00</Height>
          <Length>0.00</Length>
          <Width>0.00</Width>
          <Deleted>false</Deleted>
          <QtyStockSet>0</QtyStockSet>
          <DealerCost>0.0000</DealerCost>
          <PurchaseCost>0.0000</PurchaseCost>
          <XMLData />
          <Extra />
        </NB_Store_ModelInfo>
        <NB_Store_ModelInfo>
          <ModelID>34</ModelID>
          <ProductID>21</ProductID>
          <ListOrder>1</ListOrder>
          <UnitCost>3.5000</UnitCost>
          <Barcode />
          <ModelRef>kam_b100_16</ModelRef>
          <Lang>nl-NL</Lang>
          <ModelName>mt 16</ModelName>
          <QtyRemaining>-1</QtyRemaining>
          <QtyTrans>0</QtyTrans>
          <QtyTransDate>2010-05-03T14:00:00</QtyTransDate>
          <ProductName>Kamazan B100</ProductName>
          <PortalID>0</PortalID>
          <Weight>0.00</Weight>
          <Height>0.00</Height>
          <Length>0.00</Length>
          <Width>0.00</Width>
          <Deleted>false</Deleted>
          <QtyStockSet>0</QtyStockSet>
          <DealerCost>0.0000</DealerCost>
          <PurchaseCost>0.0000</PurchaseCost>
          <XMLData />
          <Extra />
        </NB_Store_ModelInfo>
      </M>
      <I></I>
      <D></D>
      <C>
        <NB_Store_ProductCategoryInfo>
          <ProductID>21</ProductID>
          <CategoryID>72</CategoryID>
        </NB_Store_ProductCategoryInfo>
      </C>
      <options></options>
    </P>
  </nl-NL>
</products>

Regards,
Tim Wuytens
Coordinator
May 4, 2010 at 12:28 PM

Hi Tim,

You've done well, getting the xml import structure right is a bit of a pig!! In answer to your questions..

 

  • Which fields in the XML are required to be set? Can I leave out fields with default values (eg Weight will always be 0)?

No, because the code uses XML serialization on the data classes so all the fields must be there or you'll get an error.

  • How are the ID's read/created? I noticed the ID of the products and models is different when i export the imported product again. I mean, these are not as I've set them in the import XML.
    Should I give them 'random' numbers, or doesn't this matter? Will the code import the product and assign needed IDs to it (so i can always use -1 in the XML)
    In my test file i used -1 as ProductID in the NB_Store_ProductsInfo section, and I referenced that id in the Product_ID i the 'child' models. Each consecutive model has another ModelID (-1, -2, -3, ...)

The productid is used to link the models and other data to the product, so what you've done on the example is correct, but on the second product you can;t use "-1" again.  I'd suggest your first should be ProductID "1" and then the second one "2", "3", "4"....etc...  I would also use unique ids for your models, i.e. each model having an incrementing count across the whole file.  (I think it would work without doing this, but I think it best if you do.)

  • How should I link a new product to an existing category? I tried adding the <C> block with the CategoryID of the category in which the new product should be and the productID equal to the ProductID I've set in the product, but when the product imports it has no category assigned to it. I guess this is because the product gets another ID than the one I provided?

The problem with trying to link to an existing category is that the import program doesn't know it exists, it assumes that the category your trying to add the product to is included in the xml import file.  To get this to work I think you need to include the category (existing or not) in the xml file.  Do an export of your product with the categories and you'll see he structure you'll need.

 

I do have a old program I used to export some of my clients stores from an adapted version of DNN Store into NB_Store (v.1.0), it's a bit old and may not match the currect situation but it could give you a basic idea.  Contact me through codeplex and I'll reply sending you the source code.  Of course this will only be of real help if your using .Net to create the import xml.

Let me know how you get on.

Regards,

Dave.

May 4, 2010 at 1:18 PM

Dave,

Thanks for the compliment ;-)  I was in fact thinking on publishing some extra info about the XML import once I got it working the way I want.  So other people can benefit from my mistakes too.

I would love to have a look at your old code, since I'm trying to export products from an old MS access dB to the store. So this will be quite handy I guess...

Tim