Votre panier est vide.
Commencer mes achatsيرجى الضغط على الزر الأخضر أدناه لتأكيد طلبك وتفاصيل التوصيل مباشرة عبر الواتساب لتسريع عملية الشحن.
تأكيد الطلب عبر واتسابلقد تلقينا طلبك بنجاح. سيتصل بك فريق الدعم الفني قريباً لتأكيد طلبك وبدء عملية الشحن والتوصيل window.checkoutSubtotal = 0; window.checkoutShipping = 0; window.checkoutDeposit = 0; const dbShippingCost = 35; const dbHeavyShippingCost = 80; const wholesaleDepositPercent = 20 / 100; const cartItemsDetails = [ ]; function clearCartAndGoHome() { const formData = new FormData(); formData.append('action', 'clear'); formData.append('is_ajax', '1'); fetch('cart_action.php', { method: 'POST', body: formData }) .then(() => { window.location.href = 'index.php'; }) .catch(() => { window.location.href = 'index.php'; }); } function openCheckout() { const modal = document.getElementById('checkoutModal'); const displayEl = document.getElementById('final_total_display'); if(displayEl) displayEl.innerText = (window.checkoutSubtotal + window.checkoutShipping).toFixed(2); const subtotalEl = document.getElementById('modal_subtotal_display'); if(subtotalEl) subtotalEl.innerText = window.checkoutSubtotal.toFixed(2); const shippingEl = document.getElementById('modal_shipping_display'); if(shippingEl) shippingEl.innerText = window.checkoutShipping > 0 ? window.checkoutShipping.toFixed(2) + ' DH' : 'Gratuite'; const depositEl = document.getElementById('modal_deposit_display'); if(depositEl) depositEl.innerText = window.checkoutDeposit.toFixed(2) + ' DH'; const codEl = document.getElementById('modal_cod_display'); if(codEl) codEl.innerText = ((window.checkoutSubtotal + window.checkoutShipping) - window.checkoutDeposit).toFixed(2) + ' DH'; modal.style.display = 'flex'; void modal.offsetWidth; // Trigger reflow modal.style.opacity = '1'; modal.firstElementChild.style.transform = 'translateY(0)'; } function closeModal() { const modal = document.getElementById('checkoutModal'); modal.style.opacity = '0'; modal.firstElementChild.style.transform = 'translateY(20px)'; setTimeout(() => { modal.style.display = 'none'; }, 300); } // Dynamic Coupon Validation function validateCoupon() { const code = document.getElementById('coupon_code').value; const msgDiv = document.getElementById('coupon_msg'); const totalDisplay = document.getElementById('final_total_display'); const subtotalDisplay = document.getElementById('modal_subtotal_display'); if(!code) return; msgDiv.innerHTML = 'Vérification...'; fetch('check_coupon.php', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ code: code, total: window.checkoutSubtotal }) }) .then(r => r.json()) .then(d => { if(d.success) { msgDiv.innerHTML = '' + d.message + ' (-' + d.discount_amount + ' DH)'; totalDisplay.innerText = (d.new_total + window.checkoutShipping).toFixed(2); totalDisplay.style.color = '#27ae60'; if(subtotalDisplay) subtotalDisplay.innerText = d.new_total.toFixed(2); const modalCodEl = document.getElementById('modal_cod_display'); if(modalCodEl) modalCodEl.innerText = ((d.new_total + window.checkoutShipping) - window.checkoutDeposit).toFixed(2) + ' DH'; } else { msgDiv.innerHTML = '' + d.message + ''; totalDisplay.innerText = (window.checkoutSubtotal + window.checkoutShipping).toFixed(2); // Reset totalDisplay.style.color = '#333'; if(subtotalDisplay) subtotalDisplay.innerText = window.checkoutSubtotal.toFixed(2); const modalCodEl = document.getElementById('modal_cod_display'); if(modalCodEl) modalCodEl.innerText = ((window.checkoutSubtotal + window.checkoutShipping) - window.checkoutDeposit).toFixed(2) + ' DH'; } }) .catch(e => { msgDiv.innerText = 'Error'; }); } function submitOrder(e) { e.preventDefault(); const name = document.getElementById('name').value; const phone = document.getElementById('phone').value; const city = document.getElementById('city').value; const address = document.getElementById('address').value; const coupon_code = document.getElementById('coupon_code').value; const submit_method = document.getElementById('submit_method').value; const submitBtns = e.target.querySelectorAll('button[type="submit"]'); submitBtns.forEach(btn => { btn.disabled = true; btn.style.opacity = '0.7'; }); fetch('place_order.php', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ name, phone, city, address, coupon_code, submit_method }) }) .then(response => response.json()) .then(data => { if (data.success) { closeModal(); const waConfirmArea = document.getElementById('waConfirmArea'); const standardSuccessArea = document.getElementById('standardSuccessArea'); if (data.whatsapp_url) { if (waConfirmArea) waConfirmArea.style.display = 'block'; if (standardSuccessArea) standardSuccessArea.style.display = 'none'; const waBtn = document.getElementById('whatsappConfirmBtn'); if (waBtn) waBtn.href = data.whatsapp_url; window.open(data.whatsapp_url, '_blank'); } else { if (waConfirmArea) waConfirmArea.style.display = 'none'; if (standardSuccessArea) standardSuccessArea.style.display = 'block'; } document.getElementById('thankYouModal').style.display = 'flex'; } else { alert('Erreur: ' + data.message); submitBtns.forEach(btn => { btn.disabled = false; btn.style.opacity = '1'; }); } }) .catch(error => { console.error('Error:', error); alert('Une erreur est survenue.'); submitBtns.forEach(btn => { btn.disabled = false; btn.style.opacity = '1'; }); }); } // Close modal if clicked outside window.onclick = function(event) { if (event.target == document.getElementById('checkoutModal')) { closeModal(); } } // --- SELECTION LOGIC --- function toggleAllItems(source) { const checkboxes = document.querySelectorAll('.cart-item-cb'); checkboxes.forEach(cb => cb.checked = source.checked); updateCartSelection(); } function updateCartSelection() { const checkboxes = document.querySelectorAll('.cart-item-cb'); const selectAllCb = document.getElementById('selectAllCb'); let total = 0; let count = 0; let allChecked = true; let hasPaidShipping = false; let hasBulky = false; let depositTotal = 0; checkboxes.forEach((cb, idx) => { if(cb.checked) { total += parseFloat(cb.dataset.price); count++; const itemInfo = cartItemsDetails[idx]; if (itemInfo) { if (!itemInfo.is_free) { hasPaidShipping = true; } if (itemInfo.is_bulky) { hasBulky = true; } let bulkyDep = itemInfo.is_bulky ? itemInfo.deposit_amount * itemInfo.qty : 0; let wholesaleDep = itemInfo.is_wholesale ? itemInfo.price * wholesaleDepositPercent : 0; depositTotal += Math.max(bulkyDep, wholesaleDep); } } else { allChecked = false; } }); if(selectAllCb) selectAllCb.checked = (checkboxes.length > 0 && allChecked); let activeShipping = 0; if (count > 0 && hasPaidShipping) { activeShipping = hasBulky ? dbHeavyShippingCost : dbShippingCost; } window.checkoutShipping = activeShipping; window.checkoutSubtotal = total; window.checkoutDeposit = depositTotal; // Update Total Displays const shippingEl = document.getElementById('summary-shipping-display'); if(shippingEl) shippingEl.innerText = window.checkoutShipping > 0 ? window.checkoutShipping + ' DH' : 'Gratuite'; const depositDisplayEl = document.getElementById('summary-deposit-display'); if(depositDisplayEl) depositDisplayEl.innerText = window.checkoutDeposit.toLocaleString('fr-FR') + ' DH'; const codDisplayEl = document.getElementById('summary-cod-display'); if(codDisplayEl) codDisplayEl.innerText = ((window.checkoutSubtotal + window.checkoutShipping) - window.checkoutDeposit).toLocaleString('fr-FR') + ' DH'; const totalEl = document.getElementById('summary-total-display'); if(totalEl) totalEl.innerText = (window.checkoutSubtotal + window.checkoutShipping).toLocaleString('fr-FR') + ' DH'; const modalTotalEl = document.getElementById('final_total_display'); if(modalTotalEl) modalTotalEl.innerText = (window.checkoutSubtotal + window.checkoutShipping).toFixed(2); const modalSubtotalEl = document.getElementById('modal_subtotal_display'); if(modalSubtotalEl) modalSubtotalEl.innerText = window.checkoutSubtotal.toFixed(2); const modalShippingEl = document.getElementById('modal_shipping_display'); if(modalShippingEl) modalShippingEl.innerText = window.checkoutShipping > 0 ? window.checkoutShipping.toFixed(2) + ' DH' : 'Gratuite'; const modalDepositEl = document.getElementById('modal_deposit_display'); if(modalDepositEl) modalDepositEl.innerText = window.checkoutDeposit.toFixed(2) + ' DH'; const modalCodEl = document.getElementById('modal_cod_display'); if(modalCodEl) modalCodEl.innerText = ((window.checkoutSubtotal + window.checkoutShipping) - window.checkoutDeposit).toFixed(2) + ' DH'; // Update Button Text const btn = document.getElementById('mainCheckoutBtn'); if(btn) { btn.innerText = `Commander (${count})`; } }
يرجى الضغط على الزر الأخضر أدناه لتأكيد طلبك وتفاصيل التوصيل مباشرة عبر الواتساب لتسريع عملية الشحن.
تأكيد الطلب عبر واتسابلقد تلقينا طلبك بنجاح. سيتصل بك فريق الدعم الفني قريباً لتأكيد طلبك وبدء عملية الشحن والتوصيل.