putyourlightson / craft-campaign

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

Import of Contacts from CSV with Categories - Category Values Ignored #392

Closed adrianjean closed 1 year ago

adrianjean commented 1 year ago

Following up on: https://github.com/putyourlightson/craft-campaign/issues/390

Seems I was wrong, Category fields don't import from CSV either. Imports complete without error, but it appears the data for the category is ignored by the import and no category is set on the contact's profile field.

I tried importing by:

None of them work.

bencroker commented 1 year ago

Related element field values are posted as an array of element IDs, which is the format that the import expects as well. So [1] for one element and [1, 2, 3] for multiple elements. Does that work?

bencroker commented 1 year ago

I’ve added info modals with instructions for fields that expect specific formats in https://github.com/putyourlightson/craft-campaign/commit/25dcb8a5ad6e4c48b160066979055a71e60a13c3, for the next release.

Screenshot 2023-05-27 at 10 19 57
adrianjean commented 1 year ago

Ok, using brackets around the values works but only for single values. Multiple values fails.

What's funny is the logs error out as if it doesn't understand the next value as the problem, but it's the array that only changed.

bencroker commented 1 year ago

Can you show me what the logs say?

adrianjean commented 1 year ago

Here's the CSV

email,contactFirstName,contactLastName,contactPhone,contactAddressStreet,contactAddressPostalCode,contactGender,contactGroup,contactSupport,contactVolunteer,contactWard,contactDonationAmount
test2@email.com,Sarah,Smith,555-445-2354,"47 Main St.","Z1Z1Z1",female,[25738],no,volunteer,[25772,25771],800

When imported here is the log report:

[2023-05-27 08:26:33] Line 1: Donation Amount must be a number.. Donation Amount must be a number.

Some notes:

bencroker commented 1 year ago

Could you test using this format? Assuming it works, I can add a fix for the next release.

"[""1"",""2""]"

bencroker commented 1 year ago

Oh I think I see the issue, it's the comma separating the IDs, so this will likely work.

"[1,2]"

adrianjean commented 1 year ago

That works "[1,2]" for Category fields — however for "Multi Select" fields, the same technique doest work.

bencroker commented 1 year ago

Right, that will only work for integers, strings must still be surrounded by double double quotes.

adrianjean commented 1 year ago

Yes! It works for Multi Select using format "[""donor"",""adamList""]" and the "values" or slugs.

Seems all sorted now. Thank you so much for being so responsive!!

So:

In both cases, the variables/categories already need to exist in CraftCMS

bencroker commented 1 year ago

Yup, that’s correct and added to the import field info modals for the next release.

Screenshot 2023-05-27 at 17 51 44