Skip to content

Commit

Permalink
Componentes para cupon y cart, categorias en show product
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-ser committed May 23, 2020
1 parent d22eb69 commit bdf7a5b
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 108 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ _PAYPAL_SANDBOX_API_CERTIFICATE=_
## Imagenes demo

### Tienda
![Admin](/public/img/webmall-customer.png)
![Shop](/public/img/webmall-customer.png)
### Carro
![Admin](/public/img/webmall-cart.png)
### Vendedor
![Admin](/public/img/webmall-seller-shop.png)
![Admin](/public/img/webmall-seller-products.png)
### Admistrador
![Cart](/public/img/webmall-cart.png)
### Checkout
![Checkout](/public/img/webmall-checkout.png)
### Create shop
![Create shop](/public/img/webmall-shop.png)
### [**Admin**] Vendedor
![Seller](/public/img/webmall-seller-shop.png)
### [**Admin**] Products
![Seller Products](/public/img/webmall-seller-products.png)
### [**Admin**] Admistrador
![Admin](/public/img/webmall-admin.png)

## Licencia
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function update($rowId)

public function checkout()
{
return view('cart.checkout');
$cartItems = Cart::session(auth()->id())->getContent();

return view('cart.checkout', compact('cartItems'));
}

public function applyCoupon()
Expand Down
40 changes: 40 additions & 0 deletions app/Http/Livewire/ApplyCoupon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Livewire;

use Cart;
use App\Coupon;
use Livewire\Component;

class ApplyCoupon extends Component
{
public $couponCode = '';

public function applyCoupon()
{
$couponCode = $this->couponCode;

$couponData = Coupon::where('code', $couponCode)->first();

if (!$couponData) {
$this->emit('cartUpdated', 'error', 'Coupon does not exist');
} else {
// coupon logic
$condition = new \Darryldecode\Cart\CartCondition(array(
'name' => $couponData->name,
'type' => $couponData->type,
'target' => 'total', // this condition will be applied to cart's subtotal when getSubTotal() is called.
'value' => $couponData->value,
));

Cart::session(auth()->id())->condition($condition); // for a speicifc user's cart

$this->emit('cartUpdated', 'message', 'Coupon applied!');
}
}

public function render()
{
return view('livewire.apply-coupon');
}
}
21 changes: 21 additions & 0 deletions app/Http/Livewire/CartBox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Cart;

class CartBox extends Component
{
public $cartItems = [];

public function mount()
{
$this->cartItems = Cart::session(auth()->id())->getContent()->toArray();
}

public function render()
{
return view('livewire.cart-box');
}
}
2 changes: 1 addition & 1 deletion app/Http/Livewire/CartUpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function updateCart()
)
]);

$this->emit('cartUpdated');
$this->emit('cartUpdated', 'message', 'Cart updated');
}

public function render()
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Livewire/MallCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function mount()
$this->cartItems = Cart::session(auth()->id())->getContent()->toArray();
}

public function onCartUpdate()
public function onCartUpdate($type ,$msg)
{
//$this->cartItems = Cart::session(auth()->id())->getContent()->toArray();
session()->flash($type, $msg);
$this->mount();
}

Expand Down
5 changes: 5 additions & 0 deletions app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public function shop()
{
return $this->belongsTo(Shop::class, 'shop_id');
}

public function categories()
{
return $this->belongsToMany(Category::class, 'product_categories');
}
}
15 changes: 15 additions & 0 deletions public/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,20 @@
margin-bottom: 0px;
padding-bottom: 0px;
}
.single-product-cart img {
object-fit: cover;
width: 85px;
height: 80px;
}
.cart-delete {
display: flex;
flex-grow: 100;
justify-content: flex-end;
flex-direction: column;
align-items: end;
}
.cart-delete input {
width: 50px;
}
.cart-title {
margin: 19px 0 0 15px;
Expand Down Expand Up @@ -6693,6 +6703,11 @@ h1.cart-heading {
.table-content table td.product-thumbnail {
width: 130px;
}
.table-content table td.product-thumbnail img {
object-fit: cover;
width: 80px;
height: 100px;
}
.table-content table td.product-remove i {
color: #919191;
display: inline-block;
Expand Down
Binary file modified public/img/webmall-cart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/webmall-checkout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/img/webmall-customer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/webmall-shop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 6 additions & 27 deletions resources/views/cart/checkout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,25 @@
</tr>
</thead>
<tbody>
@foreach ($cartItems as $item)
<tr class="cart_item">
<td class="product-name">
Vestibulum suscipit <strong class="product-quantity"> × 1</strong>
{{ $item['name'] }} <strong class="product-quantity"> × {{ $item['quantity'] }}</strong>
</td>
<td class="product-total">
<span class="amount">£165.00</span>
</td>
</tr>
<tr class="cart_item">
<td class="product-name">
Vestibulum dictum magna <strong class="product-quantity"> × 1</strong>
</td>
<td class="product-total">
<span class="amount">£50.00</span>
<span class="amount">${{ Cart::session(auth()->id())->get($item['id'])->getPriceSum() }}</span>
</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr class="cart-subtotal">
<th>Cart Subtotal</th>
<td><span class="amount">£215.00</span></td>
<td><span class="amount">${{ Cart::session(auth()->id())->getSubTotal() }}</span></td>
</tr>
<tr class="order-total">
<th>Order Total</th>
<td><strong><span class="amount">£215.00</span></strong>
<td><strong><span class="amount">${{ Cart::session(auth()->id())->getTotal() }}</span></strong>
</td>
</tr>
</tfoot>
Expand All @@ -115,21 +109,6 @@
</div>
</form>
</div>
{{-- <div class="row">
<div class="col-lg-6 col-md-6">
<div class="your-order floatright">
<h3>Have a coupon?</h3>
<div class="coupon-info">
<form action="#">
<p class="checkout-coupon">
<input type="text" placeholder="Coupon code" />
<input type="submit" value="Apply Coupon" />
</p>
</form>
</div>
</div>
</div>
</div> --}}
</div>
</div>
<!-- checkout-area end -->
Expand Down
54 changes: 1 addition & 53 deletions resources/views/layouts/front.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,59 +130,7 @@
<a href="{{ route('cart.index') }}">
My Cart<br> {{ Cart::session(auth()->id())->getContent()->count() }} Item
</a>
<ul class="cart-dropdown">
<li class="single-product-cart">
<div class="cart-img">
<a href="#"><img src="assets/img/cart/1.jpg" alt=""></a>
</div>
<div class="cart-title">
<h5><a href="#"> Bits Headphone</a></h5>
<h6><a href="#">Black</a></h6>
<span>$80.00 x 1</span>
</div>
<div class="cart-delete">
<a href="#"><i class="ti-trash"></i></a>
</div>
</li>
<li class="single-product-cart">
<div class="cart-img">
<a href="#"><img src="assets/img/cart/2.jpg" alt=""></a>
</div>
<div class="cart-title">
<h5><a href="#"> Bits Headphone</a></h5>
<h6><a href="#">Black</a></h6>
<span>$80.00 x 1</span>
</div>
<div class="cart-delete">
<a href="#"><i class="ti-trash"></i></a>
</div>
</li>
<li class="single-product-cart">
<div class="cart-img">
<a href="#"><img src="assets/img/cart/3.jpg" alt=""></a>
</div>
<div class="cart-title">
<h5><a href="#"> Bits Headphone</a></h5>
<h6><a href="#">Black</a></h6>
<span>$80.00 x 1</span>
</div>
<div class="cart-delete">
<a href="#"><i class="ti-trash"></i></a>
</div>
</li>
<li class="cart-space">
<div class="cart-sub">
<h4>Subtotal</h4>
</div>
<div class="cart-price">
<h4>$240.00</h4>
</div>
</li>
<li class="cart-btn-wrapper">
<a class="cart-btn btn-hover" href="{{route('cart.index')}}">View cart</a>
<a class="cart-btn btn-hover" href="{{route('cart.checkout')}}">Checkout</a>
</li>
</ul>
<livewire:cart-box />
@else
<a href="{{ route('cart.index') }}">
My Cart<br> 0 Item
Expand Down
12 changes: 12 additions & 0 deletions resources/views/livewire/apply-coupon.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div>
<div class="coupon-all">
<div class="coupon">
<h4>Have you a coupon?</h4>
<form wire:submit.prevent="applyCoupon">
<input id="coupon_code" class="input-text" name="coupon_code" placeholder="Coupon code" type="text"
wire:model="couponCode">
<input class="button" name="apply_coupon" value="Apply coupon" type="submit">
</form>
</div>
</div>
</div>
30 changes: 30 additions & 0 deletions resources/views/livewire/cart-box.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div>
<ul class="cart-dropdown">
@if (count($cartItems) > 0 )
@foreach ($cartItems as $item)
<li class="single-product-cart">
<div class="cart-img">
<a href="{{ route('product.show', $item['id']) }}"><img src="{{ asset('img/'.$item['associatedModel']['cover_img']) }}" alt=""></a>
</div>
<div class="cart-title">
<h5><a href="{{ route('product.show', $item['id']) }}">{{ $item['name'] }}</a></h5>
<span>${{ Cart::session(auth()->id())->get($item['id'])->price }} x {{ $item['quantity'] }}</span>
</div>
<div class="cart-delete">
<livewire:cart-update-form :item="$item" :key="$item['id']" />
<a href="{{ route('cart.destroy', $item['id']) }}"><i class="ti-trash"></i></a>
</div>
</li>
@endforeach
@else
<li class="single-product-cart">
<h5 class="text-center">Add produts to the cart</h5>
</li>
@endif

<li class="cart-btn-wrapper">
<a class="cart-btn btn-hover" href="{{route('cart.index')}}">View cart</a>
<a class="cart-btn btn-hover" href="{{route('cart.checkout')}}">Checkout</a>
</li>
</ul>
</div>
Loading

0 comments on commit bdf7a5b

Please sign in to comment.