class Api::Admin::IndexEnterpriseSerializer < ActiveModel::Serializer attributes :name, :id, :permalink, :is_primary_producer, :sells, :producer_profile_only, :owned, :edit_path attributes :issues, :warnings def owned return true if options[:spree_current_user].admin? object.owner == options[:spree_current_user] end def edit_path edit_admin_enterprise_path(object) end def shipping_methods_ok? return true unless object.is_distributor object.shipping_methods.any? end def payment_methods_ok? return true unless object.is_distributor object.payment_methods.any? end def issues issues = [] issues << { description: "#{object.name} currently has no shipping methods.", link: "Create New" } unless shipping_methods_ok? issues << { description: "#{object.name} currently has no payment methods.", link: "Create New" } unless payment_methods_ok? issues << { description: "Email confirmation is pending. We've sent a confirmation email to #{object.email}.", link: "Resend Email" } unless object.confirmed? issues end def warnings warnings = [] warnings << { description: "#{object.name} is not visible and so cannot be found on the map or in searches", link: "Edit" } unless object.visible warnings end end