mobizel/sylius-export-plugin
Composer 安装命令:
composer require mobizel/sylius-export-plugin
包简介
Bulk export of sylius resources
关键字:
README 文档
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_customerif 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.
mobizel/sylius-export-plugin 适用场景与选型建议
mobizel/sylius-export-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22.62k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「export」 「sylius」 「sylius-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mobizel/sylius-export-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mobizel/sylius-export-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mobizel/sylius-export-plugin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Implementation of the Omnibus Directive for Sylius application.
Sylius plugin that integrates Addwish
Setono example plugin for Sylius.
Will translate fragments of text automatically
Use price tiers in your Sylius store.
BitBag VueStorefront bridge for Sylius.
统计信息
- 总下载量: 22.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-26