SyliusImportExportPlugin
SyliusImportExportPlugin copied to clipboard
Export based on grid filters
@pamil Could you advice best way to add a generic export controller that can act similar to ResourceController without extending it (else it's tedious for users of this plugin to get each exporter working)? Would like to use the same filters/data fetching as being used on the 'indexAction' in the ResourceController..
Doing something like this doesn't really get it working (WIP) with such URL: http://webshop.test.local/app_dev.php/admin/export/country/csv?criteria%5Bcode%5D%5Btype%5D=contains&criteria%5Bcode%5D%5Bvalue%5D=nl&criteria%5Benabled%5D=
// Get metadata config
// @todo Allow for non-sylius resources
$metadata = Metadata::fromAliasAndConfiguration('sylius.' . $exporter, $this->container->getParameter('sylius.resources')['sylius.'.$exporter]);
$configuration = $this->requestConfigurationFactory->create($metadata, $request);
dump($metadata);
dump($configuration);
$resources = $this->resourcesCollectionProvider->get($configuration, $repository);
dump($resources);
I have 2 countries (BE & NL), and in this case only expected NL in the results, but both are. I'm probably overlooking something that makes it pass the criteria GET param to the resolver..
Ok, adding
_sylius:
paginate: false
filterable: true
to the routing helps, but now it's 0 results :-)
Nm, issue with the fact that 'enabled' didn't have a value while filtering. Seems unrelated.
Not sure why on the normal grid an empty value for 'enabled' works (it shows one result), but if in the URL in my example it's not returning a result. Might be a bug in resource resolving?
To make it more clear for @pamil:
I'm using this URL on the grid: http://webshop.test.local/app_dev.php/admin/export/country/csv?criteria[code][type]=contains&criteria[code][value]=nl&criteria[enabled]=.
It returns NL only on the grid. In the database I have NL & BE, that's all. This is expected behavior.
When using the same URL filtering as in PR (#81), the NL is not in the result (result is empty). Adjusting the URL to http://webshop.test.local/app_dev.php/admin/export/country/csv?criteria[code][type]=contains&criteria[code][value]=nl solves it and NL is in the export. It seems due to no value for enabled, but that works on the Grid. Not sure therefore why this is an issue.
Some progress being made in #81. Not sure it's the best solution though.