SyliusImportExportPlugin
SyliusImportExportPlugin copied to clipboard
Custom importer not register the right way
Hi,
I have a custom entity.
I add a basic importer configuration, but only json display in select importer format. The thing is the service is register under the identifer app.foo and not only foo, but the buildChoices importer is looking for foo only not app.foo.
If i change my type with foo only, the importer won't display.
Here is my configuration:
sylius.exporter.seo_urls.csv:
class: FriendsOfSylius\SyliusImportExportPlugin\Exporter\ResourceExporter
arguments:
- "@sylius.exporter.csv_writer"
- "@sylius.exporter.pluginpool.seo_urls"
- ["Id", "Url" ,"Title"]
- "@sylius.exporters_transformer_pool" # Optional
tags:
- { name: sylius.exporter, type: app.seo_url, format: csv }
sylius.processor.seo_url:
class: FriendsOfSylius\SyliusImportExportPlugin\Processor\ResourceProcessor
arguments:
- "@app.factory.seo_url"
- "@app.repository.seo_url"
- "@property_accessor"
- "@sylius.importer.metadata_validator"
- "@doctrine.orm.entity_manager"
- ["Id", "Url", "Title"]
More informations : In ImportType.php, the options array has that wrong field : 'importer_type' without the app.
In the import.html.twig, block.settings.resources.metadata.name got only 'foo' , and not 'app.foo'
Example : Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView {#16192 ▼ -metadata: Sylius\Component\Resource\Metadata\Metadata {#15196 ▼ -name: "seo_url" -applicationName: "app" -driver: "doctrine/orm" -templatesNamespace: null -parameters: array:2 [▼ "classes" => array:5 [▼ "model" => "App\Entity\Seo\SeoUrl" "repository" => "App\Repository\Seo\SeoUrlRepository" "controller" => "Sylius\Bundle\ResourceBundle\Controller\ResourceController" "factory" => "Sylius\Component\Resource\Factory\Factory" "form" => "Sylius\Bundle\ResourceBundle\Form\Type\DefaultResourceType" ] "driver" => "doctrine/orm" ] }
Yep got the same problem with the latest version of Sylius. Using CSV format it only shows JSON on the fontend
services.yaml (store ressource registered as sylius_store_locator.store)
sylius.importer.store.csv:
class: FriendsOfSylius\SyliusImportExportPlugin\Importer\ResourceImporter
arguments:
- "@sylius.factory.csv_reader"
- "@sylius_store_locator.manager.store"
- "@sylius.processor.store"
- "@sylius.importer.result"
- "%sylius.importer.batch_size%"
- "%sylius.importer.fail_on_incomplete%"
- "%sylius.importer.stop_on_failure%"
tags:
- { name: sylius.importer, type: sylius_store_locator.store, format: csv }
sylius.processor.store:
class: FriendsOfSylius\SyliusImportExportPlugin\Processor\ResourceProcessor
arguments:
- "@sylius_store_locator.factory.store"
- "@sylius_store_locator.repository.store"
- "@property_accessor"
- "@sylius.importer.metadata_validator"
- "@doctrine.orm.entity_manager"
- ["Id", "Name", "Longitude", "Latitude", "Address", "Zip_code", "Country", "Phone"]
bin/console sylius:importer
Available importers:
* sylius_store_locator.store (formats: csv)
* country (formats: csv, json)
* customer_group (formats: csv, json)
* payment_method (formats: csv, json)
* tax_category (formats: csv, json)
* product (formats: csv)
* taxonomy (formats: csv, json)
* customer (formats: json)
But in the frontend admin grid of my store resource, the only option of the importer is JSON.
The quick fix I found is
ImportType.php
private function buildChoices(array $options): array
{
/** @var string $importerType */
$importerType = $options['importer_type'];
if($importerType == "store"){
$importerType = "sylius_store_locator.".$importerType;
}
[...]
}
But that is not good... I'll see if I can investigate it further.
This seems to be the same as #249. I created a pull request to fix these: #272.