Class: Spree::Customers::Create
- Defined in:
- app/workflows/spree/customers/create.rb
Overview
Creates a customer account — the single storefront registration flow (docs/plans/6.0-service-workflows.md decision 13).
Two callers today: store self-registration and the checkout "create an
account" box, which passes order: — the customer is built from the
order without a password (the account is claimed via password reset,
like an admin-created one), the order's addresses become the account's
defaults and the order is linked to the new account.
The validate hook is the veto seam for registration policy —
bot/disposable-email screening, fraud checks, B2B approval. Handlers
read the built (unsaved) customer plus order/created_by; staff
bypass is a handler decision via created_by, the same pattern as
return eligibility. Core sends no welcome email — signup email is
host-app code on the user.created event or the after_create hook.
Instance Attribute Summary collapse
-
#customer ⇒ Object
readonly
The customer record — built (unsaved) while :validate runs.
Instance Method Summary collapse
Methods inherited from Workflow
#call, define_argument_readers, #errors, #halt!, hooks, inherited, model_name, #read_attribute_for_validation, #reject!, workflow_key
Methods included from ServiceModule::Base
Methods included from Workflow::ControlFlow
Instance Attribute Details
#customer ⇒ Object (readonly)
The customer record — built (unsaved) while :validate runs.
22 23 24 |
# File 'app/workflows/spree/customers/create.rb', line 22 def customer @customer end |
Instance Method Details
#perform(store:, email: nil, password: nil, password_confirmation: nil, first_name: nil, last_name: nil, phone: nil, accepts_email_marketing: nil, metadata: nil, order: nil, password_required: nil, created_by: nil, terms_of_service: nil, ip_address: nil, user_agent: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/workflows/spree/customers/create.rb', line 49 def perform(store:, email: nil, password: nil, password_confirmation: nil, first_name: nil, last_name: nil, phone: nil, accepts_email_marketing: nil, metadata: nil, order: nil, password_required: nil, created_by: nil, terms_of_service: nil, ip_address: nil, user_agent: nil) super step :adopt_existing_customer step :build_customer step :ensure_password # Veto point — registration policy. The customer is built but not # yet persisted. run_hooks :validate ApplicationRecord.transaction do step :create_customer step :link_order step :record_consent end step :link_newsletter_subscriber run_hooks :after_create success(order ? customer.reload : customer) end |