BlackbitDigitalCommerce / pimcore-data-director

Import Bundle for Pimcore
16 stars 3 forks source link

Identify field collection item for the import #118

Closed ascheider closed 11 months ago

ascheider commented 12 months ago

we have a field collection which is named Pcm image The collection contains some fields which are imported: image If i change something and reimport the item, i always get a new collection item in the object. image

The question is, how can i identify the item and update the collection item instead of creating new one? I did not found any examples in the book or am i blind? Thank you!

BlackbitDevs commented 12 months ago

If i change something and reimport the item, i always get a new collection item in the object.

This is on purpose. When you want to keep some of the current field collection items while removing others, please enable Truncate before import checkbox and then use $params['currentValue'] to loop through currently assigned field collection items. The ones which you want to keep you put into an array. And to this array you also add the ones which the import shall create. Then you return the array and have your desired items in the field collection.

ascheider commented 12 months ago

@BlackbitDevs Thanks for quick reply. CurrentValue seems not be present on this point. image I guess i need to load the object here and extract the data via getter.

BlackbitDevs commented 12 months ago

No, it is present but currently there are no items in the field collection, that's why you get an empty array (= [])

I guess i need to load the object here and extract the data via getter.

When you have this thought on any place when you use Data Director, there most often is an easier way. The whole purpose of this bundle is to not have to learn about all those PHP and Pimcore internals.

ascheider commented 11 months ago

@BlackbitDevs you are right, the entities present in the currentValue. It works like you described.