updated cart functions
Cette révision appartient à :
Parent
daa0d53b01
révision
43310ba237
@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\Course;
|
use App\Models\Course;
|
||||||
|
use App\Models\CourseCategory;
|
||||||
|
|
||||||
class CartController extends Controller
|
class CartController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$courses = Course::all();
|
$course = Course::all();
|
||||||
return view('frontend.searchCourse', compact('courses', 'category'));
|
$category= CourseCategory::all();
|
||||||
|
return view('frontend.searchCourse', compact('course', 'category'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cart()
|
public function cart()
|
||||||
@ -31,7 +33,9 @@ public function addToCart($id)
|
|||||||
"title_en" => $course->title_en,
|
"title_en" => $course->title_en,
|
||||||
"quantity" => 1,
|
"quantity" => 1,
|
||||||
"price" => $course->price,
|
"price" => $course->price,
|
||||||
"image" => $course->image
|
"old_price" => $course->old_price,
|
||||||
|
"image" => $course->image,
|
||||||
|
"instructor" => $course->instructor ? $course->instructor->name_en : 'Unknown Instructor',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +53,18 @@ public function update(Request $request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public function remove(Request $request)
|
||||||
|
// {
|
||||||
|
// if ($request->id) {
|
||||||
|
// $cart = session()->get('cart');
|
||||||
|
// if (isset($cart[$request->id])) {
|
||||||
|
// unset($cart[$request->id]);
|
||||||
|
// session()->put('cart', $cart);
|
||||||
|
// }
|
||||||
|
// session()->flash('success', 'Product removed successfully');
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
public function remove(Request $request)
|
public function remove(Request $request)
|
||||||
{
|
{
|
||||||
if ($request->id) {
|
if ($request->id) {
|
||||||
@ -57,7 +73,9 @@ public function remove(Request $request)
|
|||||||
unset($cart[$request->id]);
|
unset($cart[$request->id]);
|
||||||
session()->put('cart', $cart);
|
session()->put('cart', $cart);
|
||||||
}
|
}
|
||||||
session()->flash('success', 'Product removed successfully');
|
return response()->json(['success' => true], 200);
|
||||||
}
|
}
|
||||||
|
return response()->json(['error' => 'Invalid request'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
@extends('frontend.layouts.app')
|
@extends('frontend.layouts.app')
|
||||||
@section('body-attr') style="background-color: #ebebf2;" @endsection
|
@section('body-attr')
|
||||||
|
style="background-color: #ebebf2;"
|
||||||
|
@endsection
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<!-- Breadcrumb Starts Here -->
|
<!-- Breadcrumb Starts Here -->
|
||||||
<div class="py-0">
|
<div class="py-0">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
|
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
|
||||||
<ol class="breadcrumb align-items-center bg-transparent mb-0">
|
<ol class="breadcrumb align-items-center bg-transparent mb-0">
|
||||||
@ -12,33 +14,35 @@
|
|||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Breadcrumb Ends Here -->
|
<!-- Breadcrumb Ends Here -->
|
||||||
|
|
||||||
<!-- Cart Section Starts Here -->
|
<!-- Cart Section Starts Here -->
|
||||||
<section class="section cart-area">
|
<section class="section cart-area">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-8">
|
||||||
<h6 class="cart-area__label">2 Courses in Cart</h6>
|
<h6 class="cart-area__label">2 Courses in Cart</h6>
|
||||||
@php $total = 0 @endphp
|
@php $total = 0 @endphp
|
||||||
@if(session('cart'))
|
@if (session('cart'))
|
||||||
@foreach(session('cart') as $id => $details)
|
@foreach (session('cart') as $id => $details)
|
||||||
@php $total += $details['price'] * $details['quantity'] @endphp
|
@php $total += $details['price'] * $details['quantity'] @endphp
|
||||||
<div class="cart-wizard-area">
|
<div class="cart-wizard-area">
|
||||||
<div class="image">
|
<div class="image">
|
||||||
<img src="{{ $details['image'] }}" alt="product" />
|
<img src="{{ asset('public/uploads/courses/' . $details['image']) }}"
|
||||||
|
alt="course image" />
|
||||||
</div>
|
</div>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
<h6><a href="#">{{ $details['title_en'] }}</a></h6>
|
<h6><a href="#">{{ $details['title_en'] }}</a></h6>
|
||||||
<p>By <a href="#">Kevin Gilbert</a></p>
|
<p>By <a href="#">{{ $details['instructor'] }}</a></p>
|
||||||
<div class="bottom-wizard d-flex justify-content-between align-items-center">
|
<div class="bottom-wizard d-flex justify-content-between align-items-center">
|
||||||
<p>
|
<p>
|
||||||
${{ $details['price'] }} <span><del>$24.99</del></span>
|
{{ $details['price'] ? '$' . $details['price'] : 'Free' }}
|
||||||
|
<span><del>{{ $details['old_price'] ? '$' . $details['old_price'] : '' }}</del></span>
|
||||||
</p>
|
</p>
|
||||||
<div class="trash-icon">
|
<div class="trash-icon">
|
||||||
<a href="#">
|
<a href="#" class="remove-from-cart" data-id="{{ $id }}">
|
||||||
<i class="far fa-trash-alt"></i>
|
<i class="far fa-trash-alt remove-from-cart"></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -52,19 +56,19 @@
|
|||||||
<div class="summery-wizard">
|
<div class="summery-wizard">
|
||||||
<div class="summery-wizard-text pt-0">
|
<div class="summery-wizard-text pt-0">
|
||||||
<h6>Subtotal</h6>
|
<h6>Subtotal</h6>
|
||||||
<p>$49.99</p>
|
<p>{{ '$' . number_format((float) $total, 2) }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="summery-wizard-text">
|
<div class="summery-wizard-text">
|
||||||
<h6>Coupon Discount</h6>
|
<h6>Coupon Discount</h6>
|
||||||
<p>15%</p>
|
<p>0.00%</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="summery-wizard-text">
|
<div class="summery-wizard-text">
|
||||||
<h6>taxes</h6>
|
<h6>taxes</h6>
|
||||||
<p>9.99</p>
|
<p>0.00</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="total-wizard">
|
<div class="total-wizard">
|
||||||
<h6 class="font-title--card">Total:</h6>
|
<h6 class="font-title--card">Total:</h6>
|
||||||
<p class="font-title--card">$36.49</p>
|
<p class="font-title--card">{{ '$' . number_format((float) $total, 2) }}</p>
|
||||||
</div>
|
</div>
|
||||||
<form action="#">
|
<form action="#">
|
||||||
<a href="checkout.html"
|
<a href="checkout.html"
|
||||||
@ -79,14 +83,14 @@ class="button button-lg button--primary form-control mb-lg-3">Checkout</a>
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<!-- Cart Section Ends Here -->
|
<!-- Cart Section Ends Here -->
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|
||||||
@section('scripts')
|
@push('scripts')
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(".update-cart").change(function (e) {
|
$(".update-cart").change(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var ele = $(this);
|
var ele = $(this);
|
||||||
@ -99,31 +103,30 @@ class="button button-lg button--primary form-control mb-lg-3">Checkout</a>
|
|||||||
id: ele.parents("tr").attr("data-id"),
|
id: ele.parents("tr").attr("data-id"),
|
||||||
quantity: ele.parents("tr").find(".quantity").val()
|
quantity: ele.parents("tr").find(".quantity").val()
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function(response) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".remove-from-cart").click(function (e) {
|
$(".remove-from-cart").click(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var ele = $(this);
|
var ele = $(this);
|
||||||
|
|
||||||
if(confirm("Are you sure want to remove?")) {
|
if (confirm("Are you sure want to remove?")) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '{{ route('remove.from.cart') }}',
|
url: '{{ route('remove.from.cart') }}',
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
data: {
|
data: {
|
||||||
_token: '{{ csrf_token() }}',
|
_token: '{{ csrf_token() }}',
|
||||||
id: ele.parents("tr").attr("data-id")
|
id: ele.data('id') // Use data-id attribute
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function(response) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
</script>
|
||||||
</script>
|
@endpush
|
||||||
@endsection
|
|
||||||
|
|||||||
@ -126,3 +126,4 @@
|
|||||||
Route::get('add-to-cart/{id}', [CartController::class, 'addToCart'])->name('add.to.cart');
|
Route::get('add-to-cart/{id}', [CartController::class, 'addToCart'])->name('add.to.cart');
|
||||||
Route::patch('update-cart', [CartController::class, 'update'])->name('update.cart');
|
Route::patch('update-cart', [CartController::class, 'update'])->name('update.cart');
|
||||||
Route::delete('remove-from-cart', [CartController::class, 'remove'])->name('remove.from.cart');
|
Route::delete('remove-from-cart', [CartController::class, 'remove'])->name('remove.from.cart');
|
||||||
|
|
||||||
|
|||||||
Chargement…
Référencer dans un nouveau ticket
Block a user