Skip to content

Commit

Permalink
feat: Implement shopping cart UI with Livewire int
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 11, 2024
1 parent 771c4f2 commit 400a8d5
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions resources/views/livewire/shopping-cart.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div>
<h2>Shopping Cart</h2>
@if(count($items) > 0)
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($items as $id => $item)
<tr>
<td>{{ $item['name'] }}</td>
<td>${{ number_format($item['price'], 2) }}</td>
<td>
<input type="number" wire:model.lazy="items.{{ $id }}.quantity" wire:change="updateQuantity('{{ $id }}', $event.target.value)">
</td>
<td>${{ number_format($item['price'] * $item['quantity'], 2) }}</td>
<td>
<button wire:click="removeItem('{{ $id }}')">Remove</button>
</td>
</tr>
@endforeach
</tbody>
</table>
<div>
<strong>Total: ${{ number_format(array_reduce($items, function ($carry, $item) {
return $carry + ($item['price'] * $item['quantity']);
}, 0), 2) }}</strong>
</div>
<div>
<button wire:click="clearCart">Clear Cart</button>
</div>
@else
<p>Your cart is empty.</p>
@endif
</div>

0 comments on commit 400a8d5

Please sign in to comment.