zookal/ho-nl-ho_import

此包已被放弃,不再维护。未建议替代包。

一个允许您映射字段并导入各种文件格式、来源和实体的 Magento 模块。快速且内存低。

安装: 12

依赖项: 0

建议者: 0

安全性: 0

星标: 1

关注者: 3

分支: 54

类型:magento-module

dev-master 2019-02-13 01:26 UTC

This package is not auto-updated.

Last update: 2020-08-22 07:17:52 UTC


README

这是一个 Magento 模块,也是 AvS_FastSimpleImport 模块的扩展,允许您映射字段并导入各种文件格式、数据源和数据实体。

该模块包含各种下载器(http)、源适配器(csv、电子表格、数据库或xml),并支持 AvS_FastSimpleImport 支持的所有实体(产品、类别、客户),最重要的是允许您将每个格式的所有字段映射到 Magento 格式。

所有这些配置都可以使用 XML 完成。您将配置添加到 config.xml 中,然后可以运行配置文件。想法是将所有配置放在 XML 中,然后您或 cron 以最佳选项运行它。

由于该模块的原始目标是能够处理数千个产品的导入,因此它是以此为目的构建的。它能够在使用非常少的内存(例如,处理 1GB CSV 文件时,内存增加几 MB)的同时处理大型 CSV 或 XML 文件。见 用例

我们选择在 XML 中进行所有配置,这使得导入配置文件更容易维护,特别是在为单个项目进行多次导入时尤为重要。

为了提高开发和调试速度,有一个功能丰富的 shell 工具,允许您轻松创建新的字段映射、添加下载器并开始工作。

Terminal Preview

客户导入示例配置(这被添加到 <config><global><ho_import> 节点中)

<my_customer_import>
    <entity_type>customer</entity_type>
    <downloader model="ho_import/downloader_http">
        <url>http://google.nl/file.xml</url>
    </downloader>
    <decompressor model="ho_import/decompressor_zip">
        <source>var/import/Archief.zip</source>
        <target>var/import/extracted</target>
    </decompressor>
    <source model="ho_import/source_adapter_xml">
        <file>var/import/Klant.xml</file>
        <!--<rootNode>FMPDSORESULT</rootNode>-->
    </source>
    <import_options>
        <!--<continue_after_errors>1</continue_after_errors>-->
        <!--<ignore_duplicates>1</ignore_duplicates>-->
    </import_options>
    <events>
        <!--<source_row_fieldmap_before helper="ho_importinktweb/product::prepareRowCategory"/>-->
        <!--<import_before/>-->
        <!--<import_after/>-->
    </events>
    <fieldmap>
        <email field="Email"/>
        <_website helper="ho_import/import::getAllWebsites"/>
        <group_id helper="ho_import/import::getFieldMap">
            <field field="Status"/>
            <mapping>
                <particulier from="Particulier" to="1"/>
                <zakelijk from="Zakelijk" to="2"/>
            </mapping>
        </group_id>
        <prefix field="Voorletters"/>
        <firstname field="Voornaam" defaultvalue="ONBEKEND"/>
        <middlename field="Tussenvoegsel" />
        <lastname field="Achternaam" required="1"/>
        <company field="Bedrijfsnaam"/>
        <created_in value="old shop name"/>
        <taxvat field="BTWnummer" />
        <password field="cWachtWoord" />
        <gender helper="ho_import/import::getFieldMap">
            <field field="Geslacht"/>
            <mapping>
                <male from="M" to="male"/>
                <female from="V" to="female"/>
                <male_female from="M+V" to="male+female"/>
            </mapping>
        </gender>
    </fieldmap>
</my_customer_import>

安装

您可以通过 modman 安装此模块

modman clone git@github.com:ho-nl/Ho_Import.git

或者您可以直接 下载最新版本 并将其放置在您的 Magento 根目录中。

入门

1. 创建一个模块

想法是您为每个项目或导入创建一个非常轻量级的模块。此模块包含特定导入的所有配置。

需要帮助为您的安装创建空模块,请使用 模块创建器

示例配置

<config>
	<modules>
		<Ho_ImportJanselijn>
			<version>0.1.0</version>
		</Ho_ImportJanselijn>
	</modules>
	<global>
		<helpers>
            <ho_importjanselijn>
                <class>Ho_ImportJanselijn_Helper</class>
            </ho_importjanselijn>
        </helpers>

        <!-- ... -->

        <ho_import>
            <profile_name>
				<entity_type>customer</entity_type>
				<!-- ... the rest of the config -->
            </profile_name>
        </ho_import>
    </global>
</config>

2. 添加默认配置

本节假定您将这些配置值放在 <config><global><ho_import><my_import_name>

将以下内容添加到您的配置文件中(有关详细配置,请参阅以下章节)

<entity_type>customer</entity_type>
<downloader model="ho_import/downloader_http">
    <url>http://google.nl/file.xml</url>
</downloader>
<source model="ho_import/source_adapter_xml">
    <file>var/import/Klant.xml</file>
    <!--<rootNode>FMPDSORESULT</rootNode>-->
</source>
<import_options>
    <!--<continue_after_errors>1</continue_after_errors>-->
    <!--<ignore_duplicates>1</ignore_duplicates>-->
    <partial_indexing>1</partial_indexing>
</import_options>

3. 运行行 shell 工具

确保您已禁用缓存,因为所有 XML 都在 Magento 中缓存

php hoimport.php -action line -profile profile_name

您将看到类似以下内容:终端预览

第一张表格显示了源文件的第一个行,第二张表格显示了它们在导入到Magento时的结果。它显示了每一行表示的错误。

4. 根据您的喜好展开所有字段映射

从docs/imports文件夹中找到您最喜欢的一个示例,并将其字段复制到您的配置中。

现在继续映射所有字段,直到您满意为止。

5. 运行实际导入

现在您可以导入整个集合。

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

要测试导入是否可以运行,请在命令中添加-dryrun 1

您可能会在第一次尝试时遇到错误。当导入器遇到错误时,它将返回有问题的行。它将返回已导入的行(遗憾的是,它不会返回源行,因为此时源行还不为人知)。

如果您遇到特定sku等问题,可以运行行工具并执行搜索。

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

6. 安排导入(cronjob)

如果您对导入满意,可以为它添加一个时间表,这会将它添加到cron计划程序,并在您配置的时间运行。

Terminal Preview

如您所见,我们有一个ho_import_schedule cron,它会将导入添加到cron,并在导入被删除/重命名时清理cron。为了加快这一过程,您可以手动运行它。

配置文档

本节假定您将这些配置值放在 <config><global><ho_import><my_import_name>

支持实体类型

支持所有AvS_FastSimpleImport的实体。

  • catalog_product
  • customer
  • catalog_category
  • catalog_category_product

示例配置

<entity_type>customer</entity_type>

cron时间表

使用与默认cron设置相同的格式。

使用cron表达式

<schedule><cron_expr>0 2 * * *</cron_expr></schedule>

使用配置路径

<schedule><config_path>configuration/path/cron_expr</config_path></schedule>

导入选项

在这里可以执行所有与AvS_FastSimpleImport相关的选项。

<import_options>
	<error_limit>10000</error_limit>
    <continue_after_errors>1</continue_after_errors>
    <ignore_duplicates>1</ignore_duplicates>
    <allow_rename_files>0</allow_rename_files>
    <partial_indexing>1</partial_indexing>
    <skip_download>1</skip_download>
    <lock_attributes>1</lock_attributes>
    <dropdown_attributes>
        <country>country</country>
    </dropdown_attributes>
    <multiselect_attributes>
        <show_in_collection>show_in_collection</show_in_collection>
        <condition>condition</condition>
        <condition_label>condition_label</condition_label>
    </multiselect_attributes>
</import_options>

在后台锁定产品/类别属性

当您启用此选项时,商店管理员无法编辑导入器导入的属性。Ho_Import对此很智能,它会保存配置文件名与产品/类别一起,所以它只会锁定由当前导入器设置的属性。它还了解导入的特定商店视图值。

示例配置

<import_options>
    <lock_attributes>1</lock_attributes>
</import_options>

当导入产品名称时,它显示属性被锁定锁定属性

如果您切换到商店视图,可以覆盖字段:Lock Attributes

同一产品的多次导入

如果您对同一产品(例如产品信息和库存信息)有多次导入,您必须手动定义与产品关联的配置文件。

在您的 <fieldmap> 节点中,添加以下内容

<ho_import_profile value="profile_one,profile_two"/>

如果您只有一个启用了 lock_attributes 的配置文件,则此字段将自动填充。

下载器

支持的下载器是HTTP和FTP。

HTTP 示例(✅ 低内存)

<downloader model="ho_import/downloader_http">
    <url>http://google.nl/file.xml</url>

    <!-- the downloader defaults to var/import -->
    <!--<target>custom/download/path/filename.xml</target>-->
</downloader>

FTP 示例(✅ 低内存)

<downloader model="ho_import/downloader_ftp">
    <host>ftp.website.com</host>
    <username>userr</username>
    <password>supersecurepassword</password>
    <file>httpdocs/file.xml</file> <!-- Relative path on the server, relative from the login -->
    <target>var/import/file.xml</target> <!-- Path relative from the Magento root -->
    <timeout>10</timeout> <!-- Optional: How long should we wait to connect -->
    <passive>0</passive> <!-- Optional: FTP transfer mode, by default it is set to passive, usually correct -->
    <ssl>1</ssl> <!-- Optional: For FTP with implicit SSL, this is NOT SFTP, which is FTP over SSH -->
    <file_mode>1</file_mode><!-- Optional: For FTP_ASCII or FTP_TEXT set value to 1, for FTP_BINARY or FTP_IMAGE leave empty.
</downloader>

暂时禁用下载

<import_options>
	<skip_download>1</skip_download>
</import_options>

解压缩器

解压缩刚刚下载的文件。

Zip 示例(✅ 低内存)

<decompressor model="ho_import/decompressor_zip">
    <source>var/import/Archief.zip</source>
    <target>var/import/extracted</target> <!-- this is a folder, files inside the archive will be placed here -->
</decompressor>

来源

来源是一个源读取器。源允许我们从某个来源读取数据。这可能是一个文件,甚至可能是一个数据库。

CSV 来源(✅ 低内存)

CSV 来源是PHP的 fgetcsv 的实现。

<source model="ho_import/source_adapter_csv">
    <file>var/import/customer.csv</file>

    <!-- the delimmiter and enclosure aren't required -->
    <!--<delimiter>;</delimiter>-->
    <!--<enclosure></enclosure>-->
</source>

XML 来源(✅ 低内存)

XML 来源基于 XmlStreamer

<source model="ho_import/source_adapter_xml">
    <file>var/import/products.xml</file>

    <!-- If there is only one type of entity in the XML the custom rootNode isn't required. -->
    <rootNode>customRootNode</rootNode>

    <!-- You have the ability to define a custom childNode if the childNode isn't the direct ascendent of the rootNode -->
	<childNode>customChildNode</childNode>
</source>

注意:尚未测试childNode/rootNode是否在文档的深处。代码已经到位,但尚未测试。如果您有机会进行测试,请创建一个问题并让我们知道您发现了什么。

示例

如果您有以下XML文件,并且您想检索所有 <ARTICLE> 节点

<?xml version="1.0" encoding="utf-8"?>
<ARTICLES>
	<BODY>
		<COMPANY-NR>
			<COMPANY>10</COMPANY>
			<SHOP>
				<SHOPNR>2</SHOPNR>
				<ARTICLE>
					<!-- ... -->
				</ARTICLE>
				<ARTICLE>
                    <!-- ... -->
                </ARTICLE>
			</SHOP>
		</COMPANY-NR>
		<COMPANY-NR>
			<COMPANY>10</COMPANY>
            <SHOP>
                <SHOPNR>3</SHOPNR>
                <ARTICLE>
                    <!-- ... -->
                </ARTICLE>
            </SHOP>
		</COMPANY-NR>
	</BODY>
</ARTICLES>

这将产生以下配置

<source model="ho_import/source_adapter_xml">
    <file>path/to/you/file.xml</file>
    <rootNode>BODY</rootNode>
	<rootNode>ARTICLE</rootNode>
</source>

电子表格来源(✅ 低内存)

电子表格来源是 spreadsheet-reader 的实现,因此支持

到目前为止,XLSX、ODS和text/CSV文件解析应该具有内存效率。XLS文件解析使用来自 http://code.google.com/p/php-excel-reader/ 的php-excel-reader进行,遗憾的是,它在大电子表格中存在内存问题,因为它一次读取所有数据并保留在内存中。

<source model="ho_import/source_adapter_spreadsheet">
    <file>var/import/products.xml</file>

    <!-- If the first line has headers you can use that one, else the columns will only be numbered -->
    <!-- <has_headers>1</has_headers> -->
</source>

数据库来源

数据库来源是 Zend_Db_Table_Rowset 的实现,并允许所有实现 Zend_Db_Adapter_Abstract 作为来源。它支持MSSQL、MySQL、PostgreSQL、SQLite等。有关所有可能支持的数据库,请查看 /lib/Zend/Db/Adapter

当前的实现不是低内存,因为它执行查询并将所有内容加载到内存中。

<source model="ho_import/source_adapter_db">
    <host><![CDATA[hostname]]></host>
    <username><![CDATA[username]]></username>
    <password><![CDATA[password]]></password>
    <dbname><![CDATA[database]]></dbname>
    <model><![CDATA[Zend_Db_Adapter_Pdo_YourFavoriteDatabase]]></model>
    <pdoType>dblib</pdoType>
    <query><![CDATA[SELECT * FROM Customer]]></query>
    <!--<limit>10</limit>-->
    <!--<offset>10</offset>-->
</source>

如果您的PDO驱动程序不支持pdoType,则直接删除该节点。如果您想向PDO驱动程序传递更多配置参数,则可以添加更多节点,例如对于PGSQL:<sslmode>require</sslmode>

事件

所有事件都与一个传输对象一起工作,该对象包含该行的数据。这是一个设置信息的Varien_Object

<events>
	<process_before helper="ho_import/import_product::prepareSomeData"/>
	<import_before helper="ho_import/import_product::callWifeIfItIsOk"/>
	<source_row_fieldmap_before helper="ho_import/import_product::checkIfValid"/>
	<import_after helper="ho_import/import_product::reindexStuff"/>
	<process_after helper="ho_import/import_product::cleanupSomeData"/>
</events>

事件:import_before

  • objectAvS_FastSimpleImport_Model_Import的实例

事件:source_row_fieldmap_before

它有一个字段items设置。这可以替换、扩展等,以操作数据。可选地,您可以设置键skip1以完全跳过此源行。

事件:import_after

  • objectAvS_FastSimpleImport_Model_Import的实例
  • errors:错误数组

字段映射

这是模块魔法发生的地方。将随机源格式映射到Magento格式。

您的想法是在这里指定Magento格式,并加载每个Magento字段的正确值,操作数据等。有一个语法来处理最简单的情况,并且有调用辅助程序的能力,如果这还不够。

重用字段映射数据。
在导入突变并发生完整导入(例如,每晚的完整运行,每15分钟一次的突变)时,您可能想使用不同配置文件的字段映射。为此,您只需要添加<fieldmap use="name_of_other_profile" />

本节假定您将这些配置值放在<config><global><ho_import><my_import_name><fieldmap>

<tax_class_id value="2"/>

字段

<email field="Email"/>

在多级文件(如XML)中,您可以使用/获取更深的值。

<email field="Customer/Email"/>

如果有属性可用,您可以使用@attributes访问它们。

<sku field="@attributes/RECORDID"/>

辅助程序

有调用生成值的辅助程序方法的能力。字段内容是传递给辅助程序的参数。

<_website helper="ho_import/import::getAllWebsites"><limit>1</limit></_website>

调用类Ho_Import_Helper_Import中的方法,第一个参数是行,其余参数是节点中的内容,在这种情况下是限制。

/**
 * Import the product to all websites, this will return all the websites.
 * @param array $line
 * @param $limit
 * @return array|null
 */
public function getAllWebsites($line, $limit) {
    if ($this->_websiteIds === null) {
        $this->_websiteIds = array();
        foreach (Mage::app()->getWebsites() as $website) {
            /** @var $website Mage_Core_Model_Website */

            $this->_websiteIds[] = $website->getCode();
        }
    }

    if ($limit) {
        return array_slice($this->_websiteIds, 0, $limit);
    }

    return $this->_websiteIds;
}

有关更多可用的辅助程序,请参阅集成辅助方法自定义辅助方法

使用

有时您想在多个字段中多次使用相同的值。这加载其他字段的配置并返回结果。

<image_label use="name"/>

默认值

<firstname field="First_Name" defaultvalue="UNKNOWN"/>

如果字段值

<company iffieldvalue="Is_Company" field="Company_Name"/>

除非字段值

iffieldvalue的对立面

<firstname unlessfieldvalue="Is_Company" field="Customer_Name"/>

必需

某些字段对于导入程序在每行中始终是必需的。例如,对于产品,您必须有sku字段始终存在。

<sku field="sku" required="1"/>

设置商店视图特定数据

通过简单地向配置文件中添加内容,可以设置商店视图特定数据。您具有与正常字段完全相同的权限,只需为每个商店视图提供 <store_view> 元素的字段。

<description field="description_en">
    <store_view>
        <pb_de field="description_de"/>
        <pb_es field="description_es"/>
        <pb_fr field="description_fr"/>
        <pb_it field="description_it"/>
        <pb_nl field="description_nl"/>
    </store_view>
</description>

集成辅助方法

已定义了一些辅助方法,允许您进行一些常见的操作,而无需编写自己的辅助方法。

getAllWebsites

<_website helper="ho_import/import::getAllWebsites">
	<limit>1</limit> <!-- optional -->
</_website>

findReplace

<short_description helper="ho_import/import::findReplace">
	<value field="sourceField"/>
    <findReplace>
        <doubleat find="@@" replace="@"/>
        <nbsp from="&nbsp;" replace=" "/>
    </findReplace>
    <trim>1</trim> <!-- optional -->
</short_description>

parsePrice

<price helper="ho_import/import::parsePrice">
    <pricefield field="PrijsVerkoop"/>
</price>

formatField

实现 vsprinf

<meta_description helper="ho_import/import::formatField">
    <format>%s - For only €%s at Shop.com</format>
    <fields>
        <description field="Info"/>
        <price field="PrijsVerkoop"/>
    </fields>
</meta_description>

truncate

<description helper="ho_import/import::truncate">
    <value field="Info"/>
    <length>125</length>
    <etc>…</etc>
</description>

stripHtmlTags

<description helper="ho_import/import::stripHtmlTags">
    <value field="A_Xtratxt"/>
    <allowed><![CDATA[<p><a><br>]]></allowed>
</description>

getHtmlComment

获取一个简单的HTML注释(由于XML的限制,无法通过XML添加)。

<description helper="ho_import/import::getHtmlComment">empty</description>

getFieldBoolean

<is_in_stock helper="ho_import/import::getFieldBoolean">
	<value field="stock"/>
</is_in_stock>

getFieldMultiple

允许您加载多个字段。每个字段都具有与正常字段相同的权限(允许您调用辅助方法、值、字段、iffieldvalue等)。

<_address_prefix helper="ho_import/import::getFieldMultiple">
    <fields>
        <billing iffieldvalue="FactAdres" field="Voorvoegsel"/>
        <shipping iffieldvalue="BezAdres" field="Voorvoegsel"/>
    </fields>
</_address_prefix>

getFieldLimit

实现 array_slice

<image helper="ho_import/import::getFieldLimit">
    <field use="_media_image"/>
    <limit value="1"/> <!-- optional -->
    <offset value="1"/> <!-- optional -->
</image>

getFieldCombine

获取多个字段并将它们粘合在一起。

<sku helper="ho_import/import::getFieldCombine">
    <fields>
        <prefix value="B"/>
        <number field="BmNummer"/>
    </fields>
    <glue>-</glue> <!-- optional, defaults to a space -->
</sku>

getFieldSplit

将字段分割成多个部分。

<_category helper="ho_import/import::getFieldSplit">
    <field field="category"/>
    <split>***</split>
</_category>

getFieldMap

<gender helper="ho_import/import::getFieldMap">
    <value field="Geslacht"/>
    <mapping>
        <male from="M" to="male"/>
        <female from="V" to="female"/>
    </mapping>
</gender>

getFieldCounter

<_media_position helper="ho_import/import::getFieldCounter">
    <countfield field="cImagePad"/>
</_media_position>

ifFieldsValue

您通常可以定义 iffieldvalue='fieldname' 来进行简单的值检查。您需要检查多个字段的情况。

<billing_first_name helper="ho_postbeeldproduct/import_customer::ifFieldsValue">
    <fields>
        <billing_first_name field="billing_first_name"/>
        <billing_last_name field="billing_last_name"/>
        <billing_address field="billing_address"/>
        <billing_city field="billing_city"/>
        <billing_country_code field="billing_country_code"/>
    </fields>
    <billing field="billing_first_name"/>
</billing_first_name>

getMediaAttributeId (@已弃用,在1.5中使用getAttributeId)

通常与计数器结合使用,以设置正确的getMediaAttributeId。

<_media_attribute_id helper="ho_import/import::getFieldCounter">
    <countfield field="cImagePad"/>
    <fieldvalue helper="ho_import/import::getMediaAttributeId"/>
</_media_attribute_id>

getAttributeId

获取属性ID。

<field helper="ho_import/import::getAttributeId">
    <attribute value="media_gallery"/>
</field>

getMediaImage

从远程URL下载图片并将其放置在 media/import 文件夹中。

<image helper="ho_import/import::getMediaImage">
    <imagefield field="cImagePad"/>
    <limit>1</limit>
    <filename use="sku"/> <!-- optional, when the server doesn't give back readable image names -->
    <extension value="jpg"/> <!-- optional, when the URL doesn't end in a filename -->
</image>

timestampToDate

解析时间戳并以Magento运行的格式输出,只需指定当前日期所在的时区。使用相对格式之一添加偏移量。

<news_to_date helper="ho_import/import::timestampToDate">
    <field field="entry_date"/>
    <timezoneFrom>Europe/Amsterdam</timezoneFrom>
    <offset>3 day</offset>
</news_to_date>

产品:getUrlKey

<url_key helper="ho_import/import_product::getUrlKey">
    <fields>
        <name field="Titel"/>
    </fields>
    <glue>-</glue>
</url_key>

类别:getUrlKey

<url_key helper="ho_import/import_category::getUrlKey">
    <fields>
        <name field="Titel"/>
    </fields>
    <glue>-</glue>
</url_key>

客户:mapCountryIso3ToIso2

<billing helper="ho_import/import_customer::mapCountryIso3ToIso2">
    <field field="billing_country_code"/>
</billing>

客户:mapCountryIso2ToIso3

<billing helper="ho_import/import_customer::mapCountryIso2ToIso3">
    <field field="billing_country_code"/>
</billing>

自定义辅助方法

并非所有情况都是简单的值处理,可能需要使用更复杂的逻辑。您有权限轻松地为每个项目创建自己的辅助方法。只需创建自己的辅助类并调用该类。

示例:为了确定一个地址是否是默认地址,我们创建两个字段

<_address_default_billing_  helper="ho_importjanselijn/import_customer::getAddressDefaultBilling"/>
<_address_default_shipping_ helper="ho_importjanselijn/import_customer::getAddressDefaultShipping"/>

并创建一个包含以下方法的辅助类:

class Ho_ImportJanselijn_Helper_Import_Customer extends Mage_Core_Helper_Abstract
{

    public function getAddressDefaultBilling($line) {
        if ($line['InvAddress']) { //there is a billing and shipping address
            return array(1,0);
        } else { //there is only a shipping address
            return 1;
        }
    }

    public function getAddressDefaultShipping($line) {
        if ($line['InvAddress']) { //there is a billing and shipping address
            return array(0,1);
        } else { //there is only a shipping address
            return 1;
        }
    }
}

如您所见,它有时返回一个值数组,有时只返回一个值。如果您的辅助方法返回一个值数组,Ho_Imports 将内部将这些多个值重写为多个导入行

CLI / Shell 工具

导入器附带的 shell 工具是您将花费大部分时间的地方。

line

php hoimport.php  -action line
	-profile profile_name             Available profiles:    janselijn_customers
	-line 1,2,3                       Comma separated list of lines to be checked
	-search sku=abd                   Alternatively you can search for a value of a field

import

php hoimport.php -action import
	-profile profile_name             Available profiles:    janselijn_customers
	-partial_indexing 1               When done importing will the imported products be indexed or will the whole system be indexed
	-continue_after_errors 1          If encountered an error, will we continue, sometimes one row is corrupt, but the rest is fine
	-dropdown_attributes attr1,attr2  Comma separated list of dropdownattributes that are autofilled when importing.
	-rename_files 0                   Normally, when importing, images are renamed if an image exists. Set this to 0 to overwrite images
	-dryrun 1                         Run a dryrun, validate all data agains the Magento validator but do not import anything
	-ignore_duplicates 1              Ignore duplicates.;
	-error_limit 10000                Set the error limit, default=100 error lines.;

日志记录

有两种日志记录模式:CLI 和 cron 模式。在 CLI 模式下,它始终记录到 CLI 并尝试添加漂亮的颜色等。在 cron 模式下,它将记录到日志文件,并还可以在管理员面板的消息收件箱中记录。

在您的代码中调用导入器

这非常简单

protected function _importCustomers($memberIds) {
    Mage::getModel('ho_import/import')
        ->setProfile('postbeeld_customers')
        ->setSourceOptions(array('member_id' => implode(',', $memberIds)))
        ->process();

    Mage::helper('ho_import/log')->done();
    return $this;
}

文件日志记录

由 cron 运行的每个导入都在 var/ho_import.log 中保存。

管理员面板通知

有时您想在出现错误时在管理员面板中显示一条消息。默认情况下,系统仅在出现警告时创建管理员面板消息。

EMERG   = 0;  // Emergency: system is unusable
ALERT   = 1;  // Alert: action must be taken immediately
CRIT    = 2;  // Critical: critical conditions
ERR     = 3;  // Error: error conditions
WARN    = 4;  // Warning: warning conditions
NOTICE  = 5;  // Notice: normal but significant condition
INFO    = 6;  // Informational: informational messages
DEBUG   = 7;  // Debug: debug messages
SUCCESS = 8;  // Success: When everything is going well.

将这些配置值放在 <config><global><ho_import><my_import_name> 中以更改添加管理员面板消息的级别。

<log_level>6</log_level>

用例

在发布时,我们已为多个客户运行此工具,进行多种类型的导入

  • 从旧数据源进行一次性产品/类别导入 示例配置
  • 定期进行具有多个商店视图值的类别导入 示例配置
  • 15 分钟仅库存更新
  • 夜间完整库存更新 示例配置
  • 夜间价格更新
  • 从 ERP 系统进行增量类别/产品更新
  • 客户导入 示例配置
  • 客户导入带有账单和发货地址 示例配置

性能

目前我们没有实际的基准测试,但字段映射所花费的时间比实际导入快一个数量级。

许可证

OSL - 开源软件许可证 3.0

支持

如果您需要关于该模块的帮助,请在 GitHub 问题跟踪器 中创建一个问题。

作者

该模块由 Paul Hachmang 编写(twitter: @paales,email: paul@h-o.nl),为 H&O 构建(网站: http://www.h-o.nl/,email: info@h-o.nl,twitter: @ho_nl)。

为什么构建它并将其开源?

在构建了多个产品、类别和客户导入后,我对现有的项目从未真正满意。在用纯代码实现了一个项目后,我们得出结论,创建导入、确保所有字段都正确设置以便 Magento 接受它们、开发迭代速度太慢等,都是相当困难的。

在构建这个模块后,我们认为我们创建了一个对许多 Magento 开发者都有价值的优秀模块,因此将其开源是自然的。通过其他开发者的共同努力,我们可以进一步改进它,修复错误,添加新功能等。