Problem/Motivation
Yesterday we invested several hours in
✨
Allow control over "billing same as shipping" default
Needs review
try to implement a setting for the "My billing information is the same as my shipping information." checkbox.
The reason, why we did that was, that it was always unchecked by default in our case.
We had PayPal (without separate billing / shipping addresses) as first payment method and Bank transfer as second one (with separate billing / shipping).
The thing we didn't see early enough, is this nasty bug affecting the checkbox state of the corresponding checkbox in checkout:
$inline_form['copy_fields']['enable'] = [
'#type' => 'checkbox',
'#title' => $this->getCopyLabel($inline_form),
'#default_value' => $enabled,
'#ajax' => [
'callback' => [get_class($this), 'ajaxRefresh'],
'wrapper' => $inline_form['#id'],
],
];
(src/ProfileFieldCopy.php)
The checkbox works totally fine and as expected, representing the corrent $enabled
default, if not loaded through AJAX. That's the case, if the affected payment method is the 1st one and loaded with the page, without AJAX.
If the payment method is loaded through AJAX (>1 payment methods), the checkbox should still have $enabled
checked, but hasn't and is loaded unchecked!
This is tricky to find, and of course the behaviour should be consistent for end-users which are otherwise affected by unexpected / bad for the ajax-loaded payment methods.
I'm unsure about the root cause and wasn't able to fix it.
Possible causes:
Steps to reproduce
See above
Proposed resolution
Fix the bug so that the checkbox state is represented correctly through AJAX and initial load.
Remaining tasks
- Investigate the root cause
- Implement a test with >1 payment method and AJAX switching of the payment method
- Fix the issue
- Release fix and test
User interface changes
None
API changes
None
Data model changes
None