Я хочу, чтобы два или более товара были частью одной строки в таблице корзины (один и тот же идентификатор) [дубликат]Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Я хочу, чтобы два или более товара были частью одной строки в таблице корзины (один и тот же идентификатор) [дубликат]

Сообщение Anonymous »

Я хочу, чтобы два или более товара находились в одной строке в таблице корзины (с одним и тем же идентификатором).
Я хотел, чтобы два или более выбранных товара отображались в корзине как один заказ, т. е. один идентификатор, охватывающий только одну строку таблицы.
при выборе элементов в items.blade.php он должен отображаться как идентификатор в card.blade.php, составляя только одна строка таблицы
вот код (items.blade.php)

Код: Выделить всё





Selecionar Itens




[url={{ route(]Início[/url]
[url={{route(]Login[/url]



body {
font-family: Arial, sans-serif;
}
.container {
width: 80%;
margin: auto;
padding: 20px;
background-color: #f9f9f9;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
.table th, .table td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
.table th {
background-color: #f4f4f4;
}
.quantity-input {
width: 60px;
text-align: right;
}
.btn-primary {
display: inline-block;
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 4px;
cursor: pointer;
text-decoration: none;
}
.btn-primary:hover {
background-color: #0056b3;
}
.total-container {
margin-top: 20px;
padding: 10px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 18px;
text-align: center;
}
img{
width: 150px;
}




Escolha seus itens


@csrf





Prato
Preço
Quantidade



@foreach($items as $item)





@if ($item->image)
[img]{{ url([/img]
image}") }}" alt="{{ $item->title }}">
@endif

{{ $item->title }}
R$ {{ number_format($item->price, 2, ',', '.') }}


@endforeach

Total: R$ 0,00

Calcular Total
Agendar Pedido


function toggleQuantityInput(checkbox, itemId) {
var quantityInput = document.getElementById('quantity-' + itemId);
if (checkbox.checked) {
quantityInput.disabled = false;
} else {
quantityInput.disabled = true;
}
}

$('#calculateTotal').on('click', function() {
let total = 0;

$('.item-checkbox:checked').each(function() {
const row = $(this).closest('tr');
const quantityInput = row.find('.quantity-input');
const quantity = parseInt(quantityInput.val()) || 1;
const price = parseFloat($(this).data('price').toString().replace(',', '.'));

total += quantity * price;
});

$('#total').text(total.toFixed(2).replace('.', ','));
});


function showAlert() {
alert('O seu pedido foi agendado!');
}





cart.blade.php

Код: Выделить всё

@extends('layouts.app')

@section('content')









[url={{ route(]Início[/url]
[url={{route(]Login[/url]



Carrinho de Compras

@if(session('success'))
{{ session('success') }}
@endif

@if(session('error'))
{{ session('error') }}
@endif

@if ($orders && count($orders) > 0)




[url={{ route(]Adicionar itens ao carrinho[/url]
[url={{ route(] 'id', 'sortDirection' => $sortDirection]) }}">ID do Pedido[/url]

[url={{ route(] 'item_name', 'sortDirection' => $sortDirection]) }}">Nome do Item[/url]
[url={{ route(] 'quantity', 'sortDirection' => $sortDirection]) }}">Quantidade[/url]
[url={{ route(] 'price', 'sortDirection' => $sortDirection]) }}">Preço[/url]
[url={{ route(] 'price', 'sortDirection' => $sortDirection]) }}">Total[/url]




@foreach($orders as $order)

{{ $order->id }}

@if ($order->image)

[img]{{ asset([/img]
image) }}" alt="{{ $order->item_name }}" style="width: 100px; height: auto;">
@else
Imagem não disponível
@endif

{{ $order->item_name }}
{{ $order->quantity }}x
{{ $order->price }},00
{{ $order->total }},00


@csrf
@method('DELETE')
Remover



@endforeach



h2{
color:white;
}
.page, .table{
width:800px;
position:relative;
}

[h4]Total: {{ number_format($total, 2, ',', '.') }}[/h4]
Realizar Pagamento
Cancelar Pedido

@else
Seu carrinho está vazio.
@endif
@endsection
Itemcontroller.php

Код: Выделить всё


Подробнее здесь: [url]https://stackoverflow.com/questions/79138811/i-want-to-make-two-or-more-items-make-part-of-the-same-line-in-cart-table-same[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»