Skip to content

Import Products to Magento V2

This task will create or update products in Magento. See below for a sample input file.

If the <id> element is specified in the input file, the task will update the product with the specified ID. If no ID is specified, the task will use the <sku> element to check if the product already exists. If a match is found the existing product will be updated, otherwise a new product will be created.

Every field supported by the task, including the required fields and the valid values for status, visibility and type_id, is documented in the Magento V2 Product XML reference.

Required Fields

Magento rejects a new product if any of the following are missing. They are the most common cause of a 400 Bad Request from the products endpoint. Zynk does not fill in a value for any of these fields, so they must be set in your mapping.

XML Field Notes
sku Unique identifier for the product. Also used by Zynk to match existing products when no id is supplied
name Product name
attribute_set_id See Attribute Set below
price* Product price
type_id The type of product, e.g. simple
status See Status below
visibility See Visibility below
weight* Product weight
custom_attributes/custom_attribute (tax_class_id) See Tax Class below
  • price* - Required for simple, virtual and downloadable products. Not required for configurable and grouped products, or bundle products with a dynamic price
  • weight* - Required by Magento for shippable product types, e.g. simple. Omit for virtual and downloadable products

Status - Required

Sent in the status element. Controls whether the product can be sold.

Option Meaning
1 Enabled - This product is able to be sold
2 Disabled - This product is not able to be sold
<status>1</status>

Visibility - Required

Sent in the visibility element. Controls where the product appears on the storefront.

Option Meaning
1 Not Visible Individually - This product does not appear in the catalogue or in search results. Used for the child products of a configurable or grouped product
2 Catalog - This product appears when browsing the catalogue, but not in search results
3 Search - This product appears in search results, but not when browsing the catalogue
4 Catalog, Search - This product appears in both the catalogue and search results
<visibility>4</visibility>

Attribute Set - Required

Sent in the attribute_set_id element. The attribute set decides which attributes are available on the product.

Option Meaning
4 Default - The Default attribute set on a standard Magento installation
Any other ID An attribute set added to your own Magento installation. Use Export Product Attributes to find the IDs of your attribute sets
<attribute_set_id>4</attribute_set_id>

Tax Class - Required

Sent as a custom attribute with an attribute_code of tax_class_id, not as an element of the product. The options below are those of a standard Magento installation. Additional tax classes may have been added to your store.

Option Meaning
0 None - This product is not taxable
2 Taxable Goods - This product is taxed at the rate set up for Taxable Goods in Magento
<custom_attributes>
  <custom_attribute>
    <attribute_code>tax_class_id</attribute_code>
    <value>2</value>
  </custom_attribute>
</custom_attributes>

POST /V1/products

This method will be used when creating a new product record. The matching routine for products is noted above.

PUT /V1/products/{sku}

This method will be used when updated an existing product record. The matching routine for products is noted above.
{sku} The task will find a matching sku based on the data you provide.

Settings

Connection

Required
The Magento V2 connection to use. See the Connecting to Magento v2 article if you require more information on how to create/manage connections.

Fail File

Required
The XML file to save failed product imports to. The data will be written in the same format as the input file.

Input File

Required
The XML file containing the products to import in Magento.

Success File

Required
The XML file to save successful product imports to. The data will be written in the same format as the input file.

Prevent Reprocessing

Required
Set to true to prevent the same record being processed more than once by the task. This setting will only work where an <external_id> element is provided in the XML.

Store View Code

Required
The magento store view code to perform the API calls against. Default value of 'all'.

Import Categories - Case Sensitive Category

Required
Set to true if you would like to perform a case sensitive match when importing Categories.

Upload Categories - Enabled must be set to true for the Import Categories functionality to be enabled.

Defaulted to False.

Import Categories - Category Field Name

Required
The Name of the Field(s) in the Product data that contain the Category structures to import.

Upload Categories - Enabled must be set to true for the Import Categories functionality to be enabled.

Defaulted to category_structure.

<custom_attributes>
  <custom_attribute>
    <attribute_code>category_structure</attribute_code>
    <value>Category Name</value>
  </custom_attribute>
</custom_attributes>

Import Categories - Category Field Separator

Required
The separator character used between Categories to infer the Category nesting.

Upload Categories - Enabled must be set to true for the Import Categories functionality to be enabled.

Defaulted to ;.

<custom_attributes>
  <custom_attribute>
    <attribute_code>category_structure</attribute_code>
    <value>Category Top Level;Category Sub Level</value>
  </custom_attribute>
</custom_attributes>

Import Categories - Create Categories - Enabled

Required
Set to true if you would like to automatically create Categories on Magento that are provided in the Product data but do not exist yet on Magento.

Upload Categories - Enabled must be set to true for the Import Categories functionality to be enabled.

Defaulted to False.

Import Categories - Create Categories - New Category Available Sort By Value

Required
The <available_sort_by> value to use for automatically created Categories.

Upload Categories - Enabled and Upload Categories - Create Categories - Enabled must be set to true for the Create Categories functionality to be enabled.

Defaulted to position, name, sku, price.

Import Categories - Create Categories - New Category Default Sort By Value

Required
The <default_sort_by> value to use for automatically created Categories.

Upload Categories - Enabled and Upload Categories - Create Categories - Enabled must be set to true for the Create Categories functionality to be enabled.

Defaulted to price.

Import Categories - Create Categories - Include In Menu Value

Required
The <include_in_menu> value to use for automatically created Categories.

Upload Categories - Enabled and Upload Categories - Create Categories - Enabled must be set to true for the Create Categories functionality to be enabled.

Defaulted to True.

Import Categories - Create Categories - Is Active Value

Required
The <is_active> value to use for automatically created Categories.

Upload Categories - Enabled and Upload Categories - Create Categories - Enabled must be set to true for the Create Categories functionality to be enabled.

Defaulted to True.

Import Categories - Enabled

Required
Set to true if you would like to lookup Categories on Magento based on Field(s) that are provided in the Product data.

Defaulted to True.

Zynk Settings

See Common Task Settings.

Examples

A sample input file is shown below. This will update the product with SKU code '24-MB01'.

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfProduct xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Product>
    <id>1</id>
    <sku>24-MB01</sku>
    <name>Joust Duffle Bag</name>
    <attribute_set_id>15</attribute_set_id>
    <price>34</price>
    <status>1</status>
    <visibility>4</visibility>
    <type_id>simple</type_id>
    <weight xsi:nil="true" />
    <product_links>
      <product_link>
        <sku>24-MB01</sku>
        <link_type>upsell</link_type>
        <linked_product_sku>24-MB03</linked_product_sku>
        <linked_product_type>simple</linked_product_type>
        <position xsi:nil="true" />
        <extension_attributes />
      </product_link>
      <product_link>
        <sku>24-MB01</sku>
        <link_type>upsell</link_type>
        <linked_product_sku>24-MB05</linked_product_sku>
        <linked_product_type>simple</linked_product_type>
        <position xsi:nil="true" />
        <extension_attributes />
      </product_link>
    </product_links>
    <options />
    <tier_prices />
    <custom_attributes>
      <custom_attribute>
        <attribute_code>description</attribute_code>
        <value><![CDATA[<p>The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.</p>
<ul>
<li>Dual top handles.</li>
<li>Adjustable shoulder strap.</li>
<li>Full-length zipper.</li>
<li>L 29" x W 13" x H 11".</li>
</ul>]]></value>
      </custom_attribute>
      <custom_attribute>
        <attribute_code>image</attribute_code>
        <value>/m/b/mb01-blue-0.jpg</value>
      </custom_attribute>
    </custom_attributes>
  </Product>
</ArrayOfProduct>

Sample XSLT file to use to transform products exported from Sage in the Zynk XML Products format, to the Magento product format. This is also available in the Auto Mapper.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="AttributeSet">4</xsl:param>

  <xsl:template match="/">
    <ArrayOfProduct>
      <xsl:for-each select="Company/Products/Product">
        <xsl:call-template name="Product" />
      </xsl:for-each>
    </ArrayOfProduct>
  </xsl:template>

  <xsl:template name="Product">
    <Product>
      <sku><xsl:value-of select="Sku" /></sku>
      <name><xsl:value-of select="Name" /></name>
      <type_id>simple</type_id>
      <attribute_set_id><xsl:value-of select="$AttributeSet" /></attribute_set_id>
      <status>1</status>
      <visibility>4</visibility>
      <price><xsl:value-of select="SalePrice" /></price>

      <custom_attributes>
        <custom_attribute>
          <attribute_code>description</attribute_code>
          <value><xsl:value-of select="Description"/></value>
        </custom_attribute>
        <custom_attribute>
          <attribute_code>tax_class_id</attribute_code>
          <value>
            <xsl:choose>
              <xsl:when test="TaxCode = '1'">2</xsl:when>
              <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
          </value>
        </custom_attribute>
      </custom_attributes>
    </Product>
  </xsl:template>
</xsl:stylesheet>