mobizel / sylius-export-plugin
Bulk export of sylius resources
Installs: 16 081
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 1
Open Issues: 22
Type:sylius-plugin
Requires
- php: ^8.0
- portphp/csv: ^1.1
- sylius/grid-bundle: ^1.10
- sylius/resource-bundle: ^1.8
- symfony/asset: ^5.3
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.4
- dbrekelmans/bdi: ^1.0
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- matthiasnoback/symfony-dependency-injection-test: ^4.2.1
- phpspec/phpspec: ^7.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: 0.12.85
- phpstan/phpstan-doctrine: 0.12.33
- phpstan/phpstan-strict-rules: ^0.12.0
- phpstan/phpstan-webmozart-assert: 0.12.12
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- se/selenium-server-standalone: 2.*
- sensiolabs/security-checker: ^6.0
- sylius-labs/coding-standard: ^4.0
- sylius/sylius: ^1.11
- symfony/browser-kit: ^5.3
- symfony/debug-bundle: ^5.3
- symfony/dotenv: ^5.3
- symfony/intl: ^5.3
- symfony/web-profiler-bundle: ^5.3
- vimeo/psalm: 4.7.1
- dev-main
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4
- v0.3
- v0.2
- v0.1.3
- v0.1
- dev-feature/sf6
- dev-dependabot/npm_and_yarn/tests/Application/express-4.18.2
- dev-dependabot/npm_and_yarn/tests/Application/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/tests/Application/qs-6.5.3
- dev-dependabot/npm_and_yarn/tests/Application/minimatch-3.0.8
- dev-dependabot/npm_and_yarn/tests/Application/terser-4.8.1
- dev-dependabot/npm_and_yarn/tests/Application/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/tests/Application/async-2.6.4
- dev-dependabot/npm_and_yarn/tests/Application/moment-2.29.2
- dev-dependabot/npm_and_yarn/tests/Application/minimist-1.2.6
- dev-dependabot/npm_and_yarn/tests/Application/follow-redirects-1.14.9
- dev-dependabot/npm_and_yarn/tests/Application/url-parse-1.5.10
- dev-dependabot/composer/phpspec/phpspec-tw-7.1
- dev-dependabot/composer/symfony/dotenv-tw-5.3
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/symfony/debug-bundle-tw-5.1.11
- dev-dependabot/composer/lakion/mink-debug-extension-tw-2.0.0
- dev-dependabot/composer/sensiolabs/security-checker-tw-6.0
- dev-dependabot/composer/phpstan/phpstan-shim-tw-0.12
- dev-dependabot/composer/symfony/web-profiler-bundle-tw-5.0.11
- dev-dependabot/composer/se/selenium-server-standalone-tw-3.141
This package is auto-updated.
Last update: 2024-12-11 16:42:06 UTC
README
Mobizel Export plugin
Getting started
This plugin add a new bulkAction 'export' to all Sylius resources.
It use the default resource grid definition to export data.
You can also use a specific grid for export.
It allow you to export:
- All entities
- All entities filtered by search
- Selected entities (with checkbox)
IMPORTANT: This plugin does not depend on sylius/sylius
but only sylius/resource-bundle
and sylius/grid-bundle
, so it can be used in other project like the symfony starter monofony.
Installation
- Require and install the plugin
- Run
composer require mobizel/sylius-export-plugin
- Register the bundle:
=> If you do not use symfony/flex
you have to import the plugin in the Kernel.
<?php // config/bundles.php return [ // ... Mobizel\SyliusExportPlugin\MobizelSyliusExportPlugin::class => ['all' => true], ];
Configuration
GRID configuration:
Create file config/packages/sylius_grid.yaml
if not exist and add new bulk action
sylius_grid: templates: bulk_action: export: "@MobizelSyliusExportPlugin/Admin/Grid/BulkAction/export.html.twig"
Add new button macro
Add this following file to add the new button macro.
# templates/bundles/SyliusUiBundle/Macro/buttons.html.twig {% extends "@!SyliusUi/Macro/buttons.html.twig" %} {% macro bulkExport(url, message, labeled = true) %} <form action="{{ url }}" method="post" id="bulk-export"> <a class="ui red {% if labeled %}labeled {% endif %}icon button not_disabled" type="submit" href="#"> <i class="icon download"></i> {{ ((message is empty and labeled) ? 'sylius.ui.export' : message)|trans }} </a> </form> {% endmacro %}
Javascript integration
Integrate vendor/mobizel/sylius-export-plugin/src/Resources/public/js/bulk-export.js
in your javascript build (webpack / gulp) or directly in twig (you need to copy file to your assets directory)
Twig integration example:
<script src="{{ asset('bundles/mobizelsyliusexportplugin/js/bulk-export.js') }}"></script>
How to use it
Example
You only have to add export bulk action to your grid, example with customer grid, create file config/grids/admin/customer.yaml
to override customer's grid:
sylius_grid: grids: sylius_admin_customer: actions: bulk: export: type: export
Next, enable your grid.
Edit config/packages/sylius_grid.yaml
and add on the top:
imports: - { resource: '../grids/admin/customer.yaml' }
How to enable export of selected entities
Export of selected entities does not work out of the box. You need to override the entity repository.
Example for customer:
- Create CustomerRepository class:
<?php declare(strict_types=1); namespace Tests\Mobizel\SyliusExportPlugin\Application\src\Repository; use Doctrine\ORM\QueryBuilder; use Sylius\Bundle\CoreBundle\Doctrine\ORM\CustomerRepository as BaseCustomerRepository; class CustomerRepository extends BaseCustomerRepository { public function createListQueryBuilderFilteredByIds(?array $ids): QueryBuilder { $queryBuilder = $this->createQueryBuilder('o'); if (null !== $ids && count($ids) > 0) { $queryBuilder ->andWhere($queryBuilder->expr()->in('o.id', ':ids')) ->setParameter('ids', $ids); } return $queryBuilder; } }
Note: We add new method to fetch entities filtered by id
-
Create file
config/packages/sylius_customer
if not exist -
Set custom repository in this file
sylius_customer: resources: customer: classes: repository: Repository\CustomerRepository
- Update customer grid to user new method:
sylius_grid: grids: sylius_admin_customer: driver: options: class: "%sylius.model.customer.class%" OR App\Entity\Customer\Customer repository: method: createListQueryBuilderFilteredByIds arguments: - $ids
complete file:
sylius_grid: grids: sylius_admin_customer: driver: options: class: "%sylius.model.customer.class%" OR App\Entity\Customer\Customer repository: method: createListQueryBuilderFilteredByIds arguments: - $ids actions: bulk: export: type: export
How to use custom grid
If you want to use a custom grid while export entites, you just have to override the route and specify the grid paramter, example for customer:
sylius_backend_customer_bulk_export: path: /customers/bulk-export methods: [POST] defaults: _controller: sylius.controller.customer:exportAction _sylius: grid: my_custom_grid ...
Custom export format
This plugin only use CSV for export, however you can implement your own export.
Create a new class that implements Mobizel\SyliusExportPlugin\Exporter\ResourceExporterInterface
.
If you create an XmlResourceExport
with method
public function getFormat(): string { return 'xml'; }
you can change the export format in the route definition:
sylius_backend_customer_bulk_export: path: /customers/bulk-export methods: [POST] defaults: _controller: sylius.controller.customer:exportAction _sylius: grid: my_custom_grid vars: export_format: xml ...
CSV settings
You can configure setting of the CSV writer.
# config/packages/mobizel_sylius_export.yaml mobizel_sylius_export: csv_settings: delimiter: ';'
Contributing
Would like to help us ? Feel free to open a pull-request!
License
Sylius export plugin is completely free and released under the MIT License.
Authors
Sylius export plugin was originally created by Kévin REGNIER.