Fix LESS import error and refactor project structure
This commit is contained in:
@@ -40,7 +40,7 @@ use App\Core\View;
|
||||
|
||||
<main class="container">
|
||||
<div class="breadcrumbs">
|
||||
<a href="/cite_practica/">Главная</a> • <span class="current-page">Корзина</span>
|
||||
<a href="/">Главная</a> • <span class="current-page">Корзина</span>
|
||||
</div>
|
||||
|
||||
<h2 style="color: #453227; margin: 20px 0;">Товары в корзине</h2>
|
||||
@@ -49,7 +49,7 @@ use App\Core\View;
|
||||
<div class="empty-cart">
|
||||
<i class="fas fa-shopping-cart" style="font-size: 48px; color: #ccc; margin-bottom: 20px;"></i>
|
||||
<p>Ваша корзина пуста</p>
|
||||
<a href="/cite_practica/catalog" class="btn primary-btn" style="margin-top: 20px; display: inline-block; background: #453227; color: white; padding: 12px 30px; border-radius: 4px; text-decoration: none;">
|
||||
<a href="/catalog" class="btn primary-btn" style="margin-top: 20px; display: inline-block; background: #453227; color: white; padding: 12px 30px; border-radius: 4px; text-decoration: none;">
|
||||
Продолжить покупки
|
||||
</a>
|
||||
</div>
|
||||
@@ -60,7 +60,17 @@ use App\Core\View;
|
||||
<?php foreach ($cartItems as $item): ?>
|
||||
<div class="products__item" data-product-id="<?= $item['product_id'] ?>" data-price="<?= $item['price'] ?>">
|
||||
<div class="products__image">
|
||||
<img src="/cite_practica/<?= htmlspecialchars($item['image_url'] ?? 'img/1.jpg') ?>"
|
||||
<?php
|
||||
$cartImageUrl = $item['image_url'] ?? '';
|
||||
if (empty($cartImageUrl)) {
|
||||
$cartImageUrl = '/assets/images/1.jpg';
|
||||
} elseif (strpos($cartImageUrl, '/img2/') === 0) {
|
||||
$cartImageUrl = str_replace('/img2/', '/assets/images/', $cartImageUrl);
|
||||
} elseif (strpos($cartImageUrl, 'img2/') === 0) {
|
||||
$cartImageUrl = str_replace('img2/', '/assets/images/', $cartImageUrl);
|
||||
}
|
||||
?>
|
||||
<img src="<?= htmlspecialchars($cartImageUrl) ?>"
|
||||
alt="<?= htmlspecialchars($item['name']) ?>">
|
||||
</div>
|
||||
<div class="products__details">
|
||||
@@ -170,13 +180,12 @@ use App\Core\View;
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Обновление количества
|
||||
$('.products__qty-btn').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
const productId = $(this).data('id');
|
||||
const isPlus = $(this).hasClass('plus');
|
||||
const $qtyValue = $(this).siblings('.products__qty-value');
|
||||
let quantity = parseInt($qtyValue.text());
|
||||
var productId = $(this).data('id');
|
||||
var isPlus = $(this).hasClass('plus');
|
||||
var $qtyValue = $(this).siblings('.products__qty-value');
|
||||
var quantity = parseInt($qtyValue.text());
|
||||
|
||||
if (isPlus) { quantity++; }
|
||||
else if (quantity > 1) { quantity--; }
|
||||
@@ -185,7 +194,7 @@ $(document).ready(function() {
|
||||
$qtyValue.text(quantity);
|
||||
|
||||
$.ajax({
|
||||
url: '/cite_practica/cart/update',
|
||||
url: '/cart/update',
|
||||
method: 'POST',
|
||||
data: { product_id: productId, quantity: quantity },
|
||||
dataType: 'json',
|
||||
@@ -198,16 +207,15 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
|
||||
// Удаление товара
|
||||
$('.remove-from-cart').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
const productId = $(this).data('id');
|
||||
const $item = $(this).closest('.products__item');
|
||||
var productId = $(this).data('id');
|
||||
var $item = $(this).closest('.products__item');
|
||||
|
||||
if (!confirm('Удалить товар из корзины?')) return;
|
||||
|
||||
$.ajax({
|
||||
url: '/cite_practica/cart/remove',
|
||||
url: '/cart/remove',
|
||||
method: 'POST',
|
||||
data: { product_id: productId },
|
||||
dataType: 'json',
|
||||
@@ -227,31 +235,30 @@ $(document).ready(function() {
|
||||
});
|
||||
|
||||
function updateTotals() {
|
||||
let productsTotal = 0;
|
||||
let totalCount = 0;
|
||||
var productsTotal = 0;
|
||||
var totalCount = 0;
|
||||
|
||||
$('.products__item').each(function() {
|
||||
const price = parseInt($(this).data('price'));
|
||||
const quantity = parseInt($(this).find('.products__qty-value').text());
|
||||
var price = parseInt($(this).data('price'));
|
||||
var quantity = parseInt($(this).find('.products__qty-value').text());
|
||||
productsTotal += price * quantity;
|
||||
totalCount += quantity;
|
||||
});
|
||||
|
||||
const delivery = parseFloat($('input[name="delivery_price"]').val());
|
||||
const discount = parseFloat($('input[name="discount"]').val());
|
||||
const finalTotal = productsTotal + delivery - discount;
|
||||
var delivery = parseFloat($('input[name="delivery_price"]').val());
|
||||
var discount = parseFloat($('input[name="discount"]').val());
|
||||
var finalTotal = productsTotal + delivery - discount;
|
||||
|
||||
$('.products-total').text(productsTotal.toLocaleString('ru-RU') + ' ₽');
|
||||
$('.summary-count').text(totalCount);
|
||||
$('.final-total').text(finalTotal.toLocaleString('ru-RU') + ' ₽');
|
||||
}
|
||||
|
||||
// Промокод
|
||||
$('#applyPromo').click(function() {
|
||||
const promoCode = $('#promo_code').val().toUpperCase();
|
||||
var promoCode = $('#promo_code').val().toUpperCase();
|
||||
if (promoCode === 'SALE10') {
|
||||
const productsTotal = parseFloat($('.products-total').text().replace(/[^0-9]/g, ''));
|
||||
const discount = Math.round(productsTotal * 0.1);
|
||||
var productsTotal = parseFloat($('.products-total').text().replace(/[^0-9]/g, ''));
|
||||
var discount = Math.round(productsTotal * 0.1);
|
||||
$('input[name="discount"]').val(discount);
|
||||
$('.discount-total').text(discount.toLocaleString('ru-RU') + ' ₽');
|
||||
showNotification('Промокод применен! Скидка 10%');
|
||||
@@ -266,7 +273,6 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
|
||||
// Оформление заказа
|
||||
$('#orderForm').submit(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -278,7 +284,7 @@ $(document).ready(function() {
|
||||
$('#submit-order').prop('disabled', true).text('ОБРАБОТКА...');
|
||||
|
||||
$.ajax({
|
||||
url: '/cite_practica/order',
|
||||
url: '/order',
|
||||
method: 'POST',
|
||||
data: $(this).serialize(),
|
||||
dataType: 'json',
|
||||
@@ -286,7 +292,7 @@ $(document).ready(function() {
|
||||
if (result.success) {
|
||||
showNotification('Заказ успешно оформлен!');
|
||||
setTimeout(function() {
|
||||
window.location.href = '/cite_practica/';
|
||||
window.location.href = '/';
|
||||
}, 1500);
|
||||
} else {
|
||||
showNotification('Ошибка: ' + result.message, 'error');
|
||||
@@ -301,4 +307,3 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user