-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Se agrego livewire con componente para actualizar carro
- Loading branch information
1 parent
f267209
commit d22eb69
Showing
8 changed files
with
232 additions
and
94 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,35 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use Livewire\Component; | ||
use Cart; | ||
|
||
class CartUpdateForm extends Component | ||
{ | ||
public $item = []; | ||
public $quantity = 0; | ||
|
||
public function mount($item) | ||
{ | ||
$this->item = $item; | ||
$this->quantity = $item['quantity']; | ||
} | ||
|
||
public function updateCart() | ||
{ | ||
Cart::session(auth()->id())->update($this->item['id'],[ | ||
'quantity' => array( | ||
'relative' => false, | ||
'value' => $this->quantity | ||
) | ||
]); | ||
|
||
$this->emit('cartUpdated'); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.cart-update-form'); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use Livewire\Component; | ||
use Cart; | ||
|
||
class MallCart extends Component | ||
{ | ||
public $cartItems = []; | ||
|
||
protected $listeners = ['cartUpdated' => 'onCartUpdate']; | ||
|
||
public function mount() | ||
{ | ||
$this->cartItems = Cart::session(auth()->id())->getContent()->toArray(); | ||
} | ||
|
||
public function onCartUpdate() | ||
{ | ||
//$this->cartItems = Cart::session(auth()->id())->getContent()->toArray(); | ||
$this->mount(); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.mall-cart'); | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,6 @@ | ||
<div> | ||
<form wire:submit.prevent="updateCart"> | ||
<input type="number" wire:model="quantity" wire:change="updateCart"> | ||
{{-- <input type="submit" class="button" value="Save"> --}} | ||
</form> | ||
</div> |
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,67 @@ | ||
<div> | ||
<!-- shopping-cart-area start --> | ||
<div class="cart-main-area pt-50 pb-100"> | ||
<div class="container"> | ||
<div class="section-title-4 text-center mb-40"> | ||
<h2>Cart</h2> | ||
</div> | ||
<div class="row"> | ||
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> | ||
<div class="table-content table-responsive"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>remove</th> | ||
<th>images</th> | ||
<th>Product</th> | ||
<th>Price</th> | ||
<th>Quantity</th> | ||
<th>Total</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach ($cartItems as $item) | ||
<tr> | ||
<td class="product-remove"><a href="{{ route('cart.destroy', $item['id']) }}"><i class="pe-7s-close"></i></a></td> | ||
<td class="product-thumbnail"> | ||
<a href="#"><img src="assets/img/cart/1.jpg" alt=""></a> | ||
</td> | ||
<td class="product-name"><a href="#">{{ $item['name'] }} </a></td> | ||
<td class="product-price-cart"><span class="amount">${{ Cart::session(auth()->id())->get($item['id'])->price }}</span></td> | ||
<td class="product-quantity"> | ||
<livewire:cart-update-form :item="$item" :key="$item['id']" /> | ||
</td> | ||
<td class="product-subtotal">${{ Cart::session(auth()->id())->get($item['id'])->getPriceSum() }}</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
<div class="row"> | ||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> | ||
<div class="coupon-all"> | ||
<div class="coupon"> | ||
<h4>Have you a coupon?</h4> | ||
<form action="{{route('cart.coupon')}}" method="get"> | ||
<input id="coupon_code" class="input-text" name="coupon_code" placeholder="Coupon code" type="text"> | ||
<input class="button" name="apply_coupon" value="Apply coupon" type="submit"> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-md-6 ml-auto"> | ||
<div class="cart-page-total" style="padding-top:30px;"> | ||
<h2>Cart totals</h2> | ||
<ul> | ||
<li>Subtotal<span>{{ Cart::session(auth()->id())->getSubTotal() }}</span></li> | ||
<li>Total<span>{{ Cart::session(auth()->id())->getTotal() }}</span></li> | ||
</ul> | ||
<a href="{{ route('cart.checkout') }}">Proceed to checkout</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |