178 lines
11 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- 1. Global Order Total Display -->
<template id="chennora_total_uber_display" inherit_id="website_sale.total" name="Chennora Total Uber Display">
<xpath expr="//tr[@id='order_total_untaxed']" position="after">
<t t-set="uber_line" t-value="website_sale_order.order_line.filtered(lambda l: l.product_id.name == 'Uber Delivery Fee')"/>
<tr t-if="uber_line" id="uber_delivery_row">
<td class="border-0 pb-2 ps-0 pt-0 text-start text-muted" colspan="2">Uber Delivery Fee</td>
<td class="text-end border-0 pb-2 pe-0 pt-0">
<span t-field="uber_line[0].price_subtotal" t-options='{"widget": "monetary", "display_currency": website_sale_order.currency_id}' class="monetary_field"/>
</td>
</tr>
</xpath>
</template>
<!-- 2. Hide Uber fee from cart summary -->
<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">
<attribute name="t-if">line.product_id.name != 'Uber Delivery Fee'</attribute>
</xpath>
</template>
<!-- 3. MAIN FORM: Optimized Pickup/Delivery Layout -->
<template id="chennora_address_unified" inherit_id="website_sale.address" name="Chennora Address Unified" priority="99">
<!-- Hide the 'Billing address' title -->
<xpath expr="//div[contains(@class, 'oe_cart')]//*[self::h2 or self::h3][1]" position="attributes">
<attribute name="class" add="d-none" separator=" "/>
</xpath>
<!-- NEW: Hide the yellow 'Be aware' alert box -->
<xpath expr="//div[hasclass('alert-warning')][contains(., 'billing and shipping')]" position="attributes">
<attribute name="class" add="d-none" separator=" "/>
<attribute name="style">display: none !important;</attribute>
</xpath>
<!-- Inject Selection Cards -->
<xpath expr="//form" position="before">
<style>
.order-type-card { border: 2px solid #eee; border-radius: 12px; cursor: pointer; transition: all 0.3s ease; padding: 20px; text-align: center; height: 100%; position: relative; overflow: hidden; }
.order-type-card.active { border-color: #00A67E; background-color: #f0fffb; box-shadow: 0 4px 15px rgba(0,166,126,0.1); }
.order-type-card i { font-size: 2rem; margin-bottom: 10px; color: #666; }
.order-type-card.active i { color: #00A67E; }
.order-type-card h5 { margin-bottom: 5px; font-weight: bold; }
.order-type-card p { font-size: 0.85rem; color: #888; margin: 0; }
.active-mark { display: none; position: absolute; top: 10px; right: 10px; color: #00A67E; }
.order-type-card.active .active-mark { display: block; }
.section-header { font-weight: bold; margin: 30px 0 15px 0; padding-bottom: 8px; border-bottom: 2px solid #f8f9fa; font-size: 1.1rem; }
</style>
<div class="row mb-4 g-3 mt-1">
<div class="col-6">
<div id="card_delivery" class="order-type-card active" onclick="setOrderType('delivery')">
<i class="active-mark fa fa-check-circle"></i>
<i class="fa fa-truck"></i>
<h5>Delivery</h5>
<p>Deliver to my address</p>
</div>
</div>
<div class="col-6">
<div id="card_pickup" class="order-type-card" onclick="setOrderType('pickup')">
<i class="active-mark fa fa-check-circle"></i>
<i class="fa fa-shopping-basket"></i>
<h5>Store Pickup</h5>
<p>Pick up at the restaurant</p>
</div>
</div>
</div>
<input type="hidden" name="fulfilment_type" id="hidden_fulfilment_type" value="delivery"/>
<div class="section-header"><i class="fa fa-clock-o me-2"></i>Preferred Greeting / Timing</div>
<div class="mb-4">
<input type="datetime-local" name="delivery_time" id="delivery_time_input" class="form-control form-control-lg border-0 bg-light" required="required"/>
</div>
<div id="uber_message" class="alert d-none my-3" role="alert"></div>
<div id="contact_info_header" class="section-header mt-4"><i class="fa fa-user me-2"></i>Contact Details</div>
</xpath>
<!-- Hide the 'Ship to same address' section -->
<xpath expr="//label[contains(., 'Ship to the same address')]/ancestor::div[1]" position="attributes">
<attribute name="style">display: none !important;</attribute>
<attribute name="class" add="d-none" separator=" "/>
</xpath>
<!-- Use JS for more reliable UI management -->
<xpath expr="//form" position="after">
<script type="text/javascript">
(function() {
function initUnifiedForm() {
const hiddenType = document.getElementById('hidden_fulfilment_type');
const msgDiv = document.getElementById('uber_message');
const submitBtn = document.querySelector('button[type="submit"]') || document.querySelector('.btn-primary');
function getAddressContainers() {
const addressNames = ['street', 'street2', 'city', 'zip', 'country_id', 'state_id'];
let containers = [];
addressNames.forEach(name => {
const input = document.querySelector(`[name="${name}"]`);
if (input) {
const container = input.closest('div[class*="col-"]') || input.closest('.mb-3') || input.closest('.mb-4');
if (container) containers.push(container);
}
});
return [...new Set(containers)];
}
let addrHeader = document.getElementById('dynamic_address_header');
if (!addrHeader &amp;&amp; document.querySelector('[name="street"]')) {
addrHeader = document.createElement('div');
addrHeader.id = 'dynamic_address_header';
addrHeader.className = 'section-header';
addrHeader.innerHTML = '<i class="fa fa-map-marker me-2"></i>Delivery Address';
const streetInput = document.querySelector('[name="street"]');
const streetContainer = streetInput.closest('div[class*="col-"]') || streetInput.parentNode;
streetContainer.parentNode.insertBefore(addrHeader, streetContainer);
}
window.setOrderType = function(type) {
hiddenType.value = type;
document.getElementById('card_delivery').classList.toggle('active', type === 'delivery');
document.getElementById('card_pickup').classList.toggle('active', type === 'pickup');
const containers = getAddressContainers();
if (type === 'pickup') {
containers.forEach(c => c.style.display = 'none');
if (addrHeader) addrHeader.style.display = 'none';
if (msgDiv) msgDiv.style.display = 'none';
if (submitBtn) submitBtn.disabled = false;
} else {
containers.forEach(c => c.style.display = '');
if (addrHeader) addrHeader.style.display = '';
if (msgDiv) msgDiv.style.display = '';
checkUber();
}
};
function checkUber() {
if (hiddenType.value !== 'delivery') return;
const street = document.querySelector('input[name="street"]')?.value;
const zip = document.querySelector('input[name="zip"]')?.value;
if (!street || !zip) return;
fetch('/shop/uber/quote', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ params: { address_data: {
street: street,
city: document.querySelector('input[name="city"]')?.value,
zip: zip,
country: document.querySelector('select[name="country_id"] option:checked')?.text || 'Canada'
} } })
}).then(r => r.json()).then(data => {
if (data.result &amp;&amp; data.result.success) {
msgDiv.className = 'alert alert-success my-3';
msgDiv.style.display = '';
msgDiv.innerText = "✓ Covered! Delivery charge: " + data.result.fee + "$";
if (submitBtn) submitBtn.disabled = false;
} else {
msgDiv.className = 'alert alert-danger my-3';
msgDiv.style.display = '';
msgDiv.innerText = "✕ Not covered: " + (data.result?.error || "Distance too far.");
if (submitBtn) submitBtn.disabled = true;
}
});
}
const triggers = document.querySelectorAll('input[name="street"], input[name="zip"]');
triggers.forEach(t => t.addEventListener('blur', checkUber));
setOrderType('delivery');
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initUnifiedForm); else initUnifiedForm();
})();
</script>
</xpath>
</template>
</odoo>