feat: add simple checkout form template with auto-generated credentials#740
feat: add simple checkout form template with auto-generated credentials#740superdav42 wants to merge 2 commits intomainfrom
Conversation
Introduces a new 'simple' checkout form preset that requires only an email address from the customer. Username is derived from the email, password is generated server-side, site title from username, and site URL from site title — all via existing auto-generate mechanisms. Changes: - Signup_Field_Password: add auto_generate_password toggle; emits a hidden flag when enabled so no password field is rendered - Checkout: generate password via wp_generate_password() when the flag is present; skip password/password_conf/valid_password validation rules - Checkout_Form model: add 'simple' to template enum, use_template(), and save() step_types; add get_simple_template() private method - API schemas (create + update): add 'simple' to template enum
…e_password helper When a checkout form uses auto_generate_password, the password/password_conf/ valid_password fields are never rendered. Without this fix the client-side validator blocked submission because those rules were still present in the wu_checkout JS object. - Add form_has_auto_generate_password() helper that inspects the form's field config at render time - get_js_validation_rules() calls the helper and unsets the three password-related rule entries before serialising to JS
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR introduces a new "simple" checkout template mode and auto-generate password functionality. Schema definitions accept the new template value. A simple template builder creates pre-configured checkout forms with optional auto-generated passwords. The password field component adds auto_generate_password toggle that conditionally hides password inputs. Checkout class logic determines passwords via auto-generation when enabled and removes associated server/client validation constraints. Changes
Sequence DiagramsequenceDiagram
actor Admin
participant CheckoutForm
participant PasswordField
participant CheckoutClass
participant Customer
Admin->>CheckoutForm: Select 'simple' template
activate CheckoutForm
CheckoutForm->>CheckoutForm: use_template('simple')
CheckoutForm->>CheckoutForm: get_simple_template()
CheckoutForm->>PasswordField: Configure with auto_generate_password=true
deactivate CheckoutForm
Customer->>PasswordField: Submit checkout form
activate PasswordField
PasswordField->>PasswordField: to_fields_array() returns hidden input only
deactivate PasswordField
PasswordField->>CheckoutClass: Form submission received
activate CheckoutClass
CheckoutClass->>CheckoutClass: form_has_auto_generate_password() checks field config
CheckoutClass->>CheckoutClass: maybe_create_customer() with auto-generated password
CheckoutClass->>CheckoutClass: Validation rules bypass password constraints
deactivate CheckoutClass
CheckoutClass->>Customer: Create account with auto-generated password
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing — this PR has merge conflicts with the base branch. The linked issue (if any) remains open for a worker to re-attempt with a fresh branch. Closed by deterministic merge pass (pulse-wrapper.sh). |
…erated credentials (#747) * chore: add t524 simple checkout form feature to backlog (re-implement PR #740) * test(checkout): add unit tests for simple template and auto-generate password - Signup_Field_Password_Test: 6 new tests covering auto_generate_password defaults, get_fields toggle, to_fields_array hidden flag emission, v-show guards on strength meter and confirm field - Checkout_Form_Test: 11 new tests covering simple template validation, use_template() structure, field presence, auto-generate flags on username/password/site_title/site_url, filterable hook, and save path All 17 tests pass against the implementation already in main (PRs #737, #739, #742). Closes #746
Summary
simplecheckout form preset — a single-step form where the customer only needs to enter their email address. Username, password, site title, and site URL are all auto-generated server-side.auto_generate_passwordtoggle to the Password signup field, withwp_generate_password()generation and relaxed validation when enabled.Changes
inc/checkout/signup-fields/class-signup-field-password.phpauto_generate_passworddefault (off, fully backwards-compatible)get_fields()withv-showguards hiding the strength meter and confirm field when auto-generate is onto_fields_array()short-circuits to a singlehiddenfield (auto_generate_password=1) when enabled — no visible password input renderedinc/checkout/class-checkout.phpwp_generate_password(16)whenauto_generate_passwordis in the session/requestvalidation_rules(): password, password_conf, and valid_password rules are cleared whenauto_generate_passwordis setform_has_auto_generate_password()helper: inspects the form's field config at render timeget_js_validation_rules(): calls the helper and strips the three password-related rule entries before serialising to JS (prevents client-side validator blocking submission on a field that is never shown)inc/models/class-checkout-form.phpvalidation_rules(): addssimpleto thein:enumuse_template(): addselseif ('simple' === $template)branchsave(): addssimpleto$step_typesso the template is applied on saveget_simple_template(): single step — products (pre-selected), email (visible), username (auto from email), password (auto-generated), site_title (auto from username), site_url (auto from site_title), template_selection (hidden when pre-selected via URL), order_summary, payment, billing_address, submitinc/apis/schemas/checkout-form-create.php+checkout-form-update.phpsimpleto thetemplatefield enumTesting
Tested end-to-end against the local wp-env environment:
use_template('simple'){"success":true}signup_formrecorded on customerUsage
Or via REST API / WP-CLI with
"template": "simple".Summary by CodeRabbit