User Type Switcher
The User Type Switcher extension adds a Private / Business user-type toggle to the Hyvä checkout (billing and shipping) and the My Account address form; selecting Business reveals the company, VAT number and registration number fields, persists the type and its fields on the quote, order and customer address, and can optionally remove tax for VAT-registered business customers.
Overview
User Type Switcher is a Venta Theme add-on module that lets shoppers identify as a Private person or a Business at checkout and in their address book. When Business is selected, the company, VAT number and registration number fields are revealed; Private shows no extra fields. The selected type and its fields are persisted on the quote, order and customer address, and tax can optionally be removed for VAT-registered business customers. It uses Tailwind CSS and CSP-safe AlpineJS and requires Venta Theme on top of Hyva, including Hyvä Checkout (hyva-themes/magento2-hyva-checkout).
Documentation
Key Features
Checkout (Hyvä Checkout)
- A two-button Private / Business toggle (full-width segmented control, CSP-safe Alpine) on both the billing and shipping address forms
- Conditional Business fields revealed on demand: Company, VAT Number (
vat_id) and Registration Number (reference) - Company and VAT number are required for Business; Private shows no extra fields
- The selected type and its fields are persisted onto the quote address, and mirrored onto billing when "same as billing" is used
My Account
- The same Private / Business toggle on the address edit form
- Saved type is pre-selected when editing an existing address
- Advisory, non-blocking VAT-number format check on the VAT field
Persistence
user_type(0 = Private, 1 = Business) andreferencestored on the quote address, order address and customer addresscompanyandvat_idreuse the existing Magento core address fields- Business-only fields are cleared when the user is Private
Tax
- Optional removal of tax for a Business customer that has a VAT ID, controlled by a dedicated store-config flag
- Applies at both storefront checkout and admin order creation
Safe by default
- Disabled by default; when off, the module renders no UI or scripts and makes no address or tax changes
Configuration (Admin Guide)
1. Enable User Type Switcher
The module exposes its configuration under Stores → Configuration → Magebit → User Type Switcher.
General
- Enable User Type Switcher (
magebit_user_type_switcher/general/enabled)- Shows the Private / Business switcher in checkout and My Account and applies its behaviour.
- Default No. The feature stays hidden until a store enables it. When disabled the module is inert: it renders no UI or scripts and makes no address or tax changes.
This section supports the standard default / website / store-view configuration scopes.
2. Configure Tax for Legal Customers
Tax behaviour for business customers is controlled by a dedicated field under Stores → Configuration → Sales → Tax → Calculation Settings.
- Apply Taxes To Legal Customers (
tax/calculation/apply_legal_person_tax)- When set to No, tax is removed for VAT-registered legal persons (B2B).
- Default No: tax is removed for a Business customer that has a VAT ID.
- Set to Yes to keep charging tax for business customers.
For a full, step-by-step walkthrough of enabling the module and validating the tax behaviour, refer to the dedicated Setup page for this extension.
Frontend Behaviour
This module is designed for Venta Theme and uses Tailwind CSS and AlpineJS with a minimal-JS implementation. All Alpine is written for Hyvä's CSP build.
Checkout
On the Hyvä checkout, the switcher is injected into both the billing and shipping address forms.
- The toggle
- A full-width, two-button control: Private (user icon) and Business (briefcase icon).
- The active side is filled (highlighted); the inactive side is transparent with the label in the primary colour.
- The choice is written to a hidden
user_typeinput so it submits with the address form.
- Private
- No extra fields are shown; the business fields are hidden and their inputs disabled so a hidden required field cannot block submission.
- Business
- The Company, VAT Number and Registration Number fields are revealed directly beneath the toggle, ahead of the name fields.
- Company and VAT Number are required in this state.
- Billing and shipping independence
- Each address form tracks its own toggle. A selection on the billing form does not drive the shipping form (both render together on the one-page checkout).
- Persistence at save
- When the type is switched to Private, the business fields are cleared.
- When shipping is reused as billing ("same as billing"), the user-type fields are mirrored onto the billing address.
My Account
On the address edit form in My Account, the same Private / Business toggle is rendered.
- The saved user type for the edited address is pre-selected (defaulting to Private for a new address).
- Selecting Business reveals the Company, VAT Number and Registration Number fields, wrapped in the same show/hide behaviour as checkout.
- On save, the business fields are cleared when the type is Private.
VAT Number Format Check
On the My Account VAT field, an advisory format check runs client-side.
- It warns when a VAT number looks malformed for a recognised country prefix (e.g. LV, LT, EE, DE, FR, NL and other supported EU prefixes).
- It never blocks submission. The warning can be dismissed if the number is believed to be correct.
- It stays silent for unrecognised prefixes, so non-EU numbers are not flagged.
- Authoritative VIES validation is intentionally out of scope for this module.
Developer Notes
This section is intended for Magento developers integrating or customising the module.
Database
The module adds two flat columns to the quote, order and customer address tables (quote_address, sales_order_address, customer_address_entity):
user_type- integer,0= Private,1= Business (not nullable, default0)reference- varchar(255), the Registration Number (nullable)
company and vat_id are reused Magento core address fields, so no new columns are added for them. Setup/Patch/Data/AddAddressAttributes also registers user_type (with the UserType source model) and reference as customer_address EAV attributes, adds them to the Default attribute set, and associates them with the admin and customer address forms; etc/fieldset.xml carries both fields across the customer ↔ quote ↔ order address conversions.
The registration-number attribute is deliberately named
reference(rather than something project-specific) to match the refined Venta projects so they can consume this module without an attribute clash.
Frontend Templates
The module provides a small set of templates for its touch points:
- Checkout toggle
- Template:
checkout/form/field/user-type.phtml
- Template:
- Checkout Alpine registration
- Template:
checkout/js/user-type-switcher.phtml
- Template:
- My Account toggle
- Template:
account/user-type-fields.phtml
- Template:
Two CSP-safe Alpine components ship in user-type-switcher.phtml:
ventaUserTypeSwitcher: the toggle. It writes the hiddenuser_typeinput ([data-user-type-input]) and dispatches aventa-user-type-changedwindow event.ventaDependentField: a wrapper component that readsdata-show-for="business"and shows/hides itself in response to that event, disabling hidden inputs so a hidden required field cannot block submission and is not posted for the wrong type.
The inline registration script calls HyvaCsp::registerInlineScript(), components are registered via Alpine.data(), and the markup uses no-paren method references and getter properties, in line with Hyvä's CSP build.
Architecture and Plugins
Model/Form/EntityFormModifier/WithUserTypeModifier: registered on the Hyvä billing and shipping address forms (etc/frontend/di.xml). Force-adds theuser_typefield and the dependentcompany/vat_id/referencefields atform:populate(so Hyvä bindswire:model), and atform:buildsets full-width wrappers and binds each dependent field's wrapper to the toggle. Self-gates onConfig::isEnabled().Block/Customer/Address/UserTypeFields: renders the shared toggle inside the My Account address edit form, reading the edited address from its parentEditblock so the saved type is pre-selected. Self-gates onConfig::isEnabled().Plugin/Checkout/PersistUserTypePlugin: after-plugin on the base Hyvä billing and shipping save services. Writesuser_type/referenceonto the quote address (Hyvä's core save only writes fields with a real setter, so these would otherwise be dropped), clears the business fields when Private is chosen, and mirrors them onto billing when "same as billing" is set.Plugin/Customer/ClearUserTypeFieldsPlugin: abeforeSaveplugin onAddressRepositoryInterface. Clears the business fields for a Private save. Gated onisEnabled()and the presence of the submitteduser_typerequest param, so it never touches address saves from unrelated flows.Plugin/Quote/ToOrderAddressPlugin: copiesuser_type/referencefrom the quote address onto the converted order address as a backup when the feature is enabled; leaves the conversion untouched when disabled.Plugin/TaxCalculationPlugin: an around-plugin onMagento\Tax\Model\Calculation::getRateand an after-plugin ongetAppliedRatesthat zero the tax rate (and clear the applied rates) for a VAT-registered Business quote when Apply Taxes To Legal Customers is No. Reads the checkout-session quote, falling back to the admin quote session for orders placed from the admin.
The module registers itself for the Hyvä config generation via Observer/RegisterModuleForHyvaConfig (etc/frontend/events.xml) so its CSS/JS is not purged from the Tailwind build.
Troubleshooting
The Switcher Does Not Appear
- Confirm the module is enabled at
Stores → Configuration → Magebit → User Type Switcher → Enable User Type Switcher(magebit_user_type_switcher/general/enabled). It defaults to No and the module is fully inert while off. - Ensure the module is installed and active:
d/magento module:status Magebit_VentaUserTypeSwitcher
- Verify the theme in use is Venta Theme (or a child) on top of Hyva, with Hyvä Checkout installed.
- Clear caches and re-deploy static content if templates or configuration were recently changed.
Tax Is Not Removed for Business Customers
- Confirm Apply Taxes To Legal Customers is set to No at
Stores → Configuration → Sales → Tax → Calculation Settings(tax/calculation/apply_legal_person_tax). - Tax is only removed when the customer is Business and a VAT ID is present on the billing or shipping address. Check both were captured.
- Confirm the module is enabled for the relevant store scope.
Business Fields Are Missing After Save
- The business fields (
company,vat_id,reference) are intentionally cleared when the user type is Private. Confirm the saved type is Business. - On the customer address save, the clearing only runs when the submitted
user_typerequest param is present; a save from an unrelated flow will not carry it. - Verify the address save is going through the Hyvä billing/shipping save service (checkout) or
AddressRepositoryInterface(My Account) so the module's plugins run.