diff --git a/app/models/spree/marketing/list.rb b/app/models/spree/marketing/list.rb index 247f3b9..0e5d313 100644 --- a/app/models/spree/marketing/list.rb +++ b/app/models/spree/marketing/list.rb @@ -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 diff --git a/app/models/spree/marketing/list/abandoned_cart.rb b/app/models/spree/marketing/list/abandoned_cart.rb index d65b126..d6cfaf6 100644 --- a/app/models/spree/marketing/list/abandoned_cart.rb +++ b/app/models/spree/marketing/list/abandoned_cart.rb @@ -6,16 +6,14 @@ class AbandonedCart < Spree::Marketing::List NAME_TEXT = 'Abandoned Cart' AVAILABLE_REPORTS = [:purchases_by].freeze - def user_ids - # 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 diff --git a/app/views/spree/admin/marketing/lists/show.html.erb b/app/views/spree/admin/marketing/lists/show.html.erb index 92fd77c..039abfc 100644 --- a/app/views/spree/admin/marketing/lists/show.html.erb +++ b/app/views/spree/admin/marketing/lists/show.html.erb @@ -15,7 +15,11 @@ <% @contacts.each do |contact| %> - <%= link_to contact.email, edit_admin_user_path(id: contact.user_id), target: '_blank' %> + <% if contact.user_id %> + <%= link_to contact.email, edit_admin_user_path(id: contact.user_id), target: '_blank' %> + <% else %> + <%= contact.email %> + <% end %> <%= contact.uid %> <% end %>