{"id":13579248,"url":"https://github.com/FriendsOfSylius/SyliusImportExportPlugin","last_synced_at":"2025-04-05T20:33:34.195Z","repository":{"id":38410161,"uuid":"109575498","full_name":"FriendsOfSylius/SyliusImportExportPlugin","owner":"FriendsOfSylius","description":"Sylius plugin to import / export data","archived":false,"fork":false,"pushed_at":"2025-02-17T09:13:32.000Z","size":2329,"stargazers_count":118,"open_issues_count":58,"forks_count":84,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-28T22:09:35.044Z","etag":null,"topics":["csv","excel","sylius-plugin","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FriendsOfSylius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-05T11:59:38.000Z","updated_at":"2025-02-21T15:33:01.000Z","dependencies_parsed_at":"2024-04-08T16:58:48.712Z","dependency_job_id":"2d306219-ae05-4be6-ab00-b6034d328680","html_url":"https://github.com/FriendsOfSylius/SyliusImportExportPlugin","commit_stats":{"total_commits":329,"total_committers":34,"mean_commits":9.676470588235293,"dds":0.8480243161094225,"last_synced_commit":"c85ffe4b8c668776f0cc010424e24ab3f9eceed1"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FriendsOfSylius%2FSyliusImportExportPlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FriendsOfSylius%2FSyliusImportExportPlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FriendsOfSylius%2FSyliusImportExportPlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FriendsOfSylius%2FSyliusImportExportPlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FriendsOfSylius","download_url":"https://codeload.github.com/FriendsOfSylius/SyliusImportExportPlugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399874,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","excel","sylius-plugin","symfony"],"created_at":"2024-08-01T15:01:37.702Z","updated_at":"2025-04-05T20:33:29.180Z","avatar_url":"https://github.com/FriendsOfSylius.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"[![License](https://img.shields.io/packagist/l/friendsofsylius/sylius-import-export-plugin.svg)](https://github.com/FriendsOfSylius/SyliusImportExportPlugin/blob/master/LICENSE)\n[![Version](https://img.shields.io/packagist/v/friendsofsylius/sylius-import-export-plugin.svg)](https://packagist.org/packages/friendsofsylius/sylius-import-export-plugin)\n[![Build](https://github.com/FriendsOfSylius/SyliusImportExportPlugin/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/FriendsOfSylius/SyliusImportExportPlugin/actions/workflows/build.yml)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://sylius.org\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://demo.sylius.com/assets/shop/img/logo.png\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003ch1 align=\"center\"\u003eFOSSyliusImportExportPlugin\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://sylius.com/plugins/\" target=\"_blank\"\u003e\u003cimg src=\"https://sylius.com/assets/badge-approved-by-sylius.png\" width=\"200\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\n1. Require relevant portphp format support\n\n  - Run `composer require portphp/csv --no-update` to add CSV format support\n  - Run `composer require portphp/spreadsheet --no-update` to add Excel format support (also install the `zip` PHP extension)\n\n2. Require and install the plugin\n\n  - Run `composer require friendsofsylius/sylius-import-export-plugin`\n\n3. Register the bundle:\n\n```php\n\u003c?php\n\n// config/bundles.php\n\nreturn [\n    // ...\n    FriendsOfSylius\\SyliusImportExportPlugin\\FOSSyliusImportExportPlugin::class =\u003e ['all' =\u003e true],\n];\n```\n\n## Configuration\n\n### Application configuration:\n\n```yaml\n# config/packages/fos_sylius_import_export.yaml\n\nfos_sylius_import_export:\n    importer:\n        # set to false to not add an upload form to the entity overview pages\n        web_ui:               true\n        # set to an integer value bigger than 0 to flush the object manager in regular intervals\n        batch_size:           0\n        # if incomplete rows (ie. missing required fields) should be considered failures\n        fail_on_incomplete:   false\n        # if to stop the import process in case of a failure\n        stop_on_failure:      false\n    exporter:\n      # set to false to not add export buttons\n        web_ui:               true      \n```\n\n### Routing configuration (only necessary if `web_ui` is set to `true`):\n\n```yaml\n# config/routes/fos_sylius_import_export.yaml\n\nsylius_import_export:\n    resource: \"@FOSSyliusImportExportPlugin/Resources/config/routing.yml\"\n    prefix: /admin\n```\n\n### Message queue configuration\n\nAny library implementing the **\"queue-interop/queue-interop\"** can be used as the message queue. Following is the \"enqueue/redis\" library shown as an example usage.\n\n```yaml\n# config/services.yaml\n\n# define a service which will be used as the queue\nservices:\n    redis_connection_factory:\n        class: Enqueue\\Redis\\RedisConnectionFactory\n```\n\n```yaml\n# config/packages/fos_sylius_import_export.yaml\n\n# use the defined service\nfos_sylius_import_export:\n    message_queue:\n        service_id: 'redis_connection_factory'\n```\n\n## Usage\n\n### Available importer types\n\n* country (csv, excel, json)\n* customer_group (csv, excel, json)\n* payment_method (csv, excel, json)\n* tax_category (csv, excel, json)\n* customer (json)\n* product (csv)\n\n### Available exporter types\n\n* country (csv, excel, json)\n* order (csv, excel, json)\n* customer (csv, excel, json)\n* product (csv)\n\n## Example import files\n\nSee the fixtures in the Behat tests: `tests/Behat/Resources/fixtures`\n\n### UI\n\nFor all available importers, a form to upload files is automatically injected into the relevant\nadmin overview panel using the event hook system, ie. `admin/tax-categories/`.\n\n### CLI commands\n\n  - Get list of available importers\n\n        $ bin/console sylius:import\n\n  - Import a file using the `tax_category` importer\n\n        $ bin/console sylius:import tax_category my/tax/categories/csv/file.csv --format=csv\n  \n  - Import from message queue using the `country` importer\n  \n        $ bin/console sylius:import-from-message-queue country\n   \n  - To make the importer wait 1s for messages to get into the message queue (default, does not wait)\n  \n        $ bin/console sylius:import-from-message-queue country --timeout=1000\n   \n  - Export data of resources to file using `country` exporter\n\n        $ bin/console sylius:export country my/countries/export/csv/file.csv --format=csv\n    \n  - Export data of resources to message queue using `country` exporter\n  \n        $ bin/console sylius:export-to-message-queue country\n\n## Development\n\n### Adding new importer types\n\n#### Notes\n  \n  - Replace `app` and `foo` with the name of the resource (under `sylius_resource` config) you want to implement in the following examples.\n  - Replace `bar` with the name of the format you want to implement in the following examples (csv, json, ...).\n  - Note it is of course also possible to implement a dedicated importer for `app.foo` resource and format `bar`,\n    in case a generic type implementation is not possible.\n\n#### Adding a ResourceImporter\n\n##### Define Importer-Service for Generic Importer in services_bar.yml with ResourceImporter\n \n```yaml\n# config/services.yaml\n\nsylius.importer.foo.bar:\n    class: FriendsOfSylius\\SyliusImportExportPlugin\\Importer\\ResourceImporter\n    arguments:\n        - \"@sylius.factory.bar_reader\"\n        - \"@sylius.manager.foo\"\n        - \"@sylius.processor.foo\"\n        - \"@sylius.importer.result\"\n    tags:\n        - { name: sylius.importer, type: foo, domain: app, format: csv }\n```\n  \n##### Alternatively implement a custom ResourceImporter _FooImporter_\n\n```php\nclass FooImporter implements ImporterInterface\n```\n\n##### Define service instead of the above mentioned\n\n```yaml\n# config/services.yaml\n\nsylius.importer.foo.bar:\n  class: App\\FooImporter\n  arguments:\n      - \"@sylius.factory.bar_reader\"\n      - \"@sylius.manager.foo\"\n      - \"@sylius.processor.foo\"\n      - \"@sylius.importer.result\"\n  tags:\n      - { name: sylius.importer, type: foo, domain: app, format: bar }\n```\n\n#### Adding a ResourceProcessor\n\n##### Define processor service with generic ResourceProcessor in services.yml\n\n```yaml\n# config/services.yaml\n\nsylius.processor.foo:\n    class: FriendsOfSylius\\SyliusImportExportPlugin\\Processor\\ResourceProcessor\n    arguments:\n        - \"@app.factory.foo\"\n        - \"@app.repository.foo\"\n        - \"@property_accessor\"\n        - \"@sylius.importer.metadata_validator\"\n        - \"@doctrine.orm.entity_manager\"\n        - [\"HeaderKey0\", \"HeaderKey1\", \"HeaderKey2\"]\n```\n\nHeaderKey0 is the key that will be searched for in the Database, to avoid redundancy. So best would be to make HeaderKey0 a unique Key.\n\nThe fourth parameter represents the Headers of the data to import. For csv-files this would be the headers defined in \nits first line. These HeaderKeys have to be equal to the fields in the resource to import if the generic\nResourceProcessor is used, since the Keys are used for building dynamic Methodnames\n    \n\n##### Alternatively implement a custom ResourceProcessor _FooProcessor_\n \n```php\nclass FooProcessor implements ResourceProcessorInterface\n```\n##### Define processor service with _FooProcessor_ in services.yml instead of the above mentioned generic one\n \n```yaml\n# config/services.yaml\n\n sylius.processor.tax_categories:\n     class: FriendsOfSylius\\SyliusImportExportPlugin\\Processor\\FooProcessor\n     arguments:\n         - \"@app.factory.foo\"\n         - \"@app.repository.foo\"\n         - \"@sylius.importer.metadata_validator\"\n         - \"@doctrine.orm.entity_manager\"\n         - [\"HeaderKey0\", \"HeaderKey1\", \"HeaderKey2\"]\n```\n\n#### Validating Metadata\n\nEach Processor has defined mandatory 'HeaderKeys'. For basic validation of these HeaderKeys you can use \n\"@sylius.importer.metadata_validator\". Of course it is also possible to implement you own Validator, by implementing the \nMetadataValidatorInterface and injecting it in your FooProcessor instead of the generic one.\n\n### Defining new Exporters\n\n#### Notes\n  \n  - Replace `foo` with the name of the type you want to implement in the following examples.\n  - Replace `bar` with the name of the format you want to implement in the following examples.\n  - Note it is of course also possible to implement a dedicated exporter for `foo` type and format `bar`,\n    in case a generic type implementation is not possible.\n\n### Exporters\n\n#### Adding a ResourceExporter\n\nDefine your ResourceExporter in services_bar.yml (at the moment only csv is supported for export)\n\n```yaml\n# config/services.yaml\n\n  sylius.exporter.foo.bar:\n     class: FriendsOfSylius\\SyliusImportExportPlugin\\Exporter\\ResourceExporter\n     arguments:\n        - \"@sylius.exporter.bar_writer\"\n        - \"@sylius.exporter.pluginpool.foo\"\n        - [\"HeaderKey0\", \"HeaderKey1\" ,\"HeaderKey2\"]\n        - \"@sylius.exporters_transformer_pool\" # Optional\n     tags:\n        - { name: sylius.exporter, type: app.foo, format: bar }\n```\n\nNote that `app.foo` is the alias as you have named your resource:\n\n```yaml\n# config/packages/_sylius.yaml\n\nsylius_resource:\n    resources:\n        app.foo:\n```\n\nDefine the PluginPool for your ResourceExporter in services.yml\n\n```yaml\n# config/services.yaml\n\n# PluginPools for Exporters. Can contain multiple Plugins\n  sylius.exporter.pluginpool.foo:\n      class: FriendsOfSylius\\SyliusImportExportPlugin\\Exporter\\Plugin\\PluginPool\n      arguments:\n          - [\"@sylius.exporter.plugin.resource.foo\"]\n          - [\"HeaderKey0\", \"HeaderKey1\" ,\"HeaderKey2\"]\n```\n\nDefine the Plugin for your FooResource in services.yml\n\n```yaml\n# config/services.yaml\n\n  # Plugins for Exporters\n  sylius.exporter.plugin.resource.foo:\n      class: FriendsOfSylius\\SyliusImportExportPlugin\\Exporter\\Plugin\\ResourcePlugin\n      arguments:\n          - \"@sylius.repository.foo\"\n          - \"@property_accessor\"\n          - \"@doctrine.orm.entity_manager\"\n```\n\nIn case you want to use the grid filters (in the admin) to filter your output, add to your routing:\n\n```yaml\n# config/services.yaml\n\napp_export_data_foo:\n    path: /admin/export/sylius.resource/{format}\n    methods: [GET]\n    defaults:\n        resource: sylius.foo\n        _controller: sylius.controller.export_data_foo:exportAction\n        _sylius:\n            filterable: true\n            grid: sylius_admin_foo # Name of defined grid here\n```\nAnd add the associated controller service definition to your services\n\n```yaml\n# config/services.yaml\n\nsylius.controller.export_data_foo:\n    public: true\n    class: FriendsOfSylius\\SyliusImportExportPlugin\\Controller\\ExportDataController\n    arguments:\n        - \"@sylius.exporters_registry\"\n        - \"@sylius.resource_controller.request_configuration_factory\"\n        - \"@sylius.resource_controller.resources_collection_provider\"\n        - \"@sylius.repository.foo\"\n        - \"%sylius.resources%\"\n    tags: ['controller.service_arguments']\n```\n\n\nIn case you don't add it, the UI exporters will still function. They will simply load all data of that resource for the export (similar as CLI).\n\n### A real example\n\nDefine the Countries-Exporter in services_csv.yml\n```yaml\n# config/services.yaml\n\n  sylius.exporter.countries.csv:\n     class: FriendsOfSylius\\SyliusImportExportPlugin\\Exporter\\ResourceExporter\n     arguments:\n        - \"@sylius.exporter.csv_writer\"\n        - \"@sylius.exporter.pluginpool.countries\"\n        - [\"Id\", \"Code\" ,\"Enabled\"]\n        - \"@sylius.exporters_transformer_pool\" # Optional\n     tags:\n        - { name: sylius.exporter, type: sylius.country, format: csv }\n```\n\nDefine the PluginPool for the Countries-Exporter in services.yml\n\n```yaml\n# config/services.yaml\n\n# PluginPools for Exporters. Can contain multiple Plugins\n  sylius.exporter.pluginpool.countries:\n      class: FriendsOfSylius\\SyliusImportExportPlugin\\Exporter\\Plugin\\PluginPool\n      arguments:\n          - [\"@sylius.exporter.plugin.resource.country\"]\n          - [\"Id\", \"Code\" ,\"Enabled\"]\n```\n\nDefine the Plugin for the Country-Resource in services.yml\n\n```yaml\n# config/services.yaml\n\n  # Plugins for Exporters\n  sylius.exporter.plugin.resource.country:\n      class: FriendsOfSylius\\SyliusImportExportPlugin\\Exporter\\Plugin\\ResourcePlugin\n      arguments:\n          - \"@sylius.repository.country\"\n          - \"@property_accessor\"\n          - \"@doctrine.orm.entity_manager\"\n\n```\n\nThe exporter will instantly be available as a exporter for the command line.\n\n    $ bin/console sylius:export country my/countries/export/csv/file.csv --format=csv\n   \nOptional add the routing:\n\n```yaml\n# config/routes.yaml\n\napp_export_data_country:\n    path: /admin/export/sylius.country/{format}\n    methods: [GET]\n    defaults:\n        resource: sylius.country\n        _controller: sylius.controller.export_data_contry:exportAction\n        _sylius:\n            filterable: true\n            grid: sylius_admin_country\n```   \n\nAnd add the associated controller service definition to your services\n\n```yaml\n# config/services.yaml\n\nsylius.controller.export_data_country:\n    public: true\n    class: FriendsOfSylius\\SyliusImportExportPlugin\\Controller\\ExportDataController\n    arguments:\n        - \"@sylius.exporters_registry\"\n        - \"@sylius.resource_controller.request_configuration_factory\"\n        - \"@sylius.resource_controller.resources_collection_provider\"\n        - \"@sylius.repository.country\"\n        - \"%sylius.resources%\"\n    tags: ['controller.service_arguments']\n```\n\n### PluginPool\n\nThe idea behind the plugin pool is, to be able to have different kind of plugins, which could possibly\nprovide data based on a custom sql that queries additional data for the exported resource, such as the \npreferred brand of a customer. \nAt the moment there are only 'ResourcePlugin's, which allow the complete export of all data of one resource at the moment.\nWith the provided keys you can influence which fields of a resource are exported.\n\n### Running plugin tests\n\n  - Test application install\n\n        $ composer require sylius/sylius symfony/symfony\n        $ (cd tests/Application \u0026\u0026 yarn install)\n        $ (cd tests/Application \u0026\u0026 yarn run gulp)\n        $ (cd tests/Application \u0026\u0026 bin/console assets:install web -e test)\n    \n        $ (cd tests/Application \u0026\u0026 bin/console doctrine:database:create -e test)\n        $ (cd tests/Application \u0026\u0026 bin/console doctrine:schema:create -e test)\n\n  - PHPUnit\n\n        $ bin/phpunit\n\n  - PHPSpec\n\n        $ bin/phpspec run\n\n  - Behat (non-JS scenarios)\n\n        $ bin/behat features --tags=\"~@javascript\"\n\n  - Behat (JS scenarios)\n \n    1. Download [Chromedriver](https://sites.google.com/a/chromium.org/chromedriver/)\n    \n    2. Run Selenium server with previously downloaded Chromedriver:\n    \n           $ bin/selenium-server-standalone -Dwebdriver.chrome.driver=chromedriver\n\n    3. Run test application's webserver on `localhost:8080`:\n    \n           $ (cd tests/Application \u0026\u0026 bin/console server:run 127.0.0.1:8080 -d web -e test)\n    \n    4. Run Behat:\n    \n           $ bin/behat features --tags=\"@javascript\"\n\n### Opening Sylius with your plugin\n\n- Using `test` environment:\n\n      $ (cd tests/Application \u0026\u0026 bin/console sylius:fixtures:load -e test)\n      $ (cd tests/Application \u0026\u0026 bin/console server:run -d web -e test)\n    \n- Using `dev` environment:\n\n      $ (cd tests/Application \u0026\u0026 bin/console sylius:fixtures:load -e dev)\n      $ (cd tests/Application \u0026\u0026 bin/console server:run -d web -e dev)\n\nFixture file with login information:\nhttps://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/CoreBundle/Resources/config/app/fixtures.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFriendsOfSylius%2FSyliusImportExportPlugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFriendsOfSylius%2FSyliusImportExportPlugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFriendsOfSylius%2FSyliusImportExportPlugin/lists"}