一个 Magento 模块,可让您映射字段并导入各种文件格式、源和实体。速度快,内存占用低
A Magento module and extension of the [AvS_FastSimpleImport][] module which allows you to map fields and import all sorts of file formats, data sources and data entities.
The module consists of various downloaders (http), source adapters (csv, spreadsheets, database or xml) and supports all entities that [AvS_FastSimpleImport][] supports (products, categories, customers) and last but not least allows you to field map all fields in from each format to the magento format.
All this configuration can be done using XML. You add the config to a config.xml and you can run the profile. The idea is that you set all the configuration in the XML and that you or the cron will run it with the perfect options.
Since the original target for the module was an import that could process thousands of products it is build with this in mind. It is able to process large CSV or XML files while using very little memory (think a few MB memory increase for processing a 1GB CSV file). See Use cases
We have chosen to do all configuration in XML, this makes the import profile way more maintainable, especially important when doing multiple imports for a single project.
To increase development and debugging speed there is a extensive shell tool that allows you to easily create new fieldmaps, add a downloader and start working.
Example config for a customer import (this is added to the `` node:
customer
http://google.nl/file.xml
var/import/Archief.zip
var/import/extracted
var/import/Klant.xml
You can install the module via modman:
modman clone [email protected]:ho-nl/magento1-Ho_Import.gitOr you can download the latest release it and place it in you Magento root.
The idea is that you create a very light weight module for each project or import. This module has all the config for that specific import.
_Need help creating an empty module for your installation, use a module creator.
Example config (More import examples)
0.1.0
Ho_ImportJanselijn_Helper
customer
This section assumes that you place these config values in ``
Add something like the following to your profile (see chapters below for detailed configuration):
customer
http://google.nl/file.xml
var/import/Klant.xml
1
Make sure you have cache disabled, because all XML is cached in Magento
php hoimport.php -action line -profile profile_nameYou'll see something like:
The first table shows the first line from the source file and the second table shows the results how they would be imported into Magento. It shows the error on each line where they are represented.
Note that it is not safe to run multiple imports simulteneously. When manually running an import via the command shell, ensure that there is no other import running via (for example) a cron job.
Grab an example that is most to your liking from the docs/imports folder and copy those fields to your config.
Now continue to map all your fields until you are satisfied.
You can now import the complete set.
php hoimport.php -action import -profile profile_name -dryrun 1To just test if the import would run, add -dryrun 1 to the command
You will probably run into errors the first try. When the importer runs into errors it will return the faulty row. It will return the row that is imported (unfortunately it won't return the source row since that row isn't know at this point of the import).
If a specific sku, for example, is giving you trouble, you can run the line utility and do a search.
php hoimport.php -action line -profile profile_name -search sku=abdIf you are satisfied with the import you can add a schedule to it, this will add it to the cron scheduler and run it at your configured time:
As you can see, we have a ho_import_schedule cron which add the imports to the the cron and cleans up the cron if imports are removed/renamed. To speed up this process, you can run it manually.
This section assumes that you place these config values in ``
All the entities of the [AvS_FastSimpleImport][] are supported:
catalog_productcustomercatalog_categorycatalog_category_productExample Config:
customerUse the same formatting as the default cron setup.
Using a cron expression:
0 2 * * *Using a config path:
configuration/path/cron_exprAll the options that are possible with the [AvS_FastSimpleImport][] are possible here as well:
1
1
1
10000
1
1
0
1
country
show_in_collection
condition
condition_label
When you enable this option, a store admin can't edit the attributes that are imported by the importer. Ho_Import is smart about this, it save the profile name with the product/category, so it only locks the attributes which are set by the current importer. It also knows about store view specific values imported.
Exampe config:
1
When importing the name of a product it shows the attribute is locked
If you switch to a store view you can override the field:
After starting a new import the old import file gets renamed so it wont get deleted, easy for later referencing and debugging.
1
Be able to automatically delete, hide or disable products and categories after importing. When enabled, if a product
or category isn't in the source anymore it gets automatically deleted. Ho_Import tracks the entities from which profile
they came from:
If a product for example isn't in the source any more AND it is the only associated profile with the entity it can be cleaned up.
hide
If you have multiple imports for the same product (product information and stock information for example), you have to define the profile associated with the product manually.
In your `` node, add the following:
If you have only one profile with lock_attributes enabled, this field gets filled automatically.
The supported downloaders are HTTP and FTP.
http://google.nl/file.xml
ftp.website.com
2121
userr
supersecurepassword
httpdocs/file.xml
var/import/file.xml
10
0
1
1
1
Decompress a file that has just been downloaded.
var/import/Archief.zip
var/import/extracted
A source is a source reader. The source allows us to read data from a certain source. This could be a file or it even could be a database.
The CSV source is an implementation of PHP's fgetcsv
var/import/customer.csv
;
The XML source is loosely based on XmlStreamer.
var/import/products.xml
customRootNode
customChildNode
Note: It isn't tested if the childNode/rootNode is way down the document. The code is in place, but isn't tested. If you get the chance to test this please create an issue and let us know what you found.
If you have the following XML file and you want to retrieve all the `` nodes:
10
2
10
3
This would result in the following configuration:
path/to/you/file.xml
BODY
ARTICLE
The Spreadsheet Source is an implementation of spreadsheet-reader and therefor supports
So far XLSX, ODS and text/CSV file parsing should be memory-efficient. XLS file parsing is done with php-excel-reader from http://code.google.com/p/php-excel-reader/ which, sadly, has memory issues with bigger spreadsheets, as it reads the data all at once and keeps it all in memory.
var/import/products.xml
The Database source is an implementation of Zend_Db_Table_Rowset and allows all implentation of Zend_Db_Adapter_Abstract as a source. It supports MSSQL, MySQL, PostgreSQL, SQLite and many others. For all possible supported databases take a look in /lib/Zend/Db/Adapter.
The current implementation isn't low memory because it executes the query and loads everything in memory.
dblib
If your PDO driver doesn't support pdoType then simply remove that node. If you wish to pass more config parameters to the PDO driver then add more nodes like for PGSQL: require
All events work with a transport object which holds the data for that line. This a Varien_Object
with the information set.
import_beforeobject: instance of AvS_FastSimpleImport_Model_Importsource_row_fieldmap_beforeIt has one field items set. This can be replaced, extended etc. to manipulate the data. Optionally
you can set the key skip to 1 to skip this source row all together.
import_afterobject: instance of AvS_FastSimpleImport_Model_Importerrors: array of errorsThis is where the magic of the module happens. Map a random source formatting to the Magento format.
The idea is that you specify the Magento format here and load the right values for each Magento field, manipulate the data, etc. There is a syntax to handle the most easy cases and have the ability to call an helper if that isn't enough.
| Reusing fieldmapped data. |
|---|
| When importing mutations and having a complete import happens (complete runs every night for example, mutations every 15 minutes). You might want to use a different profile's fieldmapping. To do this you only need add ``. |
This section assumes that you place these config values in ``
In multi-level files like XML you can get a deeper value with a /
If there are attributes available, you can reach them with @attributes.
Have the ability to call a helper method that generates the value. The contents of the field are the arguments passed to the helper.
1Calls the method in the class Ho_Import_Helper_Import with the first argument being the line and
the rest of
暂无开放 Issues,或尚未同步最近议题。