putyourlightson / craft-campaign

Send and manage email campaigns, contacts and mailing lists in Craft CMS.
https://putyourlightson.com/plugins/campaign
Other
64 stars 24 forks source link

CSV Import mapping: automatically detect categories/entries by slug/title #454

Closed robinbeatty closed 5 months ago

robinbeatty commented 7 months ago

A common use I've come up against with several clients is when we have a categories field or entries field on a contact and want to assign categories/entries for the contact as defined in an imported CSV. Currently I've been training clients to retrieve the element ID from the CMS, then make an array of IDs for each row of the CSV etc.

What would be really cool is if they could just make a comma-separated list of category slugs or titles (ideally either) and the plugin finds them (or ignores them if not matched). – would be a real quality of life improvement for authors dealing with contact lists all day!

bencroker commented 7 months ago

Thanks for the suggestion. The issue I have with allowing slugs or titles is that they are not necessarily unique, meaning that the plugin would have to decide what to do if a title was submitted that two or more entries share. Titles can also contain commas, which means that you’d have to train the client how to handle that type of situation. Also, the fact that arranging titles in a comma-separated list is not necessarily any less work than arranging a list of IDs, makes me wonder what the actual benefit would be over simply using IDs, especially when considering the afore-mentioned pitfalls.

robinbeatty commented 7 months ago

Understood – perhaps not titles then (or use another delineator?). In our use cases they're mostly categories from a single group (which would have unique slugs). Am I right in thinking that slugs will be globally unique in craft 5? I know it wouldn't work perfectly in all use cases for the reasons you described, but I imagine for vast majority of people it would be a great feature. Campaign could still also post the raw array of ids as it currently does as a fallback.

Also same method for assigning to segments...!?

If you don't fancy it, would you mind pointing me to where in the plugin code I might make a patch to implement this? Thanks

bencroker commented 7 months ago

Am I right in thinking that slugs will be globally unique in craft 5?

Not that I’m aware of. Slugs are only unique if tied to a URI format, which isn’t always the case.

Also same method for assigning to segments...!?

Can you explain this in more detail?

If you don't fancy it, would you mind pointing me to where in the plugin code I might make a patch to implement this?

You could listen for the ImportsService::EVENT_BEFORE_IMPORT event and perhaps modify the import data at that point. https://github.com/putyourlightson/craft-campaign/blob/24e717764a79452bbdba4a1deadd10666c97d357/src/services/ImportsService.php#L30

bencroker commented 5 months ago

Closing due to inactivity.