{"title":"Accounts Controller - Liquid Controller Reference","slug":"accounts-controller-reference","url":"https://support.storeconnect.com/articles/accounts-controller-reference","url_markdown":"https://support.storeconnect.com/articles/accounts-controller-reference.md","subtitle":null,"summary":"Intercept account show, register, and create requests using Liquid controller templates at `controllers/accounts/`. Supports before, after, and final lifecycle phases for setting variables, redirecting, customizing responses, and passing custom contact fields during registration.","type":"Developer_Documentation","video_url":"","keywords":"liquid, controllers, Accounts, storefront, storeconnect, registration, custom fields, before phase, after phase, final phase, create action, register action, duplicate contact, session timeout, birthdate field, custom contact fields, registration form, email verification, contact deduplication, Liquid lifecycle, AccountsController, registration controller","last_modified":"2026-08-21T07:12:35+0000","body_markdown":"## Description\n\nUse Liquid controller templates in `controllers/accounts/` to intercept account requests before or after they are processed — for example, to redirect users, set template variables, or write custom Contact fields during registration.\n\n| Property | Value |\n|----------|-------|\n| **Controller** | `AccountsController` |\n| **Liquid Template Path** | `controllers/accounts/` |\n\n## Actions\n\n| Action | HTTP Method | Route | Liquid Page | Description |\n|--------|-------------|-------|-------------|-------------|\n| `show` | GET | `/accounts/:id` | `account` | Renders the account page for the current customer. |\n| `register` | GET | `/accounts/register` | — | Renders the registration form. |\n| `create` | POST | `/accounts` | — | Processes the registration form submission and creates the Account and Contact. |\n| `missing_details` | GET | `/accounts/missing-details` | — | Shown when a customer logs in but required account fields are incomplete. |\n| `go_back_with_errors` | GET | `/accounts/go-back-with-errors` | — | Redirects the customer back to the previous form with validation errors surfaced. |\n\n## Liquid Controller Lifecycle\n\nFor each action, Liquid controller templates are executed in three phases:\n\n1. **Before** — `controllers/accounts/{action}.liquid` runs before the Rails action\n2. **After** — runs after the Rails action but before the response is sent\n3. **Final** — runs after the response is sent; use it to clean up session variables or temporary state\n\n## Available Liquid Tags\n\nInside controller templates, these tags are available:\n\n| Tag | Description |\n|-----|-------------|\n| `{% params %}` | Set request parameters (e.g. `{% params foo: \"bar\" %}`) |\n| `{% variables %}` | Set template variables (e.g. `{% variables title: \"Hello\" %}`) |\n| `{% respond %}` | Respond with custom content, alert, or notice |\n| `{% redirect %}` | Redirect the request (e.g. `{% redirect to: \"/products\" %}`) |\n| `{% action %}` | Execute a server-side action (e.g. `{% action \"cart.add\" %}`) |\n\n## Example: basic show customization\n\nCreate a file at `controllers/accounts/show.liquid`:\n\n\n```liquid\n\n{% before %}\n  variables custom_heading: \"Welcome\"\n{% endbefore %}\n```\n\n\n## Custom fields during registration\n\nThe `create` action runs when a visitor submits the registration form. You can use the `before` and `after` phases to pass custom fields from the registration form directly to the new Contact record, without needing a separate generic form.\n\nStoreConnect creates the Account and Contact on the website side and then syncs the changes to Salesforce automatically — including any custom field values you write in the `after` phase.\n\n### How it works\n\n| Phase | Purpose |\n|-------|---------|\n| `before` | Check for an existing Contact with the same email and store the result in session — this blocks duplicate registrations |\n| `after` | Find the newly created Contact and write custom field values from the form params |\n| `final` | Clear the session variable used during duplicate checking |\n\n### Example: adding a birthdate field\n\nThis example:\n- Blocks registration if a Contact with the same username (email) already exists\n- Writes a `birthdate` field from the form to the new Contact after creation\n\nCreate a file at `controllers/accounts/create.liquid`:\n\n\n```liquid\n\n{% liquid\n  before\n    session registration_contact_id: blank\n\n    assign username = current_request.params.email\n\n    if username != blank and username != nil\n      query 'Contact' as contacts, s_c__username__c: username\n      if contacts.size \u003e 0\n        assign contact = contacts | first\n        session registration_contact_id: contact.s_c__sc_id__c\n      endif\n    endif\n  endbefore\n\n  after\n    new Map additional_fields_map\n    assign additional_fields_map = additional_fields_map | set_key: 'birthdate', 'birthdate'\n\n    assign params = current_request.params\n    assign username = current_request.params.email\n\n    if username != blank and username != nil\n      if session_variables.registration_contact_id == blank\n        query 'Contact' as contacts, s_c__username__c: username\n        if contacts.size \u003e 0\n          assign contact = contacts | first\n          assign contact_drop = contact | cast: 'Contact'\n          assign additional_fields = additional_fields_map | keys\n          for field in additional_fields\n            if params contains field\n              assign sf_field = additional_fields_map[field]\n              assign value = current_request.params[field]\n              update contact_drop, field: sf_field, value: value\n            endif\n          endfor\n        endif\n      endif\n    endif\n  endafter\n\n  final\n    session registration_contact_id: blank\n  endfinal\n%}\n```\n\n\n### Adding more custom fields\n\nTo write additional fields, add more `set_key` calls to `additional_fields_map` in the `after` phase. The key is the `name` attribute of the form input; the value is the Salesforce field API name on the Contact object.\n\n```liquid\n\nassign additional_fields_map = additional_fields_map | set_key: 'birthdate', 'birthdate'\nassign additional_fields_map = additional_fields_map | set_key: 'phone', 'phone'\nassign additional_fields_map = additional_fields_map | set_key: 'company_name', 'custom_company_name__c'\n```\n\nEach key must match the `name` attribute of the corresponding input in your registration form template.\n\n:::note\nThe duplicate-contact check in the `before` phase uses `s_c__username__c`, which StoreConnect stores as the contact's email address. If a Contact with that username already exists, `registration_contact_id` is set in session and the `after` phase skips the field update — the registration form will surface an error to the visitor.\n:::"}