// ========================================
// ICA CLUB FOOTER ENTEGRASYON KODU
// Bu dosyanın tüm içeriğini Ticimax Footer HTML'e ekleyin
// ========================================
// 1. SEPET VE CHECKOUT SAYFALARI İÇİN ÜYE KONTROLÜ
(function() {
var path = window.location.pathname.toLowerCase();
// Club sepetten geliyorsak yönlendirme yapma
var clubSepettenMi = sessionStorage.getItem('fromClubSepet');
if (clubSepettenMi === 'true') {
sessionStorage.removeItem('fromClubSepet');
console.log('Club sepetten gelindi, yönlendirme yapılmıyor');
return;
}
// Sadece sepet sayfasındaysak yönlendir (checkout'ta yönlendirme YAPMA)
if ((path.includes('sepet') || path.includes('cart')) &&
!path.includes('checkout') &&
!path.includes('odeme') &&
!path.includes('club-sepet')) {
// Üye kontrolü
if (document.cookie.indexOf('Ticimax_Member_Data=') > -1) {
window.location.replace('/club-sepet');
}
}
})();
// 2. ÜRÜN YAKALAMA - SEPETE EKLE BUTONU İÇİN
(function() {
// Tüm click eventlerini dinle
document.addEventListener('click', function(e) {
// Tıklanan element veya parent'larını kontrol et
let clickedElement = e.target;
let found = false;
// Parent'lara doğru çık ve sepete ekle butonu mu diye kontrol et
for (let i = 0; i < 5; i++) {
if (!clickedElement) break;
// Class kontrolü
const classList = clickedElement.className || '';
const value = clickedElement.value || '';
// Sepete ekle butonu mu?
if (classList.includes('btnAddBasketOnDetail') ||
classList.includes('Addtobasket') ||
value === 'Sepete Ekle') {
found = true;
break;
}
clickedElement = clickedElement.parentElement;
}
if (found) {
console.log('✅ Sepete ekle butonu tıklandı!');
// Ürün bilgilerini topla
setTimeout(function() {
const urun = {};
// Ürün Adı
const h1Element = document.querySelector('.ProductName h1 span');
urun.ad = h1Element ? h1Element.textContent.trim() : 'Ürün';
console.log('Ürün adı:', urun.ad);
// Fiyat (İndirimli fiyat varsa onu al, yoksa normal fiyat)
let fiyatElement = document.querySelector('.indirimliFiyat .spanFiyat');
if (!fiyatElement) {
fiyatElement = document.querySelector('#fiyat .spanFiyat');
}
urun.fiyat = fiyatElement ? fiyatElement.textContent.trim() : '0';
console.log('Fiyat:', urun.fiyat);
// Resim - Aktif olan thumbnail'i bul
let resimElement = document.querySelector('.owl-item.active img');
if (!resimElement) {
resimElement = document.querySelector('.thumb-item img');
}
if (!resimElement) {
resimElement = document.querySelector('.ProductGallery img');
}
urun.resim = resimElement ? resimElement.src : '';
console.log('Resim:', urun.resim);
// Ürün Kodu
const kodElement = document.querySelector('.productcode');
if (kodElement) {
const kodText = kodElement.textContent;
// Parantez içindeki kodu al
const kodMatch = kodText.match(/\((.*?)\)/);
urun.kod = kodMatch ? kodMatch[1] : kodText.trim();
} else {
urun.kod = 'URUN-' + Date.now();
}
console.log('Ürün kodu:', urun.kod);
// Adet
const adetInput = document.getElementById('txtbxurunSiparisAdedi');
urun.adet = adetInput ? adetInput.value : '1';
console.log('Adet:', urun.adet);
// Mevcut sepeti al
let sepet = JSON.parse(sessionStorage.getItem('clubSepet') || '[]');
// Aynı ürün var mı kontrol et
const mevcutUrunIndex = sepet.findIndex(item => item.kod === urun.kod);
if (mevcutUrunIndex > -1) {
// Varsa adeti artır
sepet[mevcutUrunIndex].adet = String(parseInt(sepet[mevcutUrunIndex].adet) + parseInt(urun.adet));
console.log('✓ Ürün adedi güncellendi:', urun.ad);
} else {
// Yoksa yeni ürün ekle
sepet.push(urun);
console.log('✓ Yeni ürün eklendi:', urun.ad);
}
sessionStorage.setItem('clubSepet', JSON.stringify(sepet));
console.log('Sepette toplam', sepet.length, 'farklı ürün var');
console.log('Sepet içeriği:', sepet);
// Başarı mesajı göster
showSuccessMessage(urun.ad);
// Üye ise 2 saniye sonra club sepete yönlendir
if (document.cookie.indexOf('Ticimax_Member_Data=') > -1) {
setTimeout(function() {
window.location.href = '/club-sepet';
}, 2000);
}
}, 500);
}
}, true);
// Başarı mesajı göster
function showSuccessMessage(urunAdi) {
// Mevcut bildirimi kaldır
const existing = document.querySelector('.club-sepet-notification');
if (existing) existing.remove();
const notification = document.createElement('div');
notification.className = 'club-sepet-notification';
notification.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
background: #10b981;
color: white;
padding: 20px;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
z-index: 10000;
max-width: 350px;
animation: slideUp 0.5s ease-out;
`;
notification.innerHTML = `
✅
Ürün Club Sepete Eklendi!
${urunAdi}
Club sepete yönlendiriliyorsunuz...
`;
// Animasyon CSS
if (!document.querySelector('#club-sepet-animations')) {
const style = document.createElement('style');
style.id = 'club-sepet-animations';
style.textContent = `
@keyframes slideUp {
from {
transform: translateY(100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
`;
document.head.appendChild(style);
}
document.body.appendChild(notification);
// 5 saniye sonra kaldır
setTimeout(() => {
notification.style.animation = 'slideUp 0.5s ease-out reverse';
setTimeout(() => {
notification.remove();
}, 500);
}, 5000);
}
})();
// 3. ÖDEME SAYFASINDA CLUB BİLGİLERİNİ GÖSTER VE PUAN İNDİRİMİ UYGULA
(function() {
// Sadece ödeme sayfasında çalış
if (!window.location.pathname.includes('odeme') && !window.location.pathname.includes('checkout')) {
return;
}
// Club verilerini oku
const clubData = sessionStorage.getItem('clubCheckoutData');
if (!clubData) return;
try {
const data = JSON.parse(clubData);
console.log('Club verileri yüklendi:', data);
// Bilgilendirme kutusu ekle
const bilgiKutusu = document.createElement('div');
bilgiKutusu.style.cssText = 'background: #FEF3C7; border: 2px solid #F59E0B; padding: 15px; margin: 20px auto; max-width: 600px; border-radius: 8px; text-align: center;';
bilgiKutusu.innerHTML = `
🏆 ${data.uyeTuru} Avantajlarınız
Club İndirimi: ${data.clubIndirimi}
${data.kullanilacakPuan > 0 ? `Kullanılan Puan: ${data.kullanilacakPuan} TL
` : ''}
Ödenecek Tutar: ${data.odenecekTutar}
`;
// Sayfanın başına ekle
const container = document.querySelector('.container, .content, main, body');
if (container) {
container.insertBefore(bilgiKutusu, container.firstChild);
}
// PUAN İNDİRİMİ UYGULAMA
const puanBilgisi = sessionStorage.getItem('puanIndirimBilgisi');
if (puanBilgisi) {
const puan = JSON.parse(puanBilgisi);
console.log('Puan indirimi uygulanacak:', puan);
// Puan indirim scriptini yükle
const script = document.createElement('script');
script.src = '/uye-odeme/puan-indirim-uygula.js';
script.onload = function() {
console.log('Puan indirim scripti yüklendi');
};
document.head.appendChild(script);
}
} catch (e) {
console.error('Club verisi okunamadı:', e);
}
})();
// 4. DEBUG FONKSİYONLARI (Geliştirme için)
window.clubDebug = {
// Sepeti göster
showCart: function() {
const sepet = JSON.parse(sessionStorage.getItem('clubSepet') || '[]');
console.table(sepet);
return sepet;
},
// Sepeti temizle
clearCart: function() {
sessionStorage.removeItem('clubSepet');
sessionStorage.removeItem('clubCheckoutData');
sessionStorage.removeItem('puanIndirimBilgisi');
console.log('✓ Sepet temizlendi');
},
// Club verilerini göster
showCheckoutData: function() {
const data = JSON.parse(sessionStorage.getItem('clubCheckoutData') || '{}');
console.log('Checkout verileri:', data);
return data;
},
// Test için ürün ekle
testAddProduct: function() {
const testUrun = {
ad: "Test Ürün",
kod: "TEST-" + Date.now(),
fiyat: "1000 ₺",
resim: "https://via.placeholder.com/100",
adet: "1"
};
let sepet = JSON.parse(sessionStorage.getItem('clubSepet') || '[]');
sepet.push(testUrun);
sessionStorage.setItem('clubSepet', JSON.stringify(sepet));
console.log('✓ Test ürün eklendi');
return testUrun;
}
};