百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

magento1-Ho_Import

> 编程语言
开源

一个 Magento 模块,可让您映射字段并导入各种文件格式、源和实体。速度快,内存占用低

173 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

一个 Magento 模块,可让您映射字段并导入各种文件格式、源和实体。速度快,内存占用低

H&O Importer

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:

xml

    customer
    
        http://google.nl/file.xml
    
    
        var/import/Archief.zip
        var/import/extracted
    
    
        var/import/Klant.xml
        
    
    
        
        
    
    
        
        
        
    
    
        
        
        
            
            
                
                
            
        
        
        
        
        
        
        
        
        
        
            
            
                
                
                
            
        
    

Installation

You can install the module via modman:

bash
modman clone [email protected]:ho-nl/magento1-Ho_Import.git

Or you can download the latest release it and place it in you Magento root.

Getting started

1. Create a module

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)

xml

	
		
			0.1.0
		
	
	
		
            
                Ho_ImportJanselijn_Helper
            
        

        

        
            
				customer
				
            
        
    

2. Add the default config

This section assumes that you place these config values in ``

Add something like the following to your profile (see chapters below for detailed configuration):

xml
customer

    http://google.nl/file.xml

    var/import/Klant.xml
    

    
    
    1

 

3. Run the line shell utility

Make sure you have cache disabled, because all XML is cached in Magento

bash
php hoimport.php -action line -profile profile_name

You'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.

4. Expand all the fieldmaps to your liking

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.

5. Run the actual import

You can now import the complete set.

bash
php hoimport.php -action import -profile profile_name -dryrun 1

To 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.

bash
php hoimport.php -action line -profile profile_name -search sku=abd

6. Schedule an import (cronjob)

If 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.

Config documentation

This section assumes that you place these config values in ``

Supported Entity Types

All the entities of the [AvS_FastSimpleImport][] are supported:

  • catalog_product
  • customer
  • catalog_category
  • catalog_category_product

Example Config:

xml
customer

Cron schedule

Use the same formatting as the default cron setup.

Using a cron expression:

xml
0 2 * * *

Using a config path:

xml
configuration/path/cron_expr

Import Options

All the options that are possible with the [AvS_FastSimpleImport][] are possible here as well:

xml

    1
    1
    1 

    
	10000
    1
    1
    0
    1
    
        country
    
    
        show_in_collection
        condition
        condition_label
    

Lock product/category attributes in backend

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:

xml

    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:

Archive import files

After starting a new import the old import file gets renamed so it wont get deleted, easy for later referencing and debugging.

xml

    1

Clean entities that are not in the source

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.

xml

    hide 

Multiple imports for the same product

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:

xml

If you have only one profile with lock_attributes enabled, this field gets filled automatically.

Downloaders

The supported downloaders are HTTP and FTP.

HTTP Example (Low Memory)

xml

    http://google.nl/file.xml

    
    

FTP Example (Low Memory)

xml

    ftp.website.com
    2121 
    userr
    supersecurepassword
    httpdocs/file.xml 
    var/import/file.xml 
    10 
    0 
    1 
    1

Temporarily disable a download:

xml

	1

Decompressors

Decompress a file that has just been downloaded.

Zip Example (Low Memory)

xml

    var/import/Archief.zip
    var/import/extracted 

Sources

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.

CSV Source (Low Memory)

The CSV source is an implementation of PHP's fgetcsv

xml

    var/import/customer.csv

    
    ;
    
    
    
    
    	
    	
    

XML Source (Low Memory)

The XML source is loosely based on XmlStreamer.

xml

    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.

Example:

If you have the following XML file and you want to retrieve all the `` nodes:

xml

	
		
			10
			
				2
				
					
				
				
                    
                
			
		
		
			10
            
                3
                
                    
                
            
		
	

This would result in the following configuration:

xml

    path/to/you/file.xml
    BODY
	ARTICLE

Spreadsheet Source (Low Memory)

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.

xml

    var/import/products.xml

    
    

Database Source

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.

xml

    
    
    
    
    
    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

Events

All events work with a transport object which holds the data for that line. This a Varien_Object with the information set.

xml

	
	
	
	
	
	
	

Event: import_before

  • object: instance of AvS_FastSimpleImport_Model_Import

Event: source_row_fieldmap_before

It 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.

Event: import_after

  • object: instance of AvS_FastSimpleImport_Model_Import
  • errors: array of errors

Fieldmap

This 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 ``

Value

xml

Field

xml

In multi-level files like XML you can get a deeper value with a /

xml

If there are attributes available, you can reach them with @attributes.

xml

Helper

Have the ability to call a helper method that generates the value. The contents of the field are the arguments passed to the helper.

xml
1

Calls the method in the class Ho_Import_Helper_Import with the first argument being the line and the rest of

Issues· 6 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言