tsett
This commit is contained in:
270
resources/views/cart/checkout.blade.php
Normal file
270
resources/views/cart/checkout.blade.php
Normal file
@@ -0,0 +1,270 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Оформление заказа')
|
||||
|
||||
@php $style = 'checkout'; @endphp
|
||||
|
||||
@section('content')
|
||||
<div class="container py-4">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1 class="h2 mb-4">Оформление заказа</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 col-lg-7">
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-body p-4">
|
||||
<form action="{{ route('checkout.process') }}" method="POST" id="checkout-form">
|
||||
@csrf
|
||||
|
||||
{{-- Контактные данные --}}
|
||||
<h5 class="mb-3">Контактные данные</h5>
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-12">
|
||||
<label class="form-label">Ваше имя <span class="text-danger">*</span></label>
|
||||
<input type="text"
|
||||
class="form-control @error('customer_name') is-invalid @enderror"
|
||||
name="customer_name"
|
||||
value="{{ old('customer_name', auth()->user()->name ?? '') }}"
|
||||
required>
|
||||
@error('customer_name')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-12 col-md-6">
|
||||
<label class="form-label">Email <span class="text-danger">*</span></label>
|
||||
<input type="email"
|
||||
class="form-control @error('customer_email') is-invalid @enderror"
|
||||
name="customer_email"
|
||||
value="{{ old('customer_email', auth()->user()->email ?? '') }}"
|
||||
required>
|
||||
@error('customer_email')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-12 col-md-6">
|
||||
<label class="form-label">Телефон <span class="text-danger">*</span></label>
|
||||
<input type="tel"
|
||||
class="form-control @error('customer_phone') is-invalid @enderror"
|
||||
name="customer_phone"
|
||||
value="{{ old('customer_phone', auth()->user()->phone ?? '') }}"
|
||||
required>
|
||||
@error('customer_phone')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Способ доставки --}}
|
||||
<h5 class="mb-3">Способ доставки</h5>
|
||||
<div class="row g-3 mb-4 bg-light">
|
||||
<div class="col-12">
|
||||
<div class="delivery-options">
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="radio" name="delivery_method"
|
||||
id="delivery_courier" value="courier" checked>
|
||||
<label class="form-check-label" for="delivery_courier">
|
||||
<strong>Курьером</strong> — бесплатно
|
||||
<small class="text-muted d-block">Доставка по городу в течение 1-2 дней</small>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="radio" name="delivery_method"
|
||||
id="delivery_pickup" value="pickup">
|
||||
<label class="form-check-label" for="delivery_pickup">
|
||||
<strong>Самовывоз</strong> — бесплатно
|
||||
<small class="text-muted d-block">Заберите заказ из нашего магазина</small>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="radio" name="delivery_method"
|
||||
id="delivery_express" value="express">
|
||||
<label class="form-check-label" for="delivery_express">
|
||||
<strong>Экспресс-доставка</strong> — 300 ₽
|
||||
<small class="text-muted d-block">Доставка в течение 1-2 часов</small>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@error('delivery_method')
|
||||
<div class="text-danger small">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Адрес доставки (показывается только для курьера и экспресса) --}}
|
||||
<div id="address-block" style="display: none;">
|
||||
<h5 class="mb-3">Адрес доставки</h5>
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-12">
|
||||
<label class="form-label">Адрес <span class="text-danger">*</span></label>
|
||||
<textarea class="form-control @error('shipping_address') is-invalid @enderror"
|
||||
name="shipping_address"
|
||||
rows="3"
|
||||
placeholder="Город, улица, дом, квартира">{{ old('shipping_address') }}</textarea>
|
||||
@error('shipping_address')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Способ оплаты --}}
|
||||
<h5 class="mb-3">Способ оплаты</h5>
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-12">
|
||||
<div class="payment-options">
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="radio" name="payment_method"
|
||||
id="payment_cash" value="cash" checked>
|
||||
<label class="form-check-label" for="payment_cash">
|
||||
<strong>Наличными при получении</strong>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="radio" name="payment_method"
|
||||
id="payment_card" value="card">
|
||||
<label class="form-check-label" for="payment_card">
|
||||
<strong>Картой при получении</strong>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="radio" name="payment_method"
|
||||
id="payment_online" value="online">
|
||||
<label class="form-check-label" for="payment_online">
|
||||
<strong>Онлайн-оплата</strong>
|
||||
<small class="text-muted d-block">Картой на сайте, Яндекс.Деньги и др.</small>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@error('payment_method')
|
||||
<div class="text-danger small">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Комментарий --}}
|
||||
<h5 class="mb-3">Комментарий к заказу</h5>
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-12">
|
||||
<textarea class="form-control" name="comment" rows="3"
|
||||
placeholder="Если есть особые пожелания, напишите их здесь...">{{ old('comment') }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn-dark-green flex-grow-1 py-3" id="submit-btn">
|
||||
Оформить заказ
|
||||
</button>
|
||||
<a href="{{ route('cart.index') }}" class="btn-outline-mint py-3 px-4 text-decoration-none">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Информация о заказе --}}
|
||||
<div class="col-12 col-lg-5">
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<h5 class="card-title mb-4">Ваш заказ</h5>
|
||||
|
||||
<div class="order-items mb-3">
|
||||
@foreach($cartItems as $item)
|
||||
<div class="d-flex justify-content-between mb-2 pb-2 border-bottom">
|
||||
<div>
|
||||
<span class="fw-semibold">{{ $item->variation->product->name }}</span>
|
||||
@if($item->variation->name)
|
||||
<br><small class="text-muted">{{ $item->variation->name }}</small>
|
||||
@endif
|
||||
<br><small class="text-muted">{{ $item->quantity }} шт.</small>
|
||||
</div>
|
||||
<div class="text-end">
|
||||
<span>{{ number_format($item->total, 0, '.', ' ') }} ₽</span>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
<div class="order-total">
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<span>Товары ({{ $cartItems->sum('quantity') }} шт.)</span>
|
||||
<span id="order-subtotal">{{ number_format($total, 0, '.', ' ') }} ₽</span>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<span>Доставка</span>
|
||||
<span id="order-shipping">200 ₽</span>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<strong>Итого к оплате:</strong>
|
||||
<strong class="fs-5 text-success" id="order-total">{{ number_format($total + 200, 0, '.', ' ') }} ₽</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('script')
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const deliveryRadios = document.querySelectorAll('input[name="delivery_method"]');
|
||||
const addressBlock = document.getElementById('address-block');
|
||||
const shippingAddress = document.querySelector('textarea[name="shipping_address"]');
|
||||
const orderShipping = document.getElementById('order-shipping');
|
||||
const orderTotal = document.getElementById('order-total');
|
||||
const orderSubtotal = document.getElementById('order-subtotal');
|
||||
|
||||
const subtotal = parseInt(orderSubtotal.textContent.replace(/[^0-9]/g, '')) || 0;
|
||||
|
||||
function updateShippingCost() {
|
||||
let shippingCost = 0;
|
||||
let selectedDelivery = document.querySelector('input[name="delivery_method"]:checked');
|
||||
|
||||
if (selectedDelivery) {
|
||||
switch (selectedDelivery.value) {
|
||||
case 'courier':
|
||||
shippingCost = 0;
|
||||
addressBlock.style.display = 'block';
|
||||
break;
|
||||
case 'express':
|
||||
shippingCost = 300;
|
||||
addressBlock.style.display = 'block';
|
||||
break;
|
||||
case 'pickup':
|
||||
shippingCost = 0;
|
||||
addressBlock.style.display = 'none';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (orderShipping) orderShipping.textContent = shippingCost + ' ₽';
|
||||
if (orderTotal) orderTotal.textContent = (subtotal + shippingCost).toLocaleString() + ' ₽';
|
||||
}
|
||||
|
||||
deliveryRadios.forEach(radio => {
|
||||
radio.addEventListener('change', updateShippingCost);
|
||||
});
|
||||
|
||||
// Инициализация
|
||||
updateShippingCost();
|
||||
|
||||
// Блокировка кнопки при отправке
|
||||
const form = document.getElementById('checkout-form');
|
||||
const submitBtn = document.getElementById('submit-btn');
|
||||
|
||||
if (form && submitBtn) {
|
||||
form.addEventListener('submit', function() {
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = 'Оформление...';
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
299
resources/views/cart/show.blade.php
Normal file
299
resources/views/cart/show.blade.php
Normal file
@@ -0,0 +1,299 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Корзина')
|
||||
|
||||
@php $style = 'cart'; @endphp
|
||||
|
||||
@section('content')
|
||||
<div class="container py-4">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1 class="h2 mb-4">Корзина</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if($cartItems->count())
|
||||
<div class="row">
|
||||
{{-- Список товаров --}}
|
||||
<div class="col-12 col-lg-8">
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-body p-0">
|
||||
@foreach($cartItems as $item)
|
||||
<div class="cart-item p-3 border-bottom" data-id="{{ $item->id }}">
|
||||
<div class="row align-items-center">
|
||||
{{-- Изображение --}}
|
||||
<div class="col-3 col-md-2">
|
||||
<a href="{{ route('product.show', $item->variation->product->slug) }}">
|
||||
<img src="{{ $item->variation->product->main_image }}"
|
||||
alt="{{ $item->variation->product->name }}"
|
||||
class="img-fluid rounded"
|
||||
style="max-height: 80px; object-fit: contain;">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{-- Информация о товаре --}}
|
||||
<div class="col-9 col-md-6">
|
||||
<a href="{{ route('product.show', $item->variation->product->slug) }}"
|
||||
class="text-decoration-none text-dark">
|
||||
<h6 class="mb-1">{{ $item->variation->product->name }}</h6>
|
||||
</a>
|
||||
@if($item->variation->name)
|
||||
<small class="text-muted d-block">{{ $item->variation->name }}</small>
|
||||
@endif
|
||||
<small class="text-muted">Артикул: {{ $item->variation->sku }}</small>
|
||||
</div>
|
||||
|
||||
{{-- Количество и цена --}}
|
||||
<div class="col-12 col-md-4 mt-3 mt-md-0">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
{{-- Количество (как на странице продукта) --}}
|
||||
<div class="quantity-control d-flex align-items-center border rounded" style="width: 130px;">
|
||||
<button class="btn btn-link text-dark decrement-quantity"
|
||||
data-id="{{ $item->id }}"
|
||||
data-quantity="{{ $item->quantity }}"
|
||||
style="width: 32px;">−</button>
|
||||
<input type="number"
|
||||
class="form-control border-0 text-center quantity-input"
|
||||
value="{{ $item->quantity }}"
|
||||
data-id="{{ $item->id }}"
|
||||
min="1"
|
||||
max="{{ $item->variation->stock }}"
|
||||
style="width: 60px;">
|
||||
<button class="btn btn-link text-dark increment-quantity"
|
||||
data-id="{{ $item->id }}"
|
||||
data-quantity="{{ $item->quantity }}"
|
||||
style="width: 32px;">+</button>
|
||||
</div>
|
||||
|
||||
{{-- Цена --}}
|
||||
<div class="text-end ms-2">
|
||||
<strong class="item-total">{{ number_format($item->total, 0, '.', ' ') }} ₽</strong>
|
||||
<div class="small text-muted">{{ number_format($item->price, 0, '.', ' ') }} ₽ / шт</div>
|
||||
</div>
|
||||
|
||||
{{-- Удалить --}}
|
||||
<button class="btn btn-link text-danger remove-item"
|
||||
data-id="{{ $item->id }}"
|
||||
data-url="{{ route('cart.remove', $item->id) }}">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Итого --}}
|
||||
<div class="col-12 col-lg-4">
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title mb-4">Итого</h5>
|
||||
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<span>Товары (<span id="total-items">{{ $cartItems->sum('quantity') }}</span> шт.)</span>
|
||||
<span id="cart-subtotal">{{ number_format($total, 0, '.', ' ') }} ₽</span>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<span>Скидка</span>
|
||||
<span class="text-success">0 ₽</span>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="d-flex justify-content-between mb-4">
|
||||
<strong>Итого к оплате:</strong>
|
||||
<strong class="fs-5" id="cart-total">{{ number_format($total, 0, '.', ' ') }} ₽</strong>
|
||||
</div>
|
||||
|
||||
<a href="{{ route('checkout.index') }}" class="btn-dark-green text-center w-100 py-3">
|
||||
Перейти к оформлению
|
||||
</a>
|
||||
|
||||
<div class="text-center mt-3">
|
||||
<a href="{{ route('index') }}" class="text-decoration-none small">
|
||||
← Продолжить покупки
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
{{-- Пустая корзина --}}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12 col-md-6 text-center py-5">
|
||||
<h3 class="mt-4">Корзина пуста</h3>
|
||||
<p class="text-muted mb-4">Добавьте товары в корзину, чтобы оформить заказ</p>
|
||||
<a href="{{ route('index') }}" class="btn-dark-green">
|
||||
Перейти к покупкам
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('script')
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Хранилище для отслеживания активных запросов
|
||||
let activeRequests = new Map();
|
||||
|
||||
// Debounce функция
|
||||
function debounce(func, delay) {
|
||||
let timeout;
|
||||
return function(...args) {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => func.apply(this, args), delay);
|
||||
};
|
||||
}
|
||||
|
||||
// Функция обновления количества
|
||||
async function updateQuantity(itemId, quantity) {
|
||||
if (activeRequests.has(itemId)) return;
|
||||
|
||||
activeRequests.set(itemId, true);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/cart/update/${itemId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
|
||||
},
|
||||
body: JSON.stringify({
|
||||
quantity: quantity
|
||||
})
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
const itemElement = document.querySelector(`.cart-item[data-id="${itemId}"]`);
|
||||
if (!itemElement) return;
|
||||
|
||||
const itemTotalSpan = itemElement.querySelector('.item-total');
|
||||
if (itemTotalSpan) {
|
||||
itemTotalSpan.textContent = data.total.toLocaleString() + ' ₽';
|
||||
}
|
||||
|
||||
const cartSubtotalSpan = document.getElementById('cart-subtotal');
|
||||
const cartTotalSpan = document.getElementById('cart-total');
|
||||
const totalItemsSpan = document.getElementById('total-items');
|
||||
|
||||
if (cartSubtotalSpan) cartSubtotalSpan.textContent = data.cart_total.toLocaleString() + ' ₽';
|
||||
if (cartTotalSpan) cartTotalSpan.textContent = data.cart_total.toLocaleString() + ' ₽';
|
||||
if (totalItemsSpan) totalItemsSpan.textContent = data.total_items;
|
||||
|
||||
const quantityInput = itemElement.querySelector('.quantity-input');
|
||||
if (quantityInput) {
|
||||
quantityInput.value = quantity;
|
||||
quantityInput.max = data.max_stock;
|
||||
}
|
||||
|
||||
const decrementBtn = itemElement.querySelector('.decrement-quantity');
|
||||
const incrementBtn = itemElement.querySelector('.increment-quantity');
|
||||
if (decrementBtn) decrementBtn.dataset.quantity = quantity;
|
||||
if (incrementBtn) incrementBtn.dataset.quantity = quantity;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
} finally {
|
||||
activeRequests.delete(itemId);
|
||||
}
|
||||
}
|
||||
|
||||
const debouncedUpdate = debounce(updateQuantity, 300);
|
||||
|
||||
function changeQuantity(itemId, delta) {
|
||||
const itemElement = document.querySelector(`.cart-item[data-id="${itemId}"]`);
|
||||
if (!itemElement) return;
|
||||
|
||||
const quantityInput = itemElement.querySelector('.quantity-input');
|
||||
if (!quantityInput) return;
|
||||
|
||||
let newValue = parseInt(quantityInput.value) + delta;
|
||||
const maxStock = parseInt(quantityInput.max);
|
||||
|
||||
if (newValue < 1) newValue = 1;
|
||||
if (newValue > maxStock) {
|
||||
if (delta > 0) alert('Недостаточно товара на складе');
|
||||
return;
|
||||
}
|
||||
|
||||
quantityInput.value = newValue;
|
||||
debouncedUpdate(itemId, newValue);
|
||||
}
|
||||
|
||||
// Обработчики кнопок +/-
|
||||
document.querySelectorAll('.increment-quantity').forEach(btn => {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
changeQuantity(this.dataset.id, 1);
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.decrement-quantity').forEach(btn => {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
changeQuantity(this.dataset.id, -1);
|
||||
});
|
||||
});
|
||||
|
||||
// Обработчик ручного ввода
|
||||
document.querySelectorAll('.quantity-input').forEach(input => {
|
||||
input.addEventListener('change', function() {
|
||||
const itemId = this.dataset.id;
|
||||
let quantity = parseInt(this.value);
|
||||
const maxStock = parseInt(this.max);
|
||||
const minStock = parseInt(this.min) || 1;
|
||||
|
||||
if (isNaN(quantity) || quantity < minStock) quantity = minStock;
|
||||
if (quantity > maxStock) {
|
||||
quantity = maxStock;
|
||||
alert('Недостаточно товара на складе');
|
||||
}
|
||||
|
||||
this.value = quantity;
|
||||
debouncedUpdate(itemId, quantity);
|
||||
});
|
||||
});
|
||||
|
||||
// Удаление товара (через форму, без AJAX)
|
||||
document.querySelectorAll('.remove-item').forEach(btn => {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
if (!confirm('Удалить товар из корзины?')) return;
|
||||
|
||||
// Создаем форму для отправки DELETE запроса
|
||||
const url = this.dataset.url;
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = url;
|
||||
form.style.display = 'none';
|
||||
|
||||
// Добавляем CSRF токен
|
||||
const csrfInput = document.createElement('input');
|
||||
csrfInput.type = 'hidden';
|
||||
csrfInput.name = '_token';
|
||||
csrfInput.value = document.querySelector('meta[name="csrf-token"]').content;
|
||||
form.appendChild(csrfInput);
|
||||
|
||||
// Добавляем метод DELETE
|
||||
const methodInput = document.createElement('input');
|
||||
methodInput.type = 'hidden';
|
||||
methodInput.name = '_method';
|
||||
methodInput.value = 'DELETE';
|
||||
form.appendChild(methodInput);
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user