Fix: Resolving box now by instance, not by type. Also, fixing bug where missing shipping driver would break checkout
This commit is contained in:
@@ -123,7 +123,7 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
async selectShipping(event) {
|
||||
this.toggleBoxNowLocker(event.target.value)
|
||||
this.toggleBoxNowLocker(event.target.dataset.boxNow === 'true')
|
||||
|
||||
// Tracked so flush() can await it — nothing else stops "place order"
|
||||
// (a separate, unrelated click) from racing ahead of this request.
|
||||
@@ -136,15 +136,17 @@ export default class extends Controller {
|
||||
// re-renders wholesale on every shipping-option change — so its own
|
||||
// Stimulus controller reconnects fresh each time and has no memory of
|
||||
// which option was previously selected. This is the one place that
|
||||
// knows the newly-chosen option's identifier, so it also owns
|
||||
// showing/hiding the picker.
|
||||
toggleBoxNowLocker(identifier) {
|
||||
// knows the newly-chosen option, so it also owns showing/hiding the
|
||||
// picker. Whether an option is Box Now comes from the server
|
||||
// (data-box-now, by the method's driver) — the option's value is the
|
||||
// merchant-typed method code, which needn't be "box-now".
|
||||
toggleBoxNowLocker(isBoxNow) {
|
||||
const picker = this.shippingOptionsTarget.querySelector('#bbk-box-now-locker')
|
||||
if (!picker) return
|
||||
|
||||
const controller = this.application.getControllerForElementAndIdentifier(picker, 'bbk-box-now-locker')
|
||||
|
||||
if (identifier === 'box-now') {
|
||||
if (isBoxNow) {
|
||||
controller?.show()
|
||||
} else {
|
||||
controller?.hide()
|
||||
|
||||
Reference in New Issue
Block a user