You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
7.7 KiB
293 lines
7.7 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Daraz-style Cart</title>
|
|
<style>
|
|
/* Basic Reset */
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background-color: #f9f9f9;
|
|
color: #333;
|
|
}
|
|
|
|
header {
|
|
background-color: #ff6700;
|
|
color: white;
|
|
padding: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
header h1 {
|
|
font-size: 24px;
|
|
}
|
|
|
|
#product-list {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
justify-content: space-around;
|
|
margin: 20px;
|
|
}
|
|
|
|
.product {
|
|
background-color: white;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
text-align: center;
|
|
width: 250px;
|
|
margin-bottom: 20px;
|
|
transition: transform 0.3s;
|
|
}
|
|
|
|
.product:hover {
|
|
transform: translateY(-5px);
|
|
}
|
|
|
|
.product img {
|
|
width: 100%;
|
|
height: auto;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.product h4 {
|
|
margin-top: 10px;
|
|
font-size: 18px;
|
|
}
|
|
|
|
.product p {
|
|
font-weight: bold;
|
|
color: #ff6700;
|
|
margin: 10px 0;
|
|
}
|
|
|
|
.add-to-cart-btn {
|
|
background-color: #ff6700;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 15px;
|
|
cursor: pointer;
|
|
border-radius: 5px;
|
|
margin-top: 10px;
|
|
transition: background-color 0.3s;
|
|
}
|
|
|
|
.add-to-cart-btn:hover {
|
|
background-color: #e65c00;
|
|
}
|
|
|
|
#cart {
|
|
margin: 20px auto;
|
|
padding: 20px;
|
|
max-width: 800px;
|
|
background-color: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
#cart h2 {
|
|
margin-bottom: 15px;
|
|
font-size: 22px;
|
|
}
|
|
|
|
#cart-items {
|
|
list-style: none;
|
|
padding: 0;
|
|
}
|
|
|
|
#cart-items li {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 10px 0;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
|
|
#cart-items li span {
|
|
flex: 1;
|
|
text-align: center;
|
|
}
|
|
|
|
.checkout-btn {
|
|
background-color: #ff6700;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
cursor: pointer;
|
|
border-radius: 5px;
|
|
font-size: 16px;
|
|
margin-top: 20px;
|
|
transition: background-color 0.3s;
|
|
display: block;
|
|
width: 100%;
|
|
text-align: center;
|
|
}
|
|
|
|
.checkout-btn:hover {
|
|
background-color: #e65c00;
|
|
}
|
|
|
|
/* Invoice Styles */
|
|
#invoice {
|
|
display: none;
|
|
margin: 20px auto;
|
|
max-width: 600px;
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
#invoice h2 {
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
#invoice table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
}
|
|
|
|
#invoice table th, #invoice table td {
|
|
text-align: left;
|
|
padding: 10px;
|
|
border: 1px solid #ddd;
|
|
}
|
|
|
|
#invoice .close-invoice {
|
|
background-color: #ff6700;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
cursor: pointer;
|
|
border-radius: 5px;
|
|
margin-top: 20px;
|
|
display: block;
|
|
text-align: center;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
}
|
|
|
|
#invoice .close-invoice:hover {
|
|
background-color: #e65c00;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<h1>Daraz-Style Shopping Cart</h1>
|
|
</header>
|
|
|
|
<section id="product-list">
|
|
<!-- Product 1 -->
|
|
<div class="product">
|
|
<img src="https://via.placeholder.com/250" alt="Product">
|
|
<h4>Product 1</h4>
|
|
<p>Price: $100</p>
|
|
<button class="add-to-cart-btn" data-name="Product 1" data-price="100" data-discount="10">Add to Cart</button>
|
|
</div>
|
|
|
|
<!-- Product 2 -->
|
|
<div class="product">
|
|
<img src="https://via.placeholder.com/250" alt="Product">
|
|
<h4>Product 2</h4>
|
|
<p>Price: $200</p>
|
|
<button class="add-to-cart-btn" data-name="Product 2" data-price="200" data-discount="15">Add to Cart</button>
|
|
</div>
|
|
</section>
|
|
|
|
<section id="cart">
|
|
<h2>Your Cart</h2>
|
|
<ul id="cart-items"></ul>
|
|
<button class="checkout-btn">Checkout</button>
|
|
</section>
|
|
|
|
<section id="invoice">
|
|
<h2>Invoice</h2>
|
|
<table>
|
|
<tr>
|
|
<th>Product</th>
|
|
<td id="invoice-product"></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Price</th>
|
|
<td id="invoice-price"></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Discount</th>
|
|
<td id="invoice-discount"></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Commission (10%)</th>
|
|
<td id="invoice-commission"></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Total</th>
|
|
<td id="invoice-total"></td>
|
|
</tr>
|
|
</table>
|
|
<button class="close-invoice">Close</button>
|
|
</section>
|
|
|
|
<script>
|
|
const cart = [];
|
|
const cartItemsElement = document.getElementById('cart-items');
|
|
const invoiceSection = document.getElementById('invoice');
|
|
|
|
function updateCart() {
|
|
cartItemsElement.innerHTML = '';
|
|
cart.forEach((item) => {
|
|
const li = document.createElement('li');
|
|
li.innerHTML = `
|
|
<span>${item.name}</span>
|
|
<span>$${item.price}</span>
|
|
<span>${item.discount}% Off</span>
|
|
`;
|
|
cartItemsElement.appendChild(li);
|
|
});
|
|
}
|
|
|
|
document.querySelectorAll('.add-to-cart-btn').forEach((button) => {
|
|
button.addEventListener('click', () => {
|
|
const name = button.getAttribute('data-name');
|
|
const price = parseFloat(button.getAttribute('data-price'));
|
|
const discount = parseFloat(button.getAttribute('data-discount'));
|
|
cart.push({ name, price, discount });
|
|
updateCart();
|
|
});
|
|
});
|
|
|
|
document.querySelector('.checkout-btn').addEventListener('click', () => {
|
|
if (cart.length === 0) {
|
|
alert('Your cart is empty!');
|
|
return;
|
|
}
|
|
const product = cart[0];
|
|
const discountedPrice = product.price - (product.price * (product.discount / 100));
|
|
const commission = discountedPrice * 0.1;
|
|
const total = discountedPrice + commission;
|
|
|
|
document.getElementById('invoice-product').textContent = product.name;
|
|
document.getElementById('invoice-price').textContent = `$${product.price}`;
|
|
document.getElementById('invoice-discount').textContent = `-$${(product.price * (product.discount / 100)).toFixed(2)}`;
|
|
document.getElementById('invoice-commission').textContent = `$${commission.toFixed(2)}`;
|
|
document.getElementById('invoice-total').textContent = `$${total.toFixed(2)}`;
|
|
|
|
invoiceSection.style.display = 'block';
|
|
});
|
|
|
|
document.querySelector('.close-invoice').addEventListener('click', () => {
|
|
invoiceSection.style.display = 'none';
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
|