Voici un code HTML/JS/CSS complet pour un site e-commerce avancé (à déployer sur un serveur HTTPS) :
html Copy code
<!DOCTYPE html>
<html lang="fr" data-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Luxury Commerce Pro</title>
<style>
/* Style CSS moderne et responsive */
:root {
--primary: #2A2F4F;
--secondary: #917FB3;
--accent: #E5BEEC;
--success: #4CAF50;
--danger: #f44336;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', sans-serif;
}
body {
background: #f8f9fa;
}
.navbar {
background: var(--primary);
padding: 1rem;
color: white;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.nav-content {
max-width: 1200px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.5rem;
font-weight: 700;
}
.nav-links {
display: flex;
gap: 2rem;
}
.nav-links a {
color: white;
text-decoration: none;
transition: color 0.3s;
}
.nav-links a:hover {
color: var(--accent);
}
.container {
max-width: 1200px;
margin: 2rem auto;
padding: 0 1rem;
}
.product-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 2rem;
margin-top: 2rem;
}
.product-card {
background: white;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 2px 15px rgba(0,0,0,0.1);
transition: transform 0.3s;
}
.product-card:hover {
transform: translateY(-5px);
}
.product-image {
width: 100%;
height: 200px;
object-fit: cover;
}
.product-info {
padding: 1.5rem;
}
.price {
font-size: 1.25rem;
color: var(--primary);
font-weight: 600;
margin: 0.5rem 0;
}
.btn {
background: var(--primary);
color: white;
padding: 0.8rem 1.5rem;
border: none;
border-radius: 5px;
cursor: pointer;
transition: opacity 0.3s;
}
.btn:hover {
opacity: 0.9;
}
.cart-sidebar {
position: fixed;
right: -400px;
top: 0;
width: 400px;
height: 100vh;
background: white;
box-shadow: -5px 0 15px rgba(0,0,0,0.1);
padding: 2rem;
transition: right 0.3s;
z-index: 1000;
}
.cart-sidebar.active {
right: 0;
}
.cart-item {
display: flex;
gap: 1rem;
margin-bottom: 1rem;
padding-bottom: 1rem;
border-bottom: 1px solid #eee;
}
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
z-index: 999;
display: none;
}
.filter-section {
background: white;
padding: 1.5rem;
border-radius: 10px;
margin-bottom: 2rem;
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.search-bar {
display: flex;
gap: 1rem;
margin-bottom: 1rem;
}
input[type="text"] {
padding: 0.8rem;
border: 1px solid #ddd;
border-radius: 5px;
flex: 1;
}
.admin-panel {
background: #f0f0f0;
padding: 2rem;
border-radius: 10px;
margin-top: 2rem;
}
@media (max-width: 768px) {
.nav-links {
display: none;
}
.cart-sidebar {
width: 100%;
}
}
</style>
</head>
<body>
<nav class="navbar">
<div class="nav-content">
<div class="logo">Luxury Commerce</div>
<div class="nav-links">
<a href="#">Accueil</a>
<a href="#">Produits</a>
<a href="#">Contact</a>
<a href="#" id="lang-toggle">EN</a>
</div>
</div>
</nav>
<div class="container">
<div class="filter-section">
<div class="search-bar">
<input type="text" id="search-input" placeholder="Rechercher un produit...">
<button class="btn" onclick="filterProducts()">🔍</button>
</div>
<div class="filters">
<select id="category-filter" onchange="filterProducts()">
<option value="">Toutes catégories</option>
<option value="electronics">Électronique</option>
<option value="clothing">Vêtements</option>
<option value="home">Maison</option>
</select>
</div>
</div>
<div class="product-grid" id="product-grid"></div>
</div>
<div class="cart-sidebar" id="cart-sidebar">
<h2>Panier</h2>
<div id="cart-items"></div>
<div class="cart-total">
<p>Total: <span id="cart-total">0</span> €</p>
<button class="btn" onclick="checkout()">Passer la commande</button>
</div>
</div>
<div class="overlay" id="overlay"></div>
<script>
// Données produits
const products = [
{
id: 1,
name: "Smartphone Pro X",
price: 899,
category: "electronics",
description: "Le dernier smartphone avec caméra 108MP",
image: "https://picsum.photos/300/200?1",
stock: 10
},
{
id: 2,
name: "Casque Audio Premium",
price: 249,
category: "electronics",
description: "Son haute définition avec réduction de bruit",
image: "https://picsum.photos/300/200?2",
stock: 15
},
{
id: 3,
name: "Veste en Cuir",
price: 399,
category: "clothing",
description: "Cuir véritable, coupe slim",
image: "https://picsum.photos/300/200?3",
stock: 5
},
{
id: 4,
name: "Canapé Design",
price: 1299,
category: "home",
description: "Design scandinave, tissu premium",
image: "https://picsum.photos/300/200?4",
stock: 3
}
];
// Variables globales
let cart = JSON.parse(localStorage.getItem('cart')) || [];
let currentLang = 'fr';
const translations = {
fr: {
checkout: "Passer la commande",
total: "Total",
search: "Rechercher un produit...",
adminPanel: "Panneau d'Administration"
},
en: {
checkout: "Proceed to Checkout",
total: "Total",
search: "Search products...",
adminPanel: "Admin Panel"
}
};
// Initialisation
function init() {
renderProducts();
updateCart();
setupEventListeners();
}
// Rendu des produits
function renderProducts(productsToRender = products) {
const grid = document.getElementById('product-grid');
grid.innerHTML = productsToRender.map(product => `
<div class="product-card">
<img src="${product.image}" class="product-image" alt="${product.name}">
<div class="product-info">
<h3>${product.name}</h3>
<p>${product.description}</p>
<div class="price">${product.price} €</div>
<button class="btn" onclick="addToCart(${product.id})">Ajouter au panier</button>
</div>
</div>
`).join('');
}
// Gestion du panier
function addToCart(productId) {
const product = products.find(p => p.id === productId);
const existingItem = cart.find(item => item.id === productId);
if (existingItem) {
existingItem.quantity++;
} else {
cart.push({...product, quantity: 1});
}
localStorage.setItem('cart', JSON.stringify(cart));
updateCart();
}
function updateCart() {
const cartItems = document.getElementById('cart-items');
const total = document.getElementById('cart-total');
cartItems.innerHTML = cart.map(item => `
<div class="cart-item">
<img src="${item.image}" width="60" alt="${item.name}">
<div>
<h4>${item.name}</h4>
<p>${item.price} € x ${item.quantity}</p>
<button onclick="removeFromCart(${item.id})">🗑️</button>
</div>
</div>
`).join('');
const cartTotal = cart.reduce((sum, item) => sum + (item.price * item.quantity), 0);
total.textContent = cartTotal;
}
function removeFromCart(productId) {
cart = cart.filter(item => item.id !== productId);
localStorage.setItem('cart', JSON.stringify(cart));
updateCart();
}
// Fonctionnalités avancées
function filterProducts() {
const searchTerm = document.getElementById('search-input').value.toLowerCase();
const category = document.getElementById('category-filter').value;
const filtered = products.filter(product => {
const matchesSearch = product.name.toLowerCase().includes(searchTerm);
const matchesCategory = !category || product.category === category;
return matchesSearch && matchesCategory;
});
renderProducts(filtered);
}
function checkout() {
if (cart.length === 0) {
alert(translations[currentLang].emptyCart);
return;
}
// Simulation de paiement
alert(translations[currentLang].orderSuccess);
cart = [];
localStorage.removeItem('cart');
updateCart();
}
// Internationalisation
document.getElementById('lang-toggle').addEventListener('click', function() {
currentLang = currentLang === 'fr' ? 'en' : 'fr';
this.textContent = currentLang.toUpperCase();
// Mettre à jour l'interface selon la langue
});
// Initialisation
init();
</script>
</body>
</html>
Le code actuel est une base client-side fonctionnelle qui simule les fonctionnalités principales. Pour un site production, il faudrait une architecture full-stack complète.