Problem
I'm getting the error message when updating member info:
Fatal error: Cannot use object of type stdClass as array in sites/all/modules/mailchimp/mailchimp.module on line 565
or this error message when unsubscribing member:
Fatal error: Cannot use object of type stdClass as array in sites/all/modules/mailchimp/mailchimp.module on line 552
Solution:
Looking at function mailchimp_update_local_cache is clear that in some places $cache object is accessed as array.
function mailchimp_update_local_cache($function, $args) {
$list_id = isset($args['list_id']) ? $args['list_id'] : NULL;
$email = isset($args['email']) ? $args['email'] : NULL;
if (empty($list_id) || empty($email)) {
return FALSE;
}
$cache = mailchimp_get_memberinfo($list_id, $email);
if (empty($cache)) {
// Create a new entry.
cache_set($list_id . '-' . $email, array('merges' => array()), 'cache_mailchimp', CACHE_TEMPORARY);
$cache = cache_get($list_id . '-' . $email, 'cache_mailchimp');
$cache = $cache->data;
}
// Handle unsubscribes.
if ($function == 'mailchimp_unsubscribe_process') {
<strong> $cache['status'] = 'unsubscribed';</strong>
// Reset interests.
$cache->interests = new stdClass();
}
// Handle subscribes.
if ($function == 'mailchimp_subscribe_process') {
<strong> $cache['status'] = 'subscribed';</strong>
}
// Handle member updates.
if ($function == 'mailchimp_update_member_process' ||
$function == 'mailchimp_subscribe_process') {
// Update cached merge vars.
foreach ($args['merge_vars'] as $key => $value) {
<strong> $cache['merges'][$key] = $value;</strong>
}
}
// Store the data back in the local cache.
cache_set($list_id . '-' . $email, $cache, 'cache_mailchimp', CACHE_TEMPORARY);
}
So, it needs to be corrected like below:
$cache->status = 'unsubscribed';
$cache->status = 'subscribed';
$cache->merges[$key] = $value;
Comments
Comment #3
ruscoe commentedThank you. I've committed a fix for this and we'll have a new release ready later today.
Comment #4
scotwith1tSorry to reopen, but if batch processing is turned on, this is still broken. I kept getting this after upgrading to 4.1 and checked settings, decided to turn off batch processing. The error goes away without batch processing on. Thanks!
Comment #5
ruscoe commentedComment #7
ruscoe commentedYou're right, that was still failing in batch mode. Fixed in 7.x-4.2.