| 1 |
import { _t } from '@web/core/l10n/translation'; |
| 2 |
import { patch } from '@web/core/utils/patch'; |
| 3 |
import { patchDynamicContent } from '@web/public/utils'; |
| 4 |
import { rpc } from '@web/core/network/rpc'; |
| 5 |
import { Checkout } from '@website_sale/interactions/checkout'; |
| 6 |
|
| 7 |
patch(Checkout.prototype, { |
| 8 |
setup() { |
| 9 |
super.setup(); |
| 10 |
patchDynamicContent(this.dynamicContent, { |
| 11 |
'.js_wsc_update_product_qty': { 't-on-click': this.onClickUpdateProductQty.bind(this) }, |
| 12 |
}); |
| 13 |
this.deliveryAddressTitle = this.el.querySelector('[name="delivery_address_title"]'); |
| 14 |
if (this.deliveryAddressTitle) { |
| 15 |
this.deliveryTitle = this.deliveryAddressTitle.textContent; |
| 16 |
this.useDeliveryAsBillingLabel = this.el.querySelector( |
| 17 |
'[name="use_delivery_as_billing_text"]' |
| 18 |
); |
| 19 |
this.useDeliveryAsBillingLabelText = this.useDeliveryAsBillingLabel.textContent; |
| 20 |
this.inStoreTitle = _t('Contact Details'); |
| 21 |
this.useDeliveryAsBillingLabelInStoreText = _t('Same as contact details'); |
| 22 |
this._adaptDeliveryTitles(); |
| 23 |
} |
| 24 |
}, |
| 25 |
|
| 26 |
async selectDeliveryMethod(ev) { |
| 27 |
this._adaptDeliveryTitles(); |
| 28 |
await super.selectDeliveryMethod(...arguments); |
| 29 |
}, |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
async onClickUpdateProductQty(ev) { |
| 37 |
await this.waitFor(rpc('/shop/cart/update', { |
| 38 |
line_id: parseInt(ev.currentTarget.dataset.lineId, 10), |
| 39 |
product_id: parseInt(ev.currentTarget.dataset.productId, 10), |
| 40 |
quantity: parseInt(ev.currentTarget.dataset.availableQty || 0, 10), |
| 41 |
})); |
| 42 |
window.location.reload(); |
| 43 |
}, |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
_adaptDeliveryTitles() { |
| 55 |
const checkedRadio = document.querySelector('input[name="o_delivery_radio"]:checked'); |
| 56 |
if (!checkedRadio || !this.deliveryAddressTitle || !this.useDeliveryAsBillingLabel) { |
| 57 |
return; |
| 58 |
} |
| 59 |
if (checkedRadio.dataset.deliveryType === 'in_store') { |
| 60 |
this.deliveryAddressTitle.textContent = this.inStoreTitle; |
| 61 |
this.useDeliveryAsBillingLabel.textContent = this.useDeliveryAsBillingLabelInStoreText; |
| 62 |
} else { |
| 63 |
this.deliveryAddressTitle.textContent = this.deliveryTitle; |
| 64 |
this.useDeliveryAsBillingLabel.textContent = this.useDeliveryAsBillingLabelText; |
| 65 |
} |
| 66 |
}, |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
_updatePickupLocation(button, location, jsonLocation) { |
| 74 |
super._updatePickupLocation(...arguments); |
| 75 |
const dmContainer = this._getDeliveryMethodContainer(button); |
| 76 |
const radio = dmContainer.querySelector('[name="o_delivery_radio"]'); |
| 77 |
if (radio.dataset.deliveryType === 'in_store') { |
| 78 |
dmContainer.querySelector('[name="unavailable_products_warning"]')?.remove(); |
| 79 |
} |
| 80 |
}, |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
_isDeliveryMethodReady() { |
| 89 |
if (this.dmRadios.length === 0) { |
| 90 |
return super._isDeliveryMethodReady(...arguments); |
| 91 |
} |
| 92 |
const checkedRadio = this.el.querySelector('input[name="o_delivery_radio"]:checked'); |
| 93 |
let hasWarning = false; |
| 94 |
if (checkedRadio) { |
| 95 |
const deliveryContainer = this._getDeliveryMethodContainer(checkedRadio); |
| 96 |
hasWarning = ( |
| 97 |
checkedRadio.dataset.deliveryType === 'in_store' |
| 98 |
&& deliveryContainer.querySelector('[name="unavailable_products_warning"]') |
| 99 |
); |
| 100 |
} |
| 101 |
return super._isDeliveryMethodReady(...arguments) && !hasWarning; |
| 102 |
}, |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
_hidePickupLocation() { |
| 110 |
super._hidePickupLocation(...arguments); |
| 111 |
const warning = this.el.querySelector('[name="unavailable_products_warning"]'); |
| 112 |
if (warning) { |
| 113 |
warning.classList.add('d-none'); |
| 114 |
} |
| 115 |
}, |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
async _showPickupLocation(radio) { |
| 125 |
super._showPickupLocation(...arguments); |
| 126 |
if (radio.dataset.deliveryType === 'in_store') { |
| 127 |
const dmContainer = this._getDeliveryMethodContainer(radio); |
| 128 |
const warning = dmContainer.querySelector('[name="unavailable_products_warning"]'); |
| 129 |
if (warning) { |
| 130 |
warning.classList.remove('d-none'); |
| 131 |
} |
| 132 |
} |
| 133 |
}, |
| 134 |
}); |