-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdripcontent-eco-cms.js
220 lines (198 loc) · 10.5 KB
/
dripcontent-eco-cms.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*-- DÉBUT : Drip Content paiement en plusieurs fois combiné --*/
window.addEventListener('load', function() {
function calculateDaysLeft(startDate, daysToAdd) {
if (!startDate) {
console.error('La date de début est undefined.');
return 0; // Ou toute autre valeur par défaut que vous voulez retourner dans ce cas.
}
var futureDate = new Date(startDate.getTime());
futureDate.setDate(futureDate.getDate() + daysToAdd);
return Math.max(Math.floor((futureDate - new Date()) / (1000 * 60 * 60 * 24)), 0);
}
function checkMemberPlan() {
var userData = JSON.parse(localStorage.getItem('_ms-mem'));
console.log('User data:', userData);
if (userData && userData.metaData && userData.planConnections) {
var ecomPlanIds = [
"pln_formation-webflow-e-commerce-cms-3-fois--y110qun",
"pln_formation-webflow-e-commerce-cms-kb40awg"
];
var packPlanIds = [
"pln_webflow-le-pack-3-fois--sshd024y",
"pln_webflow-le-pack-ezhb0291"
];
var megaPackPlanIds = [
"pln_le-mega-pack-webflow-3-fois--tnkm02zj",
"pln_le-mega-pack-webflow-2ljs0t3b"
];
var specialPlanIds = [
"pln_formation-webflow-e-commerce-cms-kb40awg",
"pln_webflow-le-pack-ezhb0291",
"pln_le-mega-pack-webflow-2ljs0t3b",
"pln_formation-simple-trimestriel-7rj80985",
"pln_formation-simple-semestriel-tnh604fc",
"pln_formation-simple-annuel-gyh704ly",
"pln_formation-accompagn-e-trimestriel-fih804b7",
"pln_formation-accompagn-e-semestriel-7ij9096p",
"pln_formation-accompagn-e-annuel-b6ha045g",
"pln_formation-et-assistance-trimestriel-plja09y7",
"pln_formation-et-assistance-semestriel-vohd04oh",
"pln_formation-et-assistance-annuel-wkhe043e"
];
var hasSpecialPlan = userData.planConnections.some(plan => specialPlanIds.includes(plan.planId) && plan.status === "ACTIVE");
var hasEcomPlan = userData.planConnections.some(plan => plan.planId === "pln_formation-webflow-e-commerce-cms-3-fois--y110qun" && plan.status === "ACTIVE");
var hasPackPlan = userData.planConnections.some(plan => plan.planId === "pln_webflow-le-pack-3-fois--sshd024y" && plan.status === "ACTIVE");
var hasMegaPackPlan = userData.planConnections.some(plan => plan.planId === "pln_le-mega-pack-webflow-3-fois--tnkm02zj" && plan.status === "ACTIVE");
var startDate;
if (hasEcomPlan) {
startDate = new Date(userData.metaData.start_date_wf_eco);
} else if (hasPackPlan) {
startDate = new Date(userData.metaData.start_date_wf_pack);
} else if (hasMegaPackPlan) {
startDate = new Date(userData.metaData.start_date_wf_megapack);
}
var daysForLevel2 = 30;
var daysForLevel3 = 60;
var daysSinceStart = Math.floor((new Date() - startDate) / (1000 * 60 * 60 * 24));
var accessLevel = 1;
if (daysSinceStart >= daysForLevel2) { accessLevel = 2; }
if (daysSinceStart >= daysForLevel3) { accessLevel = 3; }
// Calcul du temps restant pour chaque niveau
var timeLeftForLevel2 = calculateDaysLeft(startDate, daysForLevel2);
var timeLeftForLevel3 = calculateDaysLeft(startDate, daysForLevel3);
// Mise à jour du temps restant pour les niveaux 2 et 3
document.querySelectorAll('[data-drip-content="courseTimeLeft2"]').forEach(function(span) {
span.textContent = timeLeftForLevel2.toString();
});
document.querySelectorAll('[data-drip-content="courseTimeLeft3"]').forEach(function(span) {
span.textContent = timeLeftForLevel3.toString();
});
// Sélection des éléments pour les cartes, prix, boutons et noms des cours
var courseTimeLeftCard1 = document.querySelectorAll('[data-drip-content="courseTimeLeftCard1"]');
var courseTimeLeftCard2 = document.querySelectorAll('[data-drip-content="courseTimeLeftCard2"]');
var courseTimeLeftCard3 = document.querySelectorAll('[data-drip-content="courseTimeLeftCard3"]');
var courseTimeLeftPrice = document.querySelectorAll('[data-drip-content="courseTimeLeftPrice"]');
var courseTimeLeftButton = document.querySelectorAll('[data-drip-content="courseTimeLeftButton"]');
var courseTimeName1 = document.querySelectorAll('[data-drip-content="courseTimeName1"]');
var courseTimeName2 = document.querySelectorAll('[data-drip-content="courseTimeName2"]');
var echeancePayment2 = document.querySelectorAll('[data-drip-content="echeancePayment2"]');
var echeancePayment3 = document.querySelectorAll('[data-drip-content="echeancePayment3"]');
if (hasPackPlan || hasMegaPackPlan) {
if (daysSinceStart >= daysForLevel2) {
courseTimeLeftCard1.forEach(card => card.style.display = 'none');
courseTimeLeftCard2.forEach(card => card.style.display = 'none');
}
if (daysSinceStart >= daysForLevel3) {
courseTimeLeftCard3.forEach(card => card.style.display = 'none');
}
} else if (hasEcomPlan) {
// Pour ecomPlan, masquer la première carte immédiatement et les autres progressivement
courseTimeLeftCard1.forEach(card => card.style.display = 'none');
// Condition pour le masquage progressif, basée sur le temps depuis la date de début
if (daysSinceStart >= daysForLevel2) {
courseTimeLeftCard2.forEach(card => card.style.display = 'none');
}
if (daysSinceStart >= daysForLevel3) {
courseTimeLeftCard3.forEach(card => card.style.display = 'none');
}
}
// Fonction pour mettre à jour le contenu en fonction du plan
var updateContent = function(priceText, buttonText, buttonHref, name1Text, name2Text, paymentTime2, paymentTime3) {
courseTimeLeftPrice.forEach(function(price) {
price.textContent = priceText;
});
courseTimeLeftButton.forEach(function(button) {
button.href = buttonHref;
});
courseTimeName1.forEach(function(name) {
name.textContent = name1Text;
});
courseTimeName2.forEach(function(name) {
name.textContent = name2Text;
});
echeancePayment2.forEach(function(name) {
name.textContent = paymentTime2;
});
echeancePayment3.forEach(function(name) {
name.textContent = paymentTime3;
});
};
if (daysSinceStart >= daysForLevel2) {
// Masquer les cartes pour le niveau 2
courseTimeLeftCard2.forEach(function(card) {
card.style.display = 'none';
});
if (hasEcomPlan) {
updateContent("60€", "Commande E-commerce CMS 60€", "https://order.coriace.co/formation/commande-webflow-ecommerce-cms-60/etape/commande-webflow-ecommerce-cms-60/", "Produit Phy.", "CMS", "2ème échéance", "3ème échéance");
}
if (hasPackPlan) {
updateContent("84€", "Commande Pack Webflow 84€", "https://order.coriace.co/formation/commande-pack-webflow-84/etape/commande-pack-webflow-84/", "Wf E-co.", "Wf CMS", "2ème échéance", "3ème échéance");
}
if (hasMegaPackPlan) {
updateContent("116€", "Commande Mega Pack Webflow 116€", "https://order.coriace.co/formation/commande-mega-pack-webflow-116/etape/commande-mega-pack-webflow-116/", "Partie 2", "Partie 3", "2ème échéance", "3ème échéance");
}
} else {
// Utilisation de la fonction updateContent avec des valeurs spécifiques pour le cas où daysSinceStart < daysForLevel2
if (hasEcomPlan) {
updateContent("120€", "Commande Webflow E-commerce CMS 120€", "https://order.coriace.co/formation/commande-webflow-ecommerce-cms-120/etape/commande-webflow-ecommerce-cms-120/", "Produit Phy.", "CMS", "2ème échéance", "3ème échéance");
}
if (hasPackPlan) {
updateContent("168€", "Commande Pack Webflow 168€", "https://order.coriace.co/formation/commande-pack-webflow-168/etape/commande-pack-webflow-168/", "Wf E-co.", "Wf CMS", "2ème échéance", "3ème échéance");
}
if (hasMegaPackPlan) {
updateContent("232€", "Commande Mega Pack Webflow 232€", "https://order.coriace.co/formation/commande-mega-pack-webflow-232/etape/commande-mega-pack-webflow-232/", "Partie 2", "Partie 3", "2ème échéance", "3ème échéance");
}
}
if (daysSinceStart >= daysForLevel3) {
courseTimeLeftCard3.forEach(function(card) {
card.style.display = 'none';
});
}
if (hasSpecialPlan) {
courseTimeLeftCard2.forEach(function(card) {
card.style.display = 'none';
});
courseTimeLeftCard3.forEach(function(card) {
card.style.display = 'none';
});
courseTimeLeftCard1.forEach(function(card) {
card.style.display = 'none';
});
}
document.querySelectorAll('.course_lesson-item').forEach(function(item) {
var paidId;
if (hasEcomPlan) {
paidId = parseInt(item.getAttribute('data-paid-id'), 10);
} else if (hasPackPlan) {
paidId = parseInt(item.getAttribute('data-pack-paid-id'), 10);
} else if (hasMegaPackPlan) {
paidId = parseInt(item.getAttribute('data-megapack-paid-id'), 10);
}
var lessonMask = item.querySelector('.course_lesson-mask');
if (paidId > accessLevel) {
item.style.opacity = '0.5';
if (lessonMask) lessonMask.style.display = 'block';
} else {
item.style.opacity = '1';
if (lessonMask) lessonMask.style.display = 'none';
}
});
// Afficher les éléments lorsque l'utilisateur a un plan spécial
if (hasSpecialPlan) {
document.querySelectorAll('.course_lesson-item').forEach(function(item) {
item.style.opacity = '1';
var lessonMask = item.querySelector('.course_lesson-mask');
if (lessonMask) lessonMask.style.display = 'none';
});
}
var courseNavigation = document.getElementById('courseNavigation');
var allItemsActive = accessLevel >= 3 || hasSpecialPlan;
if (!allItemsActive && courseNavigation) courseNavigation.style.display = 'none';
else if (courseNavigation) courseNavigation.style.display = 'flex';
} else {
console.log("Les informations du membre ne sont pas disponibles dans le localStorage ou la date de début est manquante.");
}
}
checkMemberPlan();
});
/*-- FIN : Drip Content paiement en plusieurs fois combiné --*/