Magento Extensions:Stock Import Module

From XTENTO Support Wiki
Jump to: navigation, search
This is a guide for Magento 1. For Magento 2 extensions and guides, please refer to Magento 2 Guides.

Extension Logo

Contents

Overview

Importing stock level updates from CSV/TXT/Tab/Fixed-Length/XML files into Magento has never been easier. Using the Magento Stock Import Module by XTENTO you will be able to import stock information from third party systems into Magento - fully automated! Automate your inventory management today and don't spend hours a day updating stock levels manually.

Interested in this Magento Extension?

Head over to our store to purchase this extension: Magento Stock Import Module

Got questions? Feel free to contact us! Contact Form

Setting up the extension

After installing the extension as instructed in our general installation guide, please go to System > XTENTO > Stock Import Configuration. Please enter your license key there and set Module Enabled to "Yes".

Upgrading from the old Magento Stock Import Module

Attention: When updating from the old module (any version before Sep 1st, 2013) the module will need to be configured again

If you downloaded the extension before Sep 1st, 2013, please go to My Downloadable Products in our store to download the latest version of the extension. You're using the old version if the menu entry Catalog > Stock Import does not exist. Both modules run stand-alone which means you can install them both at the same time, then make sure the new version works as expected, and disable the old version as described below.

The configuration will not be migrated automatically. You have to set up new import profiles at Catalog > Stock Import. Most of the configuration of the single profile of the old extension can be copied, located at System > Configuration > XTENTO > Stock Import Module (this section is not used anymore - any settings are made at Catalog > Stock Import)

To disable the old stock import module, please open the file app/etc/modules/Xtento_InventoryImport.xml. Look for the "active" node saying true and replace true with false. Save the file and refresh the Magento cache.

Configuring the extension

Before proceeding with the configuration, please make sure you're using the latest version of the extension. If you downloaded the extension before Sep 1st, 2013, please go to My Downloadable Products in our store to download the latest version of the extension.

The following description will cover the modules configuration located at Catalog > Stock Import.

Import Profiles

Import profiles can be set up for manual and automatic imports. Every profile contains information about the data to import (e.g. field mapping), when, how, and where to import from, as well as some other settings. The extension supports an unlimited number of different import profiles.

To set up new import profiles or to modify existing import profiles, please go to Catalog > Stock Import > Import Profiles.

Setting up a new import profile is easy. Press the "Add New Profile" button. You will then be asked to select the entity (stock level) to import, the file format (CSV/XML/TXT/...), as well as to assign a name to the profile which can be used to identify the import profile in import logs. Press the Continue button.

You will then be presented with the profile configuration. The configuration of import profiles is split into several different sections ("tabs") which are explained below.

1) General Settings

General Configuration
Name: Enter the name of the profile. This name will show up in execution logs and will be used to identify the profile when importing.
Enabled: If set to "No", this profile won't show up for manual imports nor will automatic imports be made.
File Processor: This defines the file format which will be imported, e.g. CSV/TXT/XML/... Import Type: Can't be changed after profile creation. Defines which entity (data type) gets imported. Available entities:

 Entity  Description
Stock level Update stock level for products

2) Import Settings

Reindex mode: Should Magentos reindex process be initiated after importing?

If stock qty is 0 or less, mark as out of stock: If the imported stock level is below 0 and this option is set to Yes, the stock status will be set to "Out of stock".

Import relative stock level: If set to "No", the stock level specified in the import file will be imported, whatever it is. If set to "Yes", if you import +5, 5 will be added to the current stock level, and if you import -5, 5 will be subtracted from the current stock level.
Product Identifier: This is what will be called the Product Identifier in the import settings and is what's used to identify the product in the import file. Almost always you will want to use the SKU. Using a custom attribute can be slower as well.

3) File Configuration

This section maps your import file format to the fields which will be adjusted/updated in Magento.

The options you see depend on the file processor selected in the "General Configuration" tab of the profile.

CSV/TXT/Tab-delimited

Use this processor if you want to import CSV/TXT/Tab-delimited file formats, so any format where fields are delimited by some character, e.g. , ; | etc.

Configuration
Skip header line: Set this to "Yes" if you want to skip the first line of each imported CSV file as it's the header line containing the column names. You must set this to "Yes" if the first line contains the column names and you want to map fields by column name.

Field Delimiter: REQUIRED: Set the field delimiter (one character only). Example field delimiter: ; (Hint: If you want to use a tab delimited file enter: \t)

Field Enclosure Character: Set the field enclosure character (one character only). Example: "

File Mapping
You can can map the import fields to the actual column names in the CSV file here. Make sure to enter the EXACT same column name (case-sensitive).

If there are no columns in the import file, you can also map by index. The first field in the file would be 0 - the second field in the file would be 1 and so on.

XML

Use this processor if you want to import XML file formats.

Configuration
Data XPath: Set the XPath for the node containing the inventory updates.

Example XML file:
<items>
<item>
...
</item>
<item>
...
</item>
</items>

The inventory updates would be located in each "item" node, which are located in the "items" node, so the XPath would be: //items/item

Every "item" node located under the "items" node would be processed then.

More information about XPath can be found here: http://www.w3schools.com/xpath/

File Mapping
You can map the actual import fields to the fields in the XML file here. Make sure to enter the EXACT same name (case-sensitive).

What you enter into the "Field Name" field is XPath. So for example if you had this XML markup:

<items>
<item sku="123">
<qty>1</qty>
</item>
</items>

To fetch the sku you would enter: @sku (@ in front because it's an attribute) To fetch the qty you would enter: qty (This is the field name of the field you want to fetch)

More information about XPath can be found here: http://www.w3schools.com/xpath/

Fixed-Length Formats

It is also possible to import fixed-length formats using the module. Just select the CSV/TXT/Tab processor when creating a profile.

Into the Field Delimiter column enter: FLF When mapping a field at "File Mapping", you would enter the starting and ending position of the field into the "Field Name / Index" field.

For example if you wanted fetch position 5 to 30 you would enter: 5-30

4) Import Sources

Select the import sources where files should be downloaded from before importing simply by checking the checkbox right before the Source ID.

Please refer to the Import Sources section below to get an idea how to configure and set up sources.

5) Automatic Import

It is possible to set up cronjob imports for import profiles.

Cronjob Import

If you want to automate imports, you can set up cronjobs for profiles which execute the import for this profile at certain times automatically. First of all, make sure to set up your Magento cronjob as explained here. You can easily control the cronjob status right from the import module, by going to "Cronjob Import" when editing a profile in the "Automatic Import" tab. The Cronjob Status field will contain information about the status of the cronjob and whether any action is required or not.

To enable cronjob imports for this profile, simply set Enable Cronjob Import to "Yes". Select the Import Frequency of how often you want the import to run. That's it.

It is also possible to set up multiple, different cronjobs for one profile, for example if you wanted the cronjob to run at certain times during the week and only at 10pm on weekends. To do so, select "Use custom import frequency" from the Import Frequency dropdown, and enter one or more cron expressions separated by a semi-colon (;) in the Custom Import Frequency field. You can enter an unlimited amount of cron expressions there separated by semi-colons, just make sure they are valid cron expressions.

Example custom cron expression calling the cronjob for a profile at 8am, 1pm, 3pm at every full hour from Monday to Friday: 0 8,13,15 * * 1-5

Further examples:

Minute Hour Day Month Weekday Cron Expression Description
0 0 * * * 0 0 * * * Every day at 00:00
5 * * * * 5 * * * * Five minutes after every full hour
*/5 * * * * */5 * * * * Every 5 minutes
59 23 * * 0 59 23 * * 0 Every Sunday (Sunday can be 0 or 7) at 11:59pm
20,30 1 * * 1-5 20,30 1 * * 1-5 Monday to Friday at 01:20am and 01:30am
0 1 1-7 12 1 0 1 1-7 12 1 From Dec 1 to Dec 7, as well as on every Monday in December at 00:00

Important: Automated imports will only be made if the profiles status (under General Configuration) is "Enabled".

6) Profile Execution Log

The profile execution log shows any imports made using this profile, be it manual or automatic.

Import Sources

Import sources are the actual "sources" where imported files will be downloaded from. If your only goal is to manually import and upload import files from the Magento backend, you won't need to set up any import sources. If you need to download import files from remote FTP servers or certain local directories on the Magento server, you will have to set up import sources.

The module supports an unlimited amount of different import sources. The following source types are currently supported:

 Source Type  Description
Local Directory Files are retrieved from a local directory on the Magento server
FTP Server Files are retrieved from a remote FTP(S) server
SFTP Server Files are retrieved from a remote SFTP server. Supports SFTPv3 only.
HTTP Server Files are retrieved from remote HTTP servers by sending a GET/POST request for example
Webservice/API Files are retrieved from webservices/API. The webservice/API code must be set up by you.
Custom Code / Custom Class Imports can be handled by a custom class you can set up. This class could parse and modify, and then return files to process to the module.

Setting up Import Sources

To set up import sources, go to Catalog > Stock Import > Import Sources. You can modify existing sources there or add new sources.

Setting up a new import source is easy. Press the "Add New Source" button. You will then be asked to select the source type (from which type of "server" the imported files will retrieved from) to create, as well as to assign a name to the source which can be used to identify the source in import profiles and logs. Press the Continue button. You will then be presented with the source configuration.

Source Types

Local Directory

This source type will simply fetch imported files from a local directory on the Magento server.

If you begin the path with a dot in front of it, for example ./var/import/ the path will be relative to the Magento root directory. This means the file would be loaded from the /var/import/ directory located in the root directory of Magento.

Supplying an absolute path is possible by beginning the path with a dash, for example: /var/www/tmp/import/

Please make sure the path you enter is readable by the webserver. It must be possible for the webserver to read the files in that directory, otherwise a warning will be shown/logged.

FTP Server

The FTP source type supports downloading files from FTP servers.

The following configuration must be entered for FTP servers:

 Field Name  Description
IP or Hostname Enter the hostname (address) or IP address of the FTP server you want to download files from
Server Type You can select FTP or FTPS server types. Please note that FTPS (FTP "with SSL") is only supported if PHP has been compiled with OpenSSL support and also the PHP implementation is quite picky with regards to which servers it supports.
Port Enter port of FTP server. This is port 21 usually.
Username Enter the username used to log into the FTP server
Password Enter the password used to log into the FTP server
Timeout Connection timeout in seconds after which the connection will fail
Enable Passive Mode If your server is behind a firewall, or if the extension has problems downloading the import files, please set this to "Yes".
Import Directory Enter the directory from which files should be downloaded from
Filename Pattern This needs to be a valid regular expression. The regular expression will be used to detect import files. The import will fail if the pattern is invalid. Example: /csv/i for all files with the csv file extension or for all files in the import directory: //
Archive Directory If you want to move the imported file(s) to another directory after they have been processed, please enter the path here. This is the absolute path to the archive directory on the FTP server. This directory has to exist on the FTP server. Leave empty if you don't want to archive the import files.
Delete imported files Set this to "Yes" if you want to delete the imported file from the FTP server after it has been processed. You can't delete and archive at the same time, so choose either this option or the archive option above.
Potential issues: Connection/upload fails
SFTP Server

The SFTP (Secure File Transfer Protocol) source type is identical with the FTP source type, except that it loads files from a SFTP server. This source type supports SFTPv3 servers only. To find out which SFTP server version your server is using, connect to it using WinSCP (download here and look at the very bottom status bar. It will show the SFTP server version.

Most of the time port 22 is used for SFTP servers.

Potential issues: Connection/upload fails
HTTP Server

To download files from a HTTP server, please follow the following steps:

  1. Go into the app/code/local/Xtento/StockImport/Model/Source/ directory and rename the file "Http.php.sample" to "Http.php"
  2. Enter the function name you want to call in the Http.php class in the field below.
  3. Open the Http.php file and add a function that matches the function name you entered. This function will be called by this source upon importing then.

Example: If you enter server1 in the function name field below, a method called server1() must exist in the Http.php file. This way multiple HTTP servers can be added to the HTTP class, and can be called from different import source, separated by the function name that is called. The function you add then gets called whenever this source is executed by an import profile.

Important: Please make sure the function you enter exists like this in the app/code/local/Xtento/StockImport/Model/Source/Http.php file: public function yourFunctionName() { ... }

Potential issues: Connection fails
  1. Please go through the steps above one or two more times again to make sure you really set it up exactly as explained.
  2. Please make sure there is no firewall blocking outgoing HTTP connections. Get in touch with your hoster if in doubt.
Webservice/API

To import data from a webservice, please follow the following steps:

  1. Go into the app/code/local/Xtento/StockImport/Model/Source/ directory and rename the file "Webservice.php.sample" to "Webservice.php"
  2. Enter the function name you want to call in the Webservice.php class in the field below.
  3. Open the Webservice.php file and add a function that matches the function name you entered. This function will be called by this source upon importing then.

Example: If you enter server1 in the function name field below, a method called server1() must exist in the Webservice.php file. This way multiple webservices can be added to the Webservice class, and can be called from different import source, separated by the function name that is called. The function you add then gets called whenever this source is executed by an import profile.

Important: Please make sure the function you enter exists like this in the app/code/local/Xtento/StockImport/Model/Source/Webservice.php file:

public function yourFunctionName() { ... }

Potential issues: No connection
  1. Please go through the steps above one or two more times again to make sure you really set it up exactly as explained.
  2. Please make sure there is no firewall blocking outgoing HTTP connections. Get in touch with your hoster if in doubt.
Custom Code / Custom Class

You can set up an own class in our (or another) module which gets called when importing. The loadFiles() function would be called in your class. If your class was called Xtento_StockImport_Model_Source_Myclass then the identifer to enter here would be xtento_stockimport/source_myclass

Please make sure the following function exists in your custom class: public function loadFiles() { ...your code here... }

Logging errors in the profile log for custom sources

If you developed a custom class or set up a custom webservice/HTTP connection function, and in case of errors want to log them in the execution log, you can access the log entry like this to add a warning for example:

$logEntry = Mage::registry('stock_import_log');
$logEntry->setResult(Xtento_StockImport_Model_Log::RESULT_WARNING);
$logEntry->addResultMessage(Mage::helper('xtento_stockimport')->__('Source "%s" (ID: %s): %s', $this->getSource()->getName(), $this->getSource()->getId(), 'Something went wrong'));

Enabling Import Sources in Profiles

To associate created import sources to import profiles, open an import profile and go to the Import Sources tab and select the import sources where the file should be sent to by selecting the checkbox in front of it. Then save the profile.

You can associate an unlimited number of sources to a profile.

Using the extension

The following functions can found at Catalog > Stock Import.

Manual Import

Importing updates manually is easy. After configuring the extension and creating profiles, just go to Catalog > Stock Import > Manual Import.

First of all, select the profile you want to import. You can then select a file to upload (no files will be loaded from configured sources then) OR if you don't select a file to upload, files will be downloaded from configured sources in the import profile.

There are two more options to enable here. Test Mode and Debug Mode. If test mode is enabled, no real updates will be imported, nothing will be updated. If debug mode is enabled, a detailed log showing information about the last import will be shown. Both can be enabled at the same time.

If you're ready to import, just press the Import button. You will be presented with a success message if the import completed successfully. (Or an error message alternatively)

Automatic Import

To set up automatic imports, please have a look at the Automatic Import section configurable for each import profile. You can check/control whether automatic imports were made or not in the Execution Log.

Execution Log

The profile execution log shows any imports made using all profiles, be it manual or automatic.

Tools

Export Settings

The extension comes with functionality to export certain module configuration. All or certain import profiles as well as import sources can be selected for exporting at Catalog > Stock Import > Tools, and can be exported by simply pressing the Export Settings button then. The exported file (ending in .json) can then be imported into another Magento installation using the Import Settings functionality, making it very easy to transfer your settings between development/staging/test/live environments or for clients.

Import Settings

The extension comes with functionality to import certain module configuration from other Magento installations. This means if you've previously exported import profiles or import sources using the Export Settings functionality, you can import it here again.

Please note no passwords of import sources will be imported. These will have to be re-entered manually for destinations.

Questions? Concerns?

Got questions? Feel free to contact us! Contact Form

Interested in this Magento Extension?

Head over to our store to purchase this extension: Magento Stock Import Module

Troubleshooting

Or: How to fix the most common issues.

FTP Download does not work

Multi Warehouse Extensions

We do support third party extensions that add the ability to manage stock on a per-website/per-store level to Magento. However, only extensions which use the stock_id in the cataloginventory_stock* tables are supported. Extensions that set up custom tables in the database to manage the stock are not supported, as this is not the default tables that Magento would use. Currently, we are aware of the following extensions that use the cataloginventory_stock tables: InnoExts/Merchant Protocol, BoostMyShop ERP

To enable support for multi warehouse extensions, please update the Stock Import Module to at least version 2.2.1 (released Nov 17, 2014).

You can then map the "stock_id" field in the "File Configuration" tab of the import profile. This can be set to a static value then (for example, use stock_id 3 (=warehouse ID of your multi-warehouse extension) for all imports of this profile), or you can map it to a column in your import file and thus import stock levels on a per-store/website level.

Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[...]' for key 'PRIMARY'

If this error shows up when importing, conflicting files are located in the import source directory. If there are two or more files that contain the same products, the module doesn't know which data is the one to use/update and thus fails because of inconsistent data in the import files. Make sure no conflicting data is in the import directories, i.e. a SKU should never be in two files at the same time when importing, as the modules doesn't know which value to use for the update.

Cannot filter in extension grids (Execution Log, ...)

This is caused by the BL_CustomGrid extension. Please go to System > Custom Grids > List (Manage Custom Grids) and disable all XTENTO related grids.

Personal tools
Namespaces
Variants
Actions
General Information
Magento 1 Guides
Magento 1 Extensions
Magento 2 Guides
Magento 2 Extensions
Magento Integration Suite
Product Feed Guides
Toolbox