-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement shopping cart UI with Livewire int
- Loading branch information
1 parent
771c4f2
commit 400a8d5
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |