implement checkout fulfillment type selector and integrate Uber delivery fee logic, and update docker-compose service naming.
This commit is contained in:
parent
a280e64b04
commit
55abba227d
@ -13,100 +13,137 @@
|
|||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Hide Uber fee from cart summary items -->
|
|
||||||
<template id="chennora_cart_summary_uber_hide" inherit_id="website_sale.checkout_layout" name="Chennora Cart Summary Uber Hide">
|
<template id="chennora_cart_summary_uber_hide" inherit_id="website_sale.checkout_layout" name="Chennora Cart Summary Uber Hide">
|
||||||
<xpath expr="//table[@id='cart_products']//tr" position="attributes">
|
<xpath expr="//table[@id='cart_products']//tr" position="attributes">
|
||||||
<attribute name="t-if">line.product_id.name != 'Uber Delivery Fee'</attribute>
|
<attribute name="t-if">line.product_id.name != 'Uber Delivery Fee'</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Simplify Checkout: Show only Billing Address, Hide Shipping Address UI -->
|
<!-- Enhanced Checkout: Pickup vs Delivery Selector -->
|
||||||
<template id="chennora_checkout_custom" inherit_id="website_sale.checkout" name="Chennora Checkout Custom" priority="99">
|
<template id="chennora_checkout_custom" inherit_id="website_sale.checkout" name="Chennora Checkout Custom" priority="99">
|
||||||
<!-- 1. Hide the Shipping Address Block entirely by finding its header parent -->
|
<!-- 1. Add Order Type Selector (Pickup vs Delivery) -->
|
||||||
|
<xpath expr="//h3" position="before">
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-12 text-center">
|
||||||
|
<div class="btn-group btn-group-lg w-100" role="group" aria-label="Order Type Selector">
|
||||||
|
<input type="radio" class="btn-check" name="fulfilment_type" id="type_pickup" value="pickup"
|
||||||
|
t-att-checked="'checked' if order.fulfilment_type == 'pickup' else None"/>
|
||||||
|
<label class="btn btn-outline-primary py-3 fw-bold shadow-none" for="type_pickup" style="flex: 1;">🏃 STORE PICKUP</label>
|
||||||
|
|
||||||
|
<input type="radio" class="btn-check" name="fulfilment_type" id="type_delivery" value="delivery"
|
||||||
|
t-att-checked="'checked' if order.fulfilment_type == 'delivery' else None"/>
|
||||||
|
<label class="btn btn-outline-primary py-3 fw-bold shadow-none" for="type_delivery" style="flex: 1;">🚗 UBER DELIVERY</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
|
||||||
|
<!-- UI cleanup from previous steps -->
|
||||||
<xpath expr="//h4[contains(., 'Shipping')]/ancestor::div[1]" position="attributes">
|
<xpath expr="//h4[contains(., 'Shipping')]/ancestor::div[1]" position="attributes">
|
||||||
<attribute name="style">display: none !important;</attribute>
|
<attribute name="style">display: none !important;</attribute>
|
||||||
<attribute name="class" add="d-none" separator=" "/>
|
<attribute name="class" add="d-none" separator=" "/>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
||||||
<!-- 2. Make the Billing Address section full-width since Shipping is hidden -->
|
|
||||||
<xpath expr="//h4[contains(., 'Billing')]/ancestor::div[1]" position="attributes">
|
<xpath expr="//h4[contains(., 'Billing')]/ancestor::div[1]" position="attributes">
|
||||||
<attribute name="class" add="col-12" remove="col-md-6" separator=" "/>
|
<attribute name="class" add="col-12" remove="col-md-6" separator=" "/>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
||||||
<!-- 3. Rename Billing to 'Delivery Address' -->
|
|
||||||
<xpath expr="//h4[contains(., 'Billing')]" position="replace">
|
<xpath expr="//h4[contains(., 'Billing')]" position="replace">
|
||||||
<h3 class="mb-4">Delivery Address</h3>
|
<h3 class="mb-4">Delivery Address</h3>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
||||||
<!-- Script for Uber Quote -->
|
<!-- Combined Script for Pickup/Delivery Toggle and Uber Quote -->
|
||||||
<xpath expr="//h3" position="after">
|
<xpath expr="//h3" position="after">
|
||||||
<div id="uber_error" class="alert alert-danger d-none my-3" role="alert"></div>
|
<div id="uber_error" class="alert alert-danger d-none my-3" role="alert"></div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
(function() {
|
(function() {
|
||||||
function initUberQuote() {
|
function initFulfilmentLogic() {
|
||||||
const btn = document.querySelector('a[name="website_sale_main_button"]') ||
|
const btn = document.querySelector('a[name="website_sale_main_button"]') ||
|
||||||
document.querySelector('.oe_cart .btn-primary') ||
|
document.querySelector('.oe_cart .btn-primary') ||
|
||||||
document.querySelector('.btn-primary[href*="/payment"]');
|
document.querySelector('.btn-primary[href*="/payment"]');
|
||||||
const errorDiv = document.getElementById('uber_error');
|
const errorDiv = document.getElementById('uber_error');
|
||||||
|
const pickupRadio = document.getElementById('type_pickup');
|
||||||
|
const deliveryRadio = document.getElementById('type_delivery');
|
||||||
|
|
||||||
if (!btn) {
|
if (!btn || !pickupRadio || !deliveryRadio) {
|
||||||
setTimeout(initUberQuote, 500);
|
setTimeout(initFulfilmentLogic, 500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const disableButton = () => {
|
const updateButton = (state, text = null) => {
|
||||||
btn.classList.add('disabled', 'btn-secondary');
|
if (state === 'disabled') {
|
||||||
btn.classList.remove('btn-primary');
|
btn.classList.add('disabled', 'btn-secondary');
|
||||||
btn.style.pointerEvents = 'none';
|
btn.classList.remove('btn-primary');
|
||||||
};
|
btn.style.pointerEvents = 'none';
|
||||||
const enableButton = () => {
|
} else {
|
||||||
btn.classList.remove('disabled', 'btn-secondary');
|
btn.classList.remove('disabled', 'btn-secondary');
|
||||||
btn.classList.add('btn-primary');
|
btn.classList.add('btn-primary');
|
||||||
btn.style.pointerEvents = 'auto';
|
btn.style.pointerEvents = 'auto';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fulfilmentType = "<t t-esc='order.fulfilment_type'/>";
|
const runUberQuote = () => {
|
||||||
if (fulfilmentType !== "delivery") {
|
const addressData = {
|
||||||
enableButton();
|
street: "<t t-esc='order.partner_invoice_id.street'/>",
|
||||||
return;
|
city: "<t t-esc='order.partner_invoice_id.city'/>",
|
||||||
}
|
zip: "<t t-esc='order.partner_invoice_id.zip'/>",
|
||||||
|
country: "<t t-esc='order.partner_invoice_id.country_id.name'/>"
|
||||||
|
};
|
||||||
|
|
||||||
disableButton();
|
if (!addressData.street || !addressData.zip) {
|
||||||
|
updateButton('enabled'); // Fallback if no addr
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const addressData = {
|
|
||||||
street: "<t t-esc='order.partner_invoice_id.street'/>",
|
|
||||||
city: "<t t-esc='order.partner_invoice_id.city'/>",
|
|
||||||
zip: "<t t-esc='order.partner_invoice_id.zip'/>",
|
|
||||||
country: "<t t-esc='order.partner_invoice_id.country_id.name'/>"
|
|
||||||
};
|
|
||||||
|
|
||||||
if (addressData.street && addressData.zip) {
|
|
||||||
fetch('/shop/uber/quote', {
|
fetch('/shop/uber/quote', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({ params: { address_data: addressData } })
|
body: JSON.stringify({ params: { address_data: addressData } })
|
||||||
}).then(r => r.json()).then(data => {
|
}).then(r => r.json()).then(data => {
|
||||||
if (data.result && data.result.success) {
|
if (data.result && data.result.success) {
|
||||||
enableButton();
|
updateButton('enabled');
|
||||||
if (errorDiv) errorDiv.classList.add('d-none');
|
if (errorDiv) errorDiv.classList.add('d-none');
|
||||||
const hasFee = "<t t-esc="any(l.product_id.name == 'Uber Delivery Fee' for l in website_sale_order.order_line) and 'true' or 'false'"/>" === "true";
|
const hasFee = "<t t-esc="any(l.product_id.name == 'Uber Delivery Fee' for l in website_sale_order.order_line) and 'true' or 'false'"/>" === "true";
|
||||||
if (!hasFee && window.location.search.indexOf('quoted=1') === -1) {
|
if (!hasFee && window.location.search.indexOf('quoted=1') === -1) {
|
||||||
window.location.href = window.location.pathname + '?quoted=1';
|
window.location.href = window.location.pathname + '?quoted=1';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
disableButton();
|
updateButton('disabled');
|
||||||
if (errorDiv) {
|
if (errorDiv) {
|
||||||
errorDiv.innerText = (data.result && data.result.error) ? data.result.error : "Uber delivery not available.";
|
errorDiv.innerText = (data.result && data.result.error) ? data.result.error : "Uber delivery not available.";
|
||||||
errorDiv.classList.remove('d-none');
|
errorDiv.classList.remove('d-none');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
|
||||||
console.error("Uber error", err);
|
|
||||||
enableButton();
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToggle = (type) => {
|
||||||
|
// Update server state via anonymous JSON-RPC call
|
||||||
|
fetch('/shop_online_details/update_details', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: JSON.stringify({ params: { fulfilment_type: type } })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (type === 'pickup') {
|
||||||
|
updateButton('enabled');
|
||||||
|
if (errorDiv) errorDiv.classList.add('d-none');
|
||||||
|
} else {
|
||||||
|
updateButton('disabled');
|
||||||
|
runUberQuote();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pickupRadio.addEventListener('change', () => handleToggle('pickup'));
|
||||||
|
deliveryRadio.addEventListener('change', () => handleToggle('delivery'));
|
||||||
|
|
||||||
|
// Initial Run
|
||||||
|
if (deliveryRadio.checked) {
|
||||||
|
updateButton('disabled');
|
||||||
|
runUberQuote();
|
||||||
|
} else {
|
||||||
|
updateButton('enabled');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initUberQuote); } else { initUberQuote(); }
|
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initFulfilmentLogic); } else { initFulfilmentLogic(); }
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user