This topic contains 2 replies, has 3 voices, and was last updated by eaglesha619 4 years, 10 months ago.
- Topic
I have created a custom Entity named Brick and database table name is razoyo_brick. When exporting, it sends me confirmation email with correct amount of entities being imported.
But when I open the csv file it has the headers and correct amount of lines but with empty field values123Id,Name,Description,,,,Here is my importexport.yml
12345678910111213141516171819202122232425262728293031323334353637383940414243services:# Normalizerrazoyo_brick.importexport.normalizer.razoyo_brick:class: 'Razoyo\Bundle\BrickBundle\ImportExport\Normalizer\BrickNormalizer'public: falseparent: oro_importexport.serializer.configurable_entity_normalizertags:- { name: oro_importexport.normalizer }# Converterrazoyo_brick.importexport.data_converter.razoyo_brick:public: falseparent: oro_importexport.data_converter.configurableclass: 'Razoyo\Bundle\BrickBundle\ImportExport\DataConverter\BrickDataConverter'razoyo_brick.importexport.processor.export.razoyo_brick:public: falseparent: oro_importexport.processor.export_abstractcalls:- [setDataConverter, ['@razoyo_brick.importexport.data_converter.razoyo_brick']]tags:- { name: oro_importexport.processor, type: export, entity: 'Razoyo\Bundle\BrickBundle\Entity\Brick', alias: raz k', alias: razoyo_brick }razoyo_brick.importexport.processor.import.razoyo_brick:parent: oro_importexport.processor.import_abstractcalls:- [setDataConverter, ['@razoyo_brick.importexport.data_converter.razoyo_brick']]tags:- name: oro_importexport.processortype: importentity: 'Razoyo\Bundle\BrickBundle\Entity\Brick'alias: razoyo_brickrazoyo_brick.importexport.template_fixture.brick:class: 'Razoyo\Bundle\BrickBundle\ImportExport\TemplateFixture\BrickFixture'tags:- { name: oro_importexport.template_fixture }razoyo_brick.importexport.configuration_provider:class: 'Razoyo\Bundle\BrickBundle\ImportExport\Configuration\BrickImportExportConfigurationProvider'arguments:- '@translator'tags:- { name: oro_importexport.configuration, alias: razoyo_brick }My BrickNormalizer.php
12345678910111213141516171819202122232425262728293031323334353637<?phpnamespace Razoyo\Bundle\BrickBundle\ImportExport\Normalizer;use Oro\Bundle\ImportExportBundle\Serializer\Normalizer\ConfigurableEntityNormalizer;use Razoyo\Bundle\BrickBundle\Entity\Brick;class BrickNormalizer extends ConfigurableEntityNormalizer{/*** @param Brick $object** {@inheritDoc}*/public function normalize($object, $format = null, array $context = array()){$data = parent::normalize($object, $format, $context);if (array_key_exists('description', $data)) {unset($data['description']);}return $data;}/*** {@inheritDoc}*/public function supportsNormalization($data, $format = null, array $context = array()){return $data instanceof Brick;}/*** {@inheritDoc}*/public function supportsDenormalization($data, $type, $format = null, array $context = []){return false;}}My BrickDataConverter.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152<?phpnamespace Razoyo\Bundle\BrickBundle\ImportExport\DataConverter;use Oro\Bundle\ImportExportBundle\Context\ContextAwareInterface;use Oro\Bundle\ImportExportBundle\Context\ContextInterface;use Oro\Bundle\ImportExportBundle\Converter\ConfigurableTableDataConverter;class BrickDataConverter extends ConfigurableTableDataConverter implements ContextAwareInterface{/*** @var ContextInterface|null*/protected $context;/*** {@inheritdoc}*/public function setImportExportContext(ContextInterface $context){$this->context = $context;}/*** {@inheritdoc}*/public function convertToImportFormat(array $importedRecord, $skipNullValues = true){if ($this->context && empty($importedRecord['brick_id'])) {$importedRecord['brick:id'] = (int)$this->context->getOption('brick_id');}return parent::convertToImportFormat($importedRecord, $skipNullValues);}/*** {@inheritDoc}*/protected function getHeaderConversionRules(){return ['Id' => 'id','Name' => 'name','Description' => 'description',];}/*** {@inheritDoc}*/protected function getBackendHeader(){return ['id','name','description',];}my Table Structure:
123456789Table "public.razoyo_brick"Column | Type | Collation | Nullable | Default | Storage | Stats target | Description-------------+------------------------+-----------+----------+------------------------------------------+----------+--------------+-------------id | integer | | not null | nextval('razoyo_brick_id_seq'::regclass) | plain | |name | character varying(255) | | not null | | extended | |description | text | | | | extended | |Indexes:"razoyo_brick_pkey" PRIMARY KEY, btree (id)"uniq_8204fb6c5e237e06" UNIQUE, btree (name)123456app=> select * from razoyo_brick;id | name | description----+-------------+----------------------------------1 | Clay Brick | Made of Clay. Red Color2 | Stone Brick | Made of Stone. Grey Color. Hard.(2 rows)Also
1php bin/console oro:message-queue:consume --env=dev -vvvThis command showed my table data in the job logs before I added the normalizer but it was breaking because of data could not be normalized. Now that I added the normalizer the export shows success but with empty csv.
Will appreciate if another eye can advise. Thanks.
The forum ‘OroPlatform’ is closed to new topics and replies.