sndsabin/import-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sndsabin/import-bundle

最新稳定版本:v0.1.1

Composer 安装命令:

composer require sndsabin/import-bundle

包简介

Import Bundle

README 文档

README

An opinionated pimcore bundle for importing files.

Supports

  • CSV
  • JSON

Installation

Prerequisite

Requires pimcore >=10.0.0

Step 1 (install the bundle)

composer require sndsabin/import-bundle

Step 2 (enable the bundle)

bin/console pimcore:bundle:enable ImportBundle

Example use case: Import

Let's say records of customer has to be imported to Customer DataObject Class from customer.csv.

Step 3 (add mapper)

<?php

namespace App\Mapper;

use Pimcore\Model\DataObject\Customer;
use SNDSABIN\ImportBundle\Helper\IdentifierType;
use SNDSABIN\ImportBundle\Contract\MapperInterface;

class CustomerMapper implements MapperInterface
{
    /** @var string */
    const FOLDER = 'customer'; // the folder inside which all customer data objects would be created

    /**
     * @param array $data
     * @return array
     */
    public function map(array $data): array
    {
        return [
            'folder' => self::FOLDER, // mandatory
            'class' => Customer::class, // mandatory
            'identifier' => [ // analogous to primary key: used for update operation (mandatory) 
                'attribute' => 'code',
                'value' => $data['Code'],
                'type' => IdentifierType::NON_CONDITIONAL
            ],
            'attributes' => [
                'code' => $data['Code'],
                'firstname' => $data['First Name'],
                'lastname' => $data['Last Name'],
                'email' => $data['Email'],
                'company' => $data['Company'],
                'address' => $data['Address'],
                'country' => $data['Country'],
                'phone' => $data['Phone'],
                'acceptsMarketing' => (bool) $data['Accepts Marketing'],
                'key' => "{$data['Code']}-{$data['First Name']}", // o_key (mandatory)
                'localisedField' => [
                    [
                        'attribute' => 'note',
                        'value' => $data['Note English'],
                        'language' => 'en'
                    ],
                    [
                        'attribute' => 'note',
                        'value' => $data['Note Nepali'],
                        'language' => 'ne'
                    ]
                ]
            ]
        ];

    }
}

@see CustomerMapper.md for more examples on how to use IdentifierType::CONDITIONAL and IdentifierType::CONDITIONAL_PARAM.

Step 4 (add configuration)

configure import.yaml for the class (Example: customer in this case) you wish to import

#config/packages/import.yaml
import:
    config:
        base_directory: '/var/www/html/import-data' # base directory where all the files to be imported are located (required)
        customer:
            file: 'customer.csv'  # file name (required)
            mapper: 'App\Mapper\CustomerMapper' # mapper (required)

@see CommandConfigResolver.php and CommandConfigValidator.php for more info on how these attributes are parsed and validated.

@see Sample Config File for all the configurable attributes.

Step 5 (import using command)

bin/console data:import [options]

Options:
  -c, --class=CLASS                     DataObject whose data is to be imported
  -f, --file[=FILE]                     path of the data file
      --book-keeping|--no-book-keeping  maintain the records (or do not maintain --no-book-keeping) of imported file

Example usage (for customer class)

bin/console data:import -c customer

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2022-12-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固