Manipulate datas before importing to tailor model

Hello,

I need to import datas from a CSV given by the client.

I cant import raw datas, I need to do some operation before importing, for example saving a relation between a product and a category whereas the category in the CSV is an integer (so I need to search for the corresponding category, and save it as a relation to the product I import).

So be simple, I need the power of PHP / laravel to manipulate my datas before creating the corresponding tailor models, how can I do that ?

Thank you

You can hook into the model.beforeSave event to add this content to there:

https://octobercms.com/docs/api/model/beforesave

@artistro08 but this method will also be triggered when you add a new model using the backend isn’t it ? I’m not sure if I have the necessary conditions to check if the model is created using an import or using the backend form

You’re correct, but you could do some checks to see where the model is being saved

Let us know if you need us to include some new event hooks to help with this.

@daft
I finally created a “true” plugin to handle import exactly as I want, but it’s true that some hooks to be able to modify the $data array before importing model would be a great addition to tailor.

Best regards