定制 2lenet/import-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

2lenet/import-bundle

最新稳定版本:2.0.2

Composer 安装命令:

composer require 2lenet/import-bundle

包简介

Import data from files (.csv, .xml, ...)

README 文档

README

Import Bundle can be used to populate entities from flat files (.csv, .xml, etc.)

  1. Installation

Add package your composer.json file:

"require": {
    ...
    "2lenet/import-bundle": "^1.0"
    ...
}

Launch composer update to add bundle to your project:

composer update 2lenet/import-bundle

Add bundle in your app/AppKernel.php file:

$bundles = array(
            ...
            new ClickAndMortar\ImportBundle\ClickAndMortarImportBundle(),
        );
  1. Configuration

Configure bundle with your own entities in your app/config.yml file. Example:

click_and_mortar_import:
  entities:
    customer_from_pim:
      model: Acme\DemoBundle\Entity\Customer
      repository: AcmeDemoBundle:Customer
      unique_key: id
      mappings:
        id: "ID"
        name: "Name_For_Customer"
        firstname: "FirstName"
        gender: "Sex"
        age: "Age"
        ...

You can define multiple imports for a single entity by simply changing the name of the import procedure (eg. add a new part under entities with name customer_from_ecommerce)

Options available:

Option Mandatory Example Comment
model Yes Acme\DemoBundle\Entity\Customer Model name in your project
repository Yes AcmeDemoBundle:Customer Repository name for entity
unique_key No id Allows entities update from a property
only_update No false If true, only update existing entities by using unique_key
import_helper_service No acme.demo.import_helper.my_import_helper Extension point to complete classic mapping data on entity. Service must implements "ImportHelperInterface" interface
  1. Usage

Launch import of file with command:

php app/console candm:import /path/of/your/file/customers.csv customer_from_pim

Options available:

Option Comment
--delete-after-import Delete file after import
  1. Extension

You can create your own reader to read other file types.

Create your class (in YourOrganizationName/YourBundle/Reader/Readers) and extends AbstractReader:

<?php

namespace YourOrganizationName\YourBundle\Reader\Readers;

use ClickAndMortar\ImportBundle\Reader\AbstractReader;

/**
 * Class MyCustomXmlReader
 *
 * @package YourOrganizationName\YourBundle\Reader\Readers
 */
class MyCustomXmlReader extends AbstractReader
{
    /**
     * Read my custom XML file and return data array
     *
     * @param string $path
     *
     * @return array
     */
    public function read($path)
    {
        $data = array();

        ...

        return $data;
    }

    /**
     * Support only xml type
     *
     * @param string $type
     *
     * @return bool
     */
    public function support($type)
    {
        return $type == 'xml';
    }
}

Declare class as service (in YourOrganizationName/YourBundle/Resource/config/services.yml) and add tag clickandmortar.import.reader:

parameters:
  yourorganizationname.yourbundle.reader.my_custom_reader.class: YourOrganizationName\YourBundle\Reader\Readers\MyCustomXmlReader

services:
  yourorganizationname.yourbundle.reader.my_custom_reader:
    class: %yourorganizationname.yourbundle.reader.my_custom_reader.class%
    tags:
      - { name: clickandmortar.import.reader }

And that's all!

统计信息

  • 总下载量: 6.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 7
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-18