OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions ImportExportBundle how to make CollectionNormalizer working properly

This topic contains 3 replies, has 2 voices, and was last updated by  Dima Makaruk 8 years, 9 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #33894

    Dima Makaruk
    Participant

    My CSV look like this:

    column1,column2,column3:item:id
    text,text,1

    In this case the collection (column3) is normally denormalized containing one item in collection.
    How is it possible to import more than one item in collection ?

    Something like this :

    column1,column2,column3:item:id
    text,text,1|3|4

    Normalizer method looks like this:

    public function denormalize($data, $class, $format = null, array $context = array())
    {
    if (!is_array($data)) {
    return new ArrayCollection();
    }
    $itemType = $this->getItemType($class);
    if (!$itemType) {
    return new ArrayCollection($data);
    }
    $result = new ArrayCollection();
    foreach ($data as $item) {
    $result->add($this->serializer->denormalize($item, $itemType, $format, $context));
    }
    return $result;
    }

    Where :
    $data = [‘item’ => [‘id’ => ‘1|3|4’]]
    $item = [‘id’ => ‘1|3|4’]

    What actually should look like this

    $data = [[‘id’ => ‘1’],[‘id’ => ‘3’],[‘id’ => ‘4’]]

    Should i use a custom DataConverter before deserialization ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #33895

    Dima Makaruk
    Participant

    The DefaultDataConverter doesn’t check if the value should be an array:

    It look only if the key must be an array for further support of relations when deserializing.

    #33896

    Sergey
    Participant
    #33897

    Dima Makaruk
    Participant

    Hi thank you for the tip.
    Somehow i’ve missed the TreeDataConverter class,will try to use it.

    P.S.
    I created additional normalizer for this case it worked.

Viewing 3 replies - 1 through 3 (of 3 total)

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top