DynamoMTL / spree_chimpy

Spree/MailChimp Integration
BSD 3-Clause "New" or "Revised" License
35 stars 123 forks source link

'groupings' merge_var not subscribing user to specified group in list #68

Closed wcalebgray closed 7 years ago

wcalebgray commented 8 years ago

Hello,

I'm trying to insert a merge_var for 'groupings' as I've done with the Mailchimp API in the past to automatically subscribe the user to a specific group within my list. I've tried to set this in the config as follows:

config.merge_vars = {
    'EMAIL' => :email,
    'FNAME' => :first_name,
    'LNAME' => :last_name,
    'groupings' => [{
      'name' => Rails.application.secrets.mailchimp["sign_up_type_group_name"],
      'groups' => [Rails.application.secrets.mailchimp["store_customers_subgroup_name"]]
    }]
  }

The user is subscribed with his/her first and last names as expected, but the grouping does not show up. I have another form in this same project that allows a user to sign-up without creating a user profile. It uses an identical format for the merge_vars, just with a different subgroup name and works as expected.

Also, I do believe 'groupings' needs to be lower-case for this to work, from the many StackOverflow posts I've checked out.

Any ideas?

Thanks!

wcalebgray commented 8 years ago

I think this is where the problem is coming from:

def merge_vars(model)
    attributes = Config.merge_vars.except('EMAIL')

    array = attributes.map do |tag, method|
      value = model.send(method) if model.methods.include?(method)

      [tag, value.to_s]
    end

    Hash[array]
  end

I'll attempt to fix this and submit a PR. It doesn't look like this method is set up to take arrays as values in the merge_vars.

braidn commented 8 years ago

@wcalebgray hmm, I was previously unaware of groupings. The merge vars method like you showed would have to pivot on a the method being an array. Than the array of methods would have to be available on the user object?

braidn commented 8 years ago

@wcalebgray this, I believe(the MailChimp API docs are a little bonkers) is the method we use to add merge vars. I am only seeing key value pairs as params and no arrays. Am I missing something? Perhaps the groupings call was in the v1 version of their API?

braidn commented 7 years ago

@wcalebgray there was just a move to mailchimp 3.0 API can you see if you are still having the issue and maybe create a new fresh issue? Thank you.