Problem

When subscription field is added to user entity and upon checking the subscription field and saving the user, it updates the database correctly (creates new row for the "field__subscription") but it never shows that to user. The field is always unchecked.

Steps to reproduce

Install the module from composer, enable all Mailchimp sub module. Add new field "subscription" type to user entity and try to saving the field for any registred user.

Proposed resolution

Show the field is checked.

Issue fork mailchimp-3231414

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

admirernepali created an issue. See original summary.

guido_s’s picture

I've got the same problem. I set up a webhook and so on, but the checkbox which I added to the user account fields is always unchecked.
Sign up for the newsletter works with this checkbox, but it doesn't represent the current status and doesn't give you the possibility to unsubscribe.

But the Mailchimp Lists module documentation says it should be capable of this https://www.drupal.org/docs/contributed-modules/mailchimp/mailchimp-lists

rob230’s picture

I think this could be related? I'm having the problem that everyone is now being unsubscribed after updating the module. I don't know what has changed, but in the database the value for field_name_subscribe was 0 for every single row, and these are people that are subscribed in Mailchimp.

It seems that previously that's how it used to work. The only entries that have 1 are new subscriptions created after updating the module, the old ones going back years are all 0.

What's happening now when the user entity is saved (even by the system rather than the user using a form) is the following.

In MailchimpListsSubscription::postSave() (which fires every time an entity is saved that has a subscription field on it):

$choices = $this->values;

// Only act if the field has a value to prevent unintended unsubscription.
if (!empty($choices)) {
  // ...

  mailchimp_lists_process_subscribe_form_choices($choices, $this, $this->getEntity());
}

$choices always contains $choices['subscribe'] = 0, particularly if this save has come from cron or a hook rather than from the form.

In mailchimp_lists_process_subscribe_form_choices():

$subscribed = mailchimp_is_subscribed($settings['mc_list_id'], $email);

if ($choices['subscribe'] != $subscribed) {
  // Subscription selection has changed.
  if ($choices['subscribe']) {
    $function = 'add';
  }
  else {
    $function = 'remove';
  }
}
elseif ($choices['subscribe']) {
  $function = 'update';
}

$choices['subscribe'] is always 0, so people are being unsubscribed.

This is a very major issue, we are losing thousands of subscribers per day!

I could set the value of every field_name_subscribe to 1 in the database, but I don't know if they have actually subscribed or not. I don't know what to do. It seems like the historical data doesn't match what the module now expects to be there which is causing everybody to be unsubscribed.

xenophyle’s picture

Assigned: Unassigned » xenophyle

  • xenophyle committed 5cba5465 on 2.x
    Issue #3231414 by xenophyle, admirernepali, Rob230: Subscription box is...
xenophyle’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.