Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task#80295] Inplement checkout page and logic #54

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ecommerce-app/.php-cs-fixer.cache

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function store(LoginRequest $request): RedirectResponse

$request->session()->regenerate();

return redirect()->intended(route('dashboard.index', absolute: false));
return redirect()->intended(route('home.index', absolute: false));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ public function store(RegisterRequest $request): RedirectResponse
$user->telephone = $request->telephone;
$user->is_admin = false;

/*
if ($request->hasFile('photo')) {
$avatar = new ImageController();
$imageUrl = $avatar->storeImage($request, 'profile');
$user->photo = $imageUrl;
}
*/

$user->save();

Expand Down
15 changes: 0 additions & 15 deletions ecommerce-app/app/Http/Controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ public function show()

$products = Product::with('userReviews')->withAvg('userReviews', 'rating')->withCount('userReviews')->take(3)->get()->sortByDesc(['trendRating']);

/*
if (session("card_id")) {
$cart = ShoppingCart::find(session("card_id"));
$cart_items = $cart->shoppingCartItems()->orderBy("id", "desc")->get()->all();
//$order_items = $cart->products()->orderBy("id", "desc")->get()->all();

return view("cart", ["cart" => $cart, "cart_items" => $cart_items]);
} else {
$cart = $this->store();
$cart_items = $cart->shoppingCartItems()->orderBy("id", "desc")->get()->all();

return view("cart", ["cart" => $cart, "cart_items" => $cart_items]);
}
*/

return view("cart", ["cart" => $cart, "cart_items" => $cart_items, "trend_items" => $products]);
}

Expand Down
20 changes: 13 additions & 7 deletions ecommerce-app/app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\ProductCategory;
use App\Http\Requests\CategoryRequest;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
Expand All @@ -13,6 +12,12 @@ class CategoryController extends Controller
// $categories = ProductCategory::all();
// return view('admin.categories.index',compact('categories'));
// }
public function index()
{
$categories = ProductCategory::all();

return view('admin.categories.index', compact('categories'));
}

public function create()
{
Expand All @@ -32,7 +37,8 @@ public function store(CategoryRequest $request)
public function edit($id)
{
$category = ProductCategory::findOrFail($id);
return view('admin.categories.edit',compact('category'));

return view('admin.categories.edit', compact('category'));
}

public function update(CategoryRequest $request, $id)
Expand All @@ -43,16 +49,16 @@ public function update(CategoryRequest $request, $id)

$category->update($validated);

return redirect()->route('/admin')
->with('success','Category updated successfully');
return redirect()->route('categories.index')
->with('success', 'Category updated successfully');
}

public function destroy($id)
{
$category = ProductCategory::findOrFail($id);
$category->delete();

return redirect()->route('/admin')
->with('success','Category deleted successfully');
return redirect()->route('categories.index')
->with('success', 'Category deleted successfully');
}
}
190 changes: 95 additions & 95 deletions ecommerce-app/app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
<?php

namespace App\Http\Controllers;
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\ViewedProduct;
use App\Models\ProductCategory;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\ViewedProduct;
use App\Models\ProductCategory;
use Illuminate\Support\Facades\Auth;

class DashboardController extends Controller
class DashboardController extends Controller
{
public function index(Request $request)
{
public function index(Request $request)
{
$query = Product::with('category')
->withAvg('userReviews', 'rating')
->withCount('userReviews');
$trendingProducts = Product::with('userReviews')
->withAvg('userReviews', 'rating')
->withCount('userReviews')
->get()
->sortByDesc('user_reviews_avg_rating') // Sort by average rating (highest first)
->take(6); // Limit the trending products to 6 items
$categories = ProductCategory::withCount('products')->get();
$sort = $request->input('sort');
switch ($sort) {
case 'az':
$query->orderBy('name', 'ASC');
break;
case 'za':
$query->orderBy('name', 'DESC');
break;
case 'low-high':
$query->orderBy('price', 'ASC');
break;
case 'high-low':
$query->orderBy('price', 'DESC');
break;
case 'rating-low-high':
$query->orderBy('user_reviews_avg_rating', 'asc');
break;
case 'rating-high-low':
$query->orderBy('user_reviews_avg_rating', 'desc');
break;
}
$filterCategories = $request->input('categories');
if ($filterCategories && is_array($filterCategories)) {
$query->whereIn('product_category_id', $filterCategories);
}

$search = $request->input('search');




// Filter by category

if ($search)
{
$query->where('name', 'LIKE', '%' . $search . '%');
}


// them truong rating khi lay data sp
// case $sortRating === 'low-high':
// $query->orderBy('rating', 'asc');
// break;
// case $sortRating === 'high-low':
// $query->orderBy('rating', 'desc');
// break;


$products = $query->paginate(15);;
$recentlyViewedProducts = collect();
if (Auth::check()) {
$recentlyViewedProducts = ViewedProduct::where('user_id', Auth::id())
->with('product')
->orderBy('viewed_at', 'desc')
->take(5)
->get();
}
return view('dashboard', [
'products' => $products,
'categories' => $categories,
'recentlyViewedProducts' => $recentlyViewedProducts,
'trendingProducts' => $trendingProducts,
]);
$query = Product::with('category')
->withAvg('userReviews', 'rating')
->withCount('userReviews');
$trendingProducts = Product::with('userReviews')
->withAvg('userReviews', 'rating')
->withCount('userReviews')
->get()
->sortByDesc('user_reviews_avg_rating') // Sort by average rating (highest first)
->take(6); // Limit the trending products to 6 items
$categories = ProductCategory::withCount('products')->get();
$sort = $request->input('sort');
switch ($sort) {
case 'az':
$query->orderBy('name', 'ASC');
break;
case 'za':
$query->orderBy('name', 'DESC');
break;
case 'low-high':
$query->orderBy('price', 'ASC');
break;
case 'high-low':
$query->orderBy('price', 'DESC');
break;
case 'rating-low-high':
$query->orderBy('user_reviews_avg_rating', 'asc');
break;
case 'rating-high-low':
$query->orderBy('user_reviews_avg_rating', 'desc');
break;
}
$filterCategories = $request->input('categories');
if ($filterCategories && is_array($filterCategories)) {
$query->whereIn('product_category_id', $filterCategories);
}

$search = $request->input('search');

public function search(Request $request)
{
$search = $request->input('search');

if ($search)
{
$products = DB::table('products')->where('name', $search)->get();
return view('dashboard', [
'products' => $products,
]);
}

$products = Product::all();

// Filter by category

if ($search) {
$query->where('name', 'LIKE', '%' . $search . '%');
}


// them truong rating khi lay data sp
// case $sortRating === 'low-high':
// $query->orderBy('rating', 'asc');
// break;
// case $sortRating === 'high-low':
// $query->orderBy('rating', 'desc');
// break;


$products = $query->paginate(15);
;
$recentlyViewedProducts = collect();
if (Auth::check()) {
$recentlyViewedProducts = ViewedProduct::where('user_id', Auth::id())
->with('product')
->orderBy('viewed_at', 'desc')
->take(5)
->get();
}
return view('dashboard', [
'products' => $products,
'categories' => $categories,
'recentlyViewedProducts' => $recentlyViewedProducts,
'trendingProducts' => $trendingProducts,
]);
}

public function search(Request $request)
{
$search = $request->input('search');

if ($search) {
$products = DB::table('products')->where('name', $search)->get();
return view('dashboard', [
'products' => $products,
]);
}

$products = Product::all();
return view('dashboard', [
'products' => $products,
]);
}
}

49 changes: 49 additions & 0 deletions ecommerce-app/app/Http/Controllers/GoogleAuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Http\Controllers;

use App\Models\User;

use Hash;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

use Laravel\Socialite\Facades\Socialite;

class GoogleAuthController extends Controller
{
public function redirect()
{
return Socialite::driver('google')->redirect();
}

public function callbackGoogle()
{
try {
$google_user = Socialite::driver('google')->user();
$user = User::where('google_id', $google_user->getId())->first();

if (!$user) {
$new_user = User::create([
'username' => $google_user->getName(),
'password' => Hash::make('123456789'),
'first_name' => "",
'last_name' => "",
'email' => $google_user->getEmail(),
'google_id' => $google_user->getId(),
'telephone' => "",
]);

Auth::login($new_user);

return redirect()->intended('dashboard');
} else {
Auth::login($user);

return redirect()->intended('dashboard');
}
} catch (\Throwable $th) {
dd("Something went wrong!" . $th->getMessage());
}
}
}
12 changes: 5 additions & 7 deletions ecommerce-app/app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
namespace App\Http\Controllers;

use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class HomeController extends Controller
{
function __construct()
{
public function __construct() {}

}

public function index()
{
$products = Product::with('userReviews')
->withAvg('userReviews', 'rating')
->withCount('userReviews')
->get()
->sortByDesc(['trendRating']);
// ->orderByDesc(['trendRating'])
->paginate(20);

// dd($products->toArray());

return view('home', [
'user' => Auth::user(),
Expand Down
Loading