Jump to content

trackChanges


LostKobrakai
 Share

Recommended Posts

I'm currently trying to get a custom fieldtype, which uses InputfieldCheckboxes to work with trackChanges (show changed values as well), but I cannot seem to get it to work. It should just be a simple multiselect of subscribable newsletters, that are loaded from mandrill. Does anybody have any insights on how to tackle that? I need to be able to get the changes, so I can add/remove users from the mailchimp lists accordingly.

Link to comment
Share on other sites

Ok, just notices, that my page field's changes are tracked as well as my custom module's. 

array(2) { 
  ["subscribed_to"]=> array(1) { [0]=> NULL }
  ["mailchimp_newsletter"]=> array(1) { [0]=> NULL }
}

Can I somehow get useful values out of getChanges(true)?

Link to comment
Share on other sites

I am not sure if the following will fit your needs. I wrote a module to subscribe/ unsubscribe from mailchimp using a checkbox  in the users template + updating mailchimp if the email address has changed. User profile is provided in frontend. All changings are logged by the module. Here the snippet of the template.

function hookAfterSave($event) {
	$modules = wire('modules');
	$user = wire('users')->getCurrentUser();
	if ($event->arguments('what') == 'newsletter') {
		if ($event->arguments('new') == 1) $modules->get('ProcessMailchimp')->subscribe($user->email,false);
		else $modules->get('ProcessMailchimp')->unsubscribe($user->email);
	}
	if ($event->arguments('what') == 'email') {
		if ($event->arguments('old') != $event->arguments('new') && $user->newsletter) $modules->get('ProcessMailchimp')->update($event->arguments('old'),$event->arguments('new'));
	}
}

And the module (running on pw 2.5.29, not tested in 2.6 latest devs)
ProcessMailchimp.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...