Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brendan Rice 538 posts 1102 karma points
    Sep 22, 2010 @ 17:23
    Brendan Rice
    0

    Umbraco Member Event Syncing with MailChimp

    I need to sync umbraco members with a MailChimp account.  The bit I am struggling with is the following events and knowing when to create/update/delete an email in MailChimp.

    If I am in the Ubraco admin section and I create a user the event AfterNew is fired followed by BeforeSave then AfterSave.  I was going to put a flag in to the AfterNew to say that the member is a new member and add them to MailChimp ain AfterSave.

    When the Member is being edited in Umbraco I need to know what the old/new email addresses are for syncing purposes.  What is the best practice for going about this?  BeforeSave sender already has the updated email and when I do a Member.GetMemberFromLoginName the member email is already updated, any help would be great.

     

       public class UmbracoMembershipIntegration :  ApplicationBase
        {
            public UmbracoMembershipIntegration()
            {
                Member.BeforeSave += new Member.SaveEventHandler(Member_BeforeSave);
                Member.AfterSave += new Member.SaveEventHandler(Member_AfterSave);
                Member.AfterDelete += new Member.DeleteEventHandler(Member_AfterDelete);
                Member.BeforeDelete += new Member.DeleteEventHandler(Member_BeforeDelete);
            }

            void Member_BeforeDelete(Member sender, DeleteEventArgs e)
            {
                Member member = sender;
            }

            void Member_BeforeSave(Member sender, SaveEventArgs e)
            {
                Member member = sender;
            }

            void Member_AfterDelete(Member sender, DeleteEventArgs e)
            {
                Member member = sender;
            }

            public void Member_AfterSave(Member sender, umbraco.cms.businesslogic.SaveEventArgs e)
            {
                Member member = sender;
            }
        }

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 23, 2010 @ 00:28
    Aaron Powell
    0

    Members fall into the same trap that I described here: http://www.aaron-powell.com/the-great-umbraco-api-misconception

    I'd actually go about syncing with the member id rather than the email if the email can be changed.

  • Brendan Rice 538 posts 1102 karma points
    Sep 23, 2010 @ 13:54
    Brendan Rice
    0

    Thanks Slace, totally not the way I was expecting things to work.  It almost seems like a bug in Umbraco to me.  MailChimp does accept custom properties and I could set one up for an Umbraco Member ID just seems like there is going to be more work in it than there should be.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 23, 2010 @ 14:05
    Aaron Powell
    0

    Yeah it's a known problem, and its down to the design of data types in version 4.x (see: http://www.aaron-powell.com/umbraco-data-type-design ). Although I did "fix" it for documents in 4.5 it required a lot of dodgy work and to have it working for all objects based on content type it was going to add too much overhead.

    Sadly it's something we have to live with.

    Actually, another idea I just had was you create your own DataType for email which stores current & last value, so you can fully control it, or even store all previous email addresses.

  • Brendan Rice 538 posts 1102 karma points
    Sep 23, 2010 @ 15:07
    Brendan Rice
    0

    That is not a bad idea, I will look into it more when I am back in the office tomorrow.  Thanks for the input really appreciate it.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 23, 2010 @ 15:14
    Aaron Powell
    0

    Well the data type would give you the most redundancy so if a password is changed multiple times before you sync you can still handle it nicely.

  • Brendan Rice 538 posts 1102 karma points
    Sep 27, 2010 @ 12:39
    Brendan Rice
    0

    MailChimp doesn't let me retrieve by a custom variable so that only left me with the option of setting up a custom datatype.

    Could you help with the following questions:

    1. I can't see how I can get access to the "Member Email" datatype on the member section, I am assuming this is core Umbraco and should not be changed, is that right?
    2. If I can get access to it what would the best practice be for implementing the datatype (I was thinking of having an array that gets put to a string and saved for the Data.Value) does this sound about right?
    3. What about rendering the datatype would I have to render the comma delimited string to a hidden field to persist the value?

    Thanks again for the help.

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 27, 2010 @ 14:07
    Aaron Powell
    0

    Ah shit you're right, Email is built into the Member object so you wont be able to change the data type...

    You'll just have to create a property and ensure your users are trained to never use the other field :P

  • Brendan Rice 538 posts 1102 karma points
    Sep 27, 2010 @ 15:55
    Brendan Rice
    0

    Figured that out, we went with a custom property that is a label so it can never be changed.

Please Sign in or register to post replies

Write your reply to:

Draft