Import Definitions


#1

Hi,
I have use “Import Definition” bundle to import csv and to create data-objects.

Now I need to put imported data-Object to relevant folders. I need to do it automatically.

eg -

  • Import fist row of the CSV
  • Check the CSV first row “Category” column value
  • According to column value need to move into relevant folder.

I have tried with “Runner” is it possible to do this using “Runner” or not?

I can see it’ll says to create service -

  • where I need to create this service?
  • Do I need to create new bundle?

I can see it says - “acme_bundle.import_definition.my_runner:

  • That mean “acme_bundle” is new bundle we need to create?
  • “import_definition” means “Import Definition” bundle location or?
  • And implementation of “RunnerInterface” where I need to place this class file?

Is there have any solution to this

Thanks.


#2

Hi,
to set the path of imported objects you can use Path field in import definition settings. There you can use placeholders to set path eg. to: /products/%Text(mycolumn1);/%Text(mycolumn2);
mycolumn1 and mycolumn2 are the names of the columns in csv. This will automatically create the folder also if it doesn’t already exist.
For more complicated structures not achievable by above directly I am using my own interpreter which returns correct folder (and creates it if it doesn’t exist). I then set it in Mappings in o_parent with Custom From column and my folder interpreter.
But as starter I think the first solution should work well for most cases.


#3

BTW: If you don’t know what a service is, move a step back and start with the symfony documentation first: https://symfony.com/doc/3.4/index.html#gsc.tab=0


#4

Thank you very much… My csv it’s comes with category code not full name. I hope I need to do some mapping.

eg:-
csv column category value is - OFH
my data-object folder name is Office & Furniture Hardware

I need to match those two and place into correct folder.

What is the best way to do this with “Import Definitions” code?

Thanks.


#5

You somehow have to define how to map it. Either use object-properties or something else… You need to decide how to do the mapping


#6

Ok, Thanks mertaivan and dpfaffenbauer

It is really help full your reply mertaivan according to that I have implement my solution and here I’m going to keep what I have been done. I think it’ll help to others to understand.

Fist install Import Definition -

(it’ll install into - /var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/)

composer require w-vision/import-definitions:^2.0-dev

bin/console pimcore:bundle:enable ImportDefinitionsBundle

bin/console pimcore:bundle:install ImportDefinitionsBundle

Add new custom Interpreter

Add “categorymap.js” to
/var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Resources/public/pimcore/js/interpreters/categorymap.js

Add “CategoryMap.php” to
/var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Interpreter/CategoryMap.php

Add “CategoryMapInterpreterType.php” to
/var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Form/Type/Interpreter/CategoryMapInterpreterType.php

Update Service.yml in -
/var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Resources/config/services.yml

adding Following -

    import_definition.interpreter.category_map:
        class: ImportDefinitionsBundle\Interpreter\CategoryMap
        tags:
            - { name: import_definition.interpreter, type: category_map, form-type: ImportDefinitionsBundle\Form\Type\Interpreter\CategoryMapInterpreterType }

Update config.yml in -

adding follwing -

interpreter_categorymap: '/bundles/importdefinitions/pimcore/js/interpreters/categorymap.js'

To import csv use following CLI command -

Run upload - bin/console import-definitions:import -d 1 -p "{\"file\":\"sap_export1.csv\"}"

Thanks.


#7

NEVER work directly in the vendor folder! Once you install an update, everything is gone!

It works the same by adding all of those files into your AppBundle!


#8

Thanks dpfaffenbauer,

it’s true I have move my code into new bundle and now there is no any code update in vendor folder.

Thanks