Download the PHP package lionelkouame/sylius-import-export-plugin without Composer
On this page you can find all versions of the php package lionelkouame/sylius-import-export-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lionelkouame/sylius-import-export-plugin
More information about lionelkouame/sylius-import-export-plugin
Files in lionelkouame/sylius-import-export-plugin
Package sylius-import-export-plugin
Short Description import / export plugin for Sylius.
License MIT
Informations about the package sylius-import-export-plugin
FOSSyliusImportExportPlugin
Installation
-
Require relevant portphp format support
- Run
composer require portphp/csv --no-update
to add CSV format support - Run
composer require portphp/spreadsheet --no-update
to add Excel format support (also install thezip
PHP extension)
- Run
-
Require and install the plugin
- Run
composer require friendsofsylius/sylius-import-export-plugin
- Run
- Register the bundle:
Configuration
Application configuration:
Routing configuration (only necessary if web_ui
is set to true
):
Message queue configuration
Any 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.
Usage
Available importer types
- country (csv, excel, json)
- customer_group (csv, excel, json)
- payment_method (csv, excel, json)
- tax_category (csv, excel, json)
- customer (json)
- product (csv)
Available exporter types
- country (csv, excel, json)
- order (csv, excel, json)
- customer (csv, excel, json)
- product (csv)
Example import files
See the fixtures in the Behat tests: tests/Behat/Resources/fixtures
UI
For all available importers, a form to upload files is automatically injected into the relevant
admin overview panel using the event hook system, ie. admin/tax-categories/
.
CLI commands
-
Get list of available importers
$ bin/console sylius:import
-
Import a file using the
tax_category
importer$ bin/console sylius:import tax_category my/tax/categories/csv/file.csv --format=csv
-
Import from message queue using the
country
importer$ bin/console sylius:import-from-message-queue country
-
To make the importer wait 1s for messages to get into the message queue (default, does not wait)
$ bin/console sylius:import-from-message-queue country --timeout=1000
-
Export data of resources to file using
country
exporter$ bin/console sylius:export country my/countries/export/csv/file.csv --format=csv
-
Export data of resources to message queue using
country
exporter$ bin/console sylius:export-to-message-queue country
Development
Adding new importer types
Notes
- Replace
app.foo
with the name of the resource (undersylius_resource
config) you want to implement in the following examples. - Replace
bar
with the name of the format you want to implement in the following examples (csv, json, ...). - Note it is of course also possible to implement a dedicated importer for
app.foo
resource and formatbar
, in case a generic type implementation is not possible.
Adding a ResourceImporter
Define Importer-Service for Generic Importer in services_bar.yml with ResourceImporter
Alternatively implement a custom ResourceImporter FooImporter
Define service instead of the above mentioned
Adding a ResourceProcessor
Define processor service with generic ResourceProcessor in services.yml
HeaderKey0 is the key that will be searched for in the Database, to avoid redundancy. So best would be to make HeaderKey0 a unique Key.
The fourth parameter represents the Headers of the data to import. For csv-files this would be the headers defined in its first line. These HeaderKeys have to be equal to the fields in the resource to import if the generic ResourceProcessor is used, since the Keys are used for building dynamic Methodnames
Alternatively implement a custom ResourceProcessor FooProcessor
Define processor service with FooProcessor in services.yml instead of the above mentioned generic one
Validating Metadata
Each Processor has defined mandatory 'HeaderKeys'. For basic validation of these HeaderKeys you can use "@sylius.importer.metadata_validator". Of course it is also possible to implement you own Validator, by implementing the MetadataValidatorInterface and injecting it in your FooProcessor instead of the generic one.
Defining new Exporters
Notes
- Replace
foo
with the name of the type you want to implement in the following examples. - Replace
bar
with the name of the format you want to implement in the following examples. - Note it is of course also possible to implement a dedicated exporter for
foo
type and formatbar
, in case a generic type implementation is not possible.
Exporters
Adding a ResourceExporter
Define your ResourceExporter in services_bar.yml (at the moment only csv is supported for export)
Note that app.foo
is the alias as you have named your resource:
Define the PluginPool for your ResourceExporter in services.yml
Define the Plugin for your FooResource in services.yml
In case you want to use the grid filters (in the admin) to filter your output, add to your routing:
And add the associated controller service definition to your services
In 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).
A real example
Define the Countries-Exporter in services_csv.yml
Define the PluginPool for the Countries-Exporter in services.yml
Define the Plugin for the Country-Resource in services.yml
The exporter will instantly be available as a exporter for the command line.
$ bin/console sylius:export country my/countries/export/csv/file.csv --format=csv
Optional add the routing:
And add the associated controller service definition to your services
PluginPool
The idea behind the plugin pool is, to be able to have different kind of plugins, which could possibly provide data based on a custom sql that queries additional data for the exported resource, such as the preferred brand of a customer. At the moment there are only 'ResourcePlugin's, which allow the complete export of all data of one resource at the moment. With the provided keys you can influence which fields of a resource are exported.
Running plugin tests
-
Test application install
$ composer require sylius/sylius symfony/symfony $ (cd tests/Application && yarn install) $ (cd tests/Application && yarn run gulp) $ (cd tests/Application && bin/console assets:install web -e test) $ (cd tests/Application && bin/console doctrine:database:create -e test) $ (cd tests/Application && bin/console doctrine:schema:create -e test)
-
PHPUnit
$ bin/phpunit
-
PHPSpec
$ bin/phpspec run
-
Behat (non-JS scenarios)
$ bin/behat features --tags="~@javascript"
-
Behat (JS scenarios)
-
Download Chromedriver
-
Run Selenium server with previously downloaded Chromedriver:
$ bin/selenium-server-standalone -Dwebdriver.chrome.driver=chromedriver
-
Run test application's webserver on
localhost:8080
:$ (cd tests/Application && bin/console server:run 127.0.0.1:8080 -d web -e test)
-
Run Behat:
$ bin/behat features --tags="@javascript"
-
Opening Sylius with your plugin
-
Using
test
environment:$ (cd tests/Application && bin/console sylius:fixtures:load -e test) $ (cd tests/Application && bin/console server:run -d web -e test)
-
Using
dev
environment:$ (cd tests/Application && bin/console sylius:fixtures:load -e dev) $ (cd tests/Application && bin/console server:run -d web -e dev)
Fixture file with login information: https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/CoreBundle/Resources/config/app/fixtures.yml
All versions of sylius-import-export-plugin with dependencies
sylius/sylius Version ~1.8.0 || ~1.9.0 || ~1.10.0 || ~v1.11.0
portphp/portphp Version ^1.2
symfony/stopwatch Version ^4.4 || ^5.2
queue-interop/queue-interop Version ^0.6.2 || ^0.7 || ^0.8