Class: Spree::Companies::AddMember
- Inherits:
-
Object
- Object
- Spree::Companies::AddMember
- Includes:
- ServiceModule::Base
- Defined in:
- app/services/spree/companies/add_member.rb
Overview
Adds a person to a company node by email — the single convergent path behind both the dashboard's and the storefront's "add member".
An email that matches an existing customer becomes a membership
immediately; an unknown email becomes a Spree::CompanyInvitation,
whose creation event sends the invite mail. Extension payloads (e.g. an
Enterprise role reference) ride metadata on either record.
Instance Method Summary collapse
-
#call(company:, email: nil, customer: nil, inviter: nil, metadata: nil, require_acceptance: false) ⇒ Spree::ServiceModule::Result
Value is the created Spree::CompanyMembership or Spree::CompanyInvitation.
Methods included from ServiceModule::Base
Instance Method Details
#call(company:, email: nil, customer: nil, inviter: nil, metadata: nil, require_acceptance: false) ⇒ Spree::ServiceModule::Result
Returns value is the created Spree::CompanyMembership or Spree::CompanyInvitation.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/services/spree/companies/add_member.rb', line 32 def call(company:, email: nil, customer: nil, inviter: nil, metadata: nil, require_acceptance: false) normalized_email = (email.presence || customer&.email).to_s.strip.downcase # Acceptance outranks a customer handed in: they are invited by their # address like anyone else, so only the holder can agree to join. customer = require_acceptance ? nil : (customer || Spree.customer_class.find_by(email: normalized_email)) record = if customer company.memberships.new(customer: customer) else company.invitations.new(email: normalized_email, inviter: inviter, metadata: ) end record.save ? success(record) : failure(record) end |