Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mailchimp contacts for not registered users #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/models/spree/marketing/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ def self.computed_time
end
private_class_method :computed_time

protected

def all_users(emails)
registered_users = Spree.user_class.where(email: emails)

user_emails = registered_users.pluck(:email)
unregistered_emails = emails - user_emails

unregistered_users = unregistered_emails.map{|email| Spree.user_class.new(email: email) }

registered_users.to_a + unregistered_users
end

private
def computed_time
self.class.send :computed_time
Expand Down
18 changes: 8 additions & 10 deletions app/models/spree/marketing/list/abandoned_cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ class AbandonedCart < Spree::Marketing::List
NAME_TEXT = 'Abandoned Cart'
AVAILABLE_REPORTS = [:purchases_by].freeze

def user_ids
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergeyMell You can't just replace user_ids method. It will simply raise exception as mentioned here .

If you want to change this list type. You will have need to change the whole flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place where user_ids is used is method users. As long as I've changed this method it won't break anything. The only thing I should change is 3 test cases - I'll do this ASAP.

# FIXME: There is a case where guest user has an incomplete order and we
# might have his email if he has processed address state successfully
# right now we are leaving that case.
Spree::Order.incomplete
.of_registered_users
.where.not(item_count: 0)
.distinct
.pluck(:user_id)
end
private

def users
order_emails = Spree::Order.incomplete.where.not(item_count: 0).distinct.pluck(:email).compact.uniq

all_users(order_emails)
end

end
end
end
Expand Down
6 changes: 5 additions & 1 deletion app/views/spree/admin/marketing/lists/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
<tbody>
<% @contacts.each do |contact| %>
<tr>
<td><%= link_to contact.email, edit_admin_user_path(id: contact.user_id), target: '_blank' %></td>
<% if contact.user_id %>
<td><%= link_to contact.email, edit_admin_user_path(id: contact.user_id), target: '_blank' %></td>
<% else %>
<td><%= contact.email %></td>
<% end %>
<td><%= contact.uid %></td>
</tr>
<% end %>
Expand Down