Beta
This commit is contained in:
parent
e19f942547
commit
5e0a3cfabe
7 changed files with 61 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ksiegarnia"
|
||||
version = "0.1.0"
|
||||
version = "0.9.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
3
migrations/20250601094238_zmień_dostawe.sql
Normal file
3
migrations/20250601094238_zmień_dostawe.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE zamowienia ALTER COLUMN typ_dostawy SET DEFAULT 'shipping';
|
||||
|
||||
UPDATE zamowienia SET typ_dostawy = 'shipping' WHERE typ_dostawy IS NULL;
|
|
@ -58,19 +58,16 @@
|
|||
<span class="text-primary" id="products-value">0.00 PLN</span>
|
||||
</div>
|
||||
|
||||
<!-- Zmieniony układ dla opcji dostawy -->
|
||||
<div class="mb-3">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="d-flex justify-content-between mb-3 align-items-center">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="localPickup">
|
||||
<input class="form-check-input" type="checkbox" id="localPickup" checked>
|
||||
<label class="form-check-label" for="localPickup">
|
||||
Dostawa
|
||||
Dostawa (12.99 PLN)
|
||||
</label>
|
||||
</div>
|
||||
<span id="delivery-value">12.99 PLN</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<div class="d-flex justify-content-between fw-bold fs-5">
|
||||
<span>Do zapłaty:</span>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { formatCurrency } from "./utils.js"
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const bookId = urlParams.get('id');
|
||||
|
@ -38,9 +40,11 @@ async function loadBookDetails(bookId) {
|
|||
}
|
||||
|
||||
function displayBookDetails(book) {
|
||||
const price = formatCurrency(book.cena);
|
||||
|
||||
document.getElementById('book-title').textContent = book.tytul;
|
||||
document.getElementById('book-author').textContent = book.autor;
|
||||
document.getElementById('book-price').textContent = `${book.cena} PLN`;
|
||||
document.getElementById('book-price').textContent = price;
|
||||
document.getElementById('book-description').textContent = book.opis;
|
||||
|
||||
const bookCover = document.getElementById('book-cover');
|
||||
|
@ -51,6 +55,14 @@ function displayBookDetails(book) {
|
|||
}
|
||||
|
||||
async function addToCart(bookId) {
|
||||
const response = await fetch('/api/check-auth');
|
||||
const data = await response.json();
|
||||
|
||||
if (!data.authenticated) {
|
||||
window.location.href = '/login.html';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/add-to-cart', {
|
||||
method: 'POST',
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { formatCurrency } from './utils.js';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const booksContainer = document.getElementById('books-container');
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
|
@ -72,6 +74,8 @@ function displayBooks(books) {
|
|||
booksContainer.innerHTML = '';
|
||||
|
||||
books.forEach(book => {
|
||||
const price = formatCurrency(book.cena);
|
||||
|
||||
const bookCard = `
|
||||
<div class="book-card">
|
||||
<a href="/book.html?id=${book.id}" class="book-cover-link">
|
||||
|
@ -80,7 +84,7 @@ function displayBooks(books) {
|
|||
<div class="book-overlay">
|
||||
<h5>${book.tytul}</h5>
|
||||
<p>${book.autor}</p>
|
||||
<p class="price">${book.cena} PLN</p>
|
||||
<p class="price">${price}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
@ -101,8 +105,15 @@ function displayBooks(books) {
|
|||
});
|
||||
}
|
||||
|
||||
// Funkcja dodająca do koszyka
|
||||
async function addToCart(bookId) {
|
||||
const response = await fetch('/api/check-auth');
|
||||
const data = await response.json();
|
||||
|
||||
if (!data.authenticated) {
|
||||
window.location.href = '/login.html';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/add-to-cart', {
|
||||
method: 'POST',
|
||||
|
|
|
@ -8,7 +8,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
|
||||
// Dodaj event listeners
|
||||
if (localPickupCheckbox) {
|
||||
// JEDEN listener dla checkboxa
|
||||
localPickupCheckbox.addEventListener('change', function() {
|
||||
// Pobierz aktualny stan koszyka i zaktualizuj podsumowanie
|
||||
const cartItems = Array.from(document.querySelectorAll('.card.mb-3')).map(card => {
|
||||
|
@ -60,6 +59,13 @@ async function loadCart() {
|
|||
|
||||
const cartItems = await response.json();
|
||||
displayCartItems(cartItems);
|
||||
|
||||
// Ustaw checkbox jako odznaczony domyślnie (dostawa)
|
||||
const localPickupCheckbox = document.getElementById('localPickup');
|
||||
if (localPickupCheckbox) {
|
||||
localPickupCheckbox.checked = false;
|
||||
}
|
||||
|
||||
updateSummary(cartItems);
|
||||
} catch (error) {
|
||||
console.error('Błąd ładowania koszyka:', error);
|
||||
|
@ -179,7 +185,6 @@ async function updateCartItemQuantity(bookId, change) {
|
|||
}
|
||||
}
|
||||
|
||||
// Funkcja do aktualizacji podsumowania na podstawie DOM
|
||||
function updateSummaryFromDOM() {
|
||||
const cartItems = Array.from(document.querySelectorAll('.card.mb-3')).map(card => {
|
||||
const bookId = card.querySelector('.decrease-btn').dataset.bookId;
|
||||
|
@ -218,8 +223,8 @@ function updateSummary(cartItems) {
|
|||
|
||||
productsValueEl.textContent = productsValue.toFixed(2) + ' PLN';
|
||||
|
||||
// Oblicz koszt dostawy
|
||||
const deliveryCost = localPickupCheckbox && localPickupCheckbox.checked ? 0 : 12.99;
|
||||
// Oblicz koszt dostawy: jeśli checkbox ZAZNACZONY to 0 (odbiór lokalny), w przeciwnym razie 12.99 (dostawa)
|
||||
const deliveryCost = localPickupCheckbox && localPickupCheckbox.checked ? 12.99 : 0;
|
||||
deliveryValueEl.textContent = deliveryCost.toFixed(2) + ' PLN';
|
||||
|
||||
const totalValue = productsValue + deliveryCost;
|
||||
|
@ -272,6 +277,7 @@ async function handleCheckout() {
|
|||
quantity: item.quantity
|
||||
})),
|
||||
total: parseFloat(document.getElementById('total-value').textContent),
|
||||
// Odwrócona logika: checked = odbiór lokalny, unchecked = dostawa
|
||||
delivery_type: localPickupCheckbox.checked ? "local" : "shipping"
|
||||
};
|
||||
|
||||
|
|
|
@ -50,13 +50,27 @@ function displayOrderHistory(orders) {
|
|||
|
||||
orders.forEach(order => {
|
||||
const orderDate = new Date(order.data_zamowienia).toLocaleDateString();
|
||||
|
||||
// Poprawione mapowanie typów dostawy
|
||||
let deliveryType = order.typ_dostawy || 'shipping';
|
||||
let deliveryText = '';
|
||||
|
||||
if (deliveryType === 'local') {
|
||||
deliveryText = 'Odbiór lokalny';
|
||||
} else if (deliveryType === 'shipping') {
|
||||
deliveryText = 'Dostawa';
|
||||
} else {
|
||||
// Dla starych zamówień bez typu
|
||||
deliveryText = 'Dostawa';
|
||||
}
|
||||
|
||||
const orderElement = `
|
||||
<div class="card mb-3 order-card">
|
||||
<div class="card-header">
|
||||
<h5>Zamówienie #${order.id} - ${orderDate}</h5>
|
||||
<p class="mb-0">Status: ${order.status || 'W realizacji'}</p>
|
||||
<p class="mb-0">Suma: ${order.suma_totalna} PLN</p>
|
||||
<p class="mb-0">Typ dostawy: ${order.typ_dostawy === 'local' ? 'Odbiór lokalny' : 'Dostawa'}</p>
|
||||
<p class="mb-0">Typ: ${deliveryText}</p>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h6>Produkty:</h6>
|
||||
|
@ -78,3 +92,4 @@ function displayOrderHistory(orders) {
|
|||
orderHistoryContainer.innerHTML += orderElement;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue