diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index a2e3e57..152e74e 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -11,13 +11,7 @@ class ProductController extends Controller public function detail($slug, Request $request, ProductRepository $productRepository) { - $product = Items::where('slug', $slug)->first(); - - - if ($product == null) { - abort(404); - } - + $product = $productRepository->show($slug); $complete_look_products_data = $productRepository->getList([ @@ -25,14 +19,13 @@ class ProductController extends Controller 'limit' => 4, ]); - - $complete_look_products = collect($complete_look_products_data->items())->chunk(2); return view('shop.product-fashion',[ 'product' => $product, - 'complete_look_products' => $complete_look_products + 'complete_look_products' => $complete_look_products, + ]); } } diff --git a/app/Repositories/Catalog/ProductRepository.php b/app/Repositories/Catalog/ProductRepository.php index 89df759..9c9061c 100644 --- a/app/Repositories/Catalog/ProductRepository.php +++ b/app/Repositories/Catalog/ProductRepository.php @@ -30,29 +30,29 @@ class ProductRepository ( discounts.valid_at is null or discounts.expired_at >= now()) order by item_id, discounts.created_at desc ) as d"),"d.item_id","=","items.id") -->when(true, function($query) use ($event, $sort){ -if ($event){ - $query->orderByRaw("case when brand = 'CHAMELO' then 1 else 2 end ASC "); + ->when(true, function($query) use ($event, $sort){ + if ($event){ + $query->orderByRaw("case when brand = 'CHAMELO' then 1 else 2 end ASC "); -$query->orderBy("percent", "desc"); -}else{ + $query->orderBy("percent", "desc"); + }else{ -/* if ($event == "special-offer"){ -$query->orderByRaw("case when brand = 'CHAMELO' then 1 else 2 end ASC "); -} */ + /* if ($event == "special-offer"){ + $query->orderByRaw("case when brand = 'CHAMELO' then 1 else 2 end ASC "); + } */ -if ($sort == "new"){ -\Log::info($sort); + if ($sort == "new"){ + \Log::info($sort); - $query->orderByRaw("case when category1 in ('CLUBS','CLUB','COMPONENT HEAD') and brand = 'PXG' then 1 else 2 end ASC"); -}else{ - $query->orderByRaw("case when d.created_at is not null then 1 else 2 end ASC, random()"); -} + $query->orderByRaw("case when category1 in ('CLUBS','CLUB','COMPONENT HEAD') and brand = 'PXG' then 1 else 2 end ASC"); + }else{ + $query->orderByRaw("case when d.created_at is not null then 1 else 2 end ASC, random()"); + } -// $query->orderByRaw("items.created_at desc NULLS LAST"); -} + // $query->orderByRaw("items.created_at desc NULLS LAST"); + } -}) + }) ->where("is_publish", true) ->when($search, function ($query) use ($search) { $query->where(function ($query) use ($search) { @@ -94,4 +94,34 @@ if ($sort == "new"){ return $builder->paginate($limit); } + + public function show($slug) + { + $product = Items::where('slug', $slug)->first(); + + + + if ($product == null) { + abort(404); + } + + $all = session()->get('viewed_products', []); + $all[] = $product->id; + session()->put('viewed_products', array_unique($all)); + + return $product; + } + + public function viewed_products($except_ids = []) + { + $ids = session()->get('viewed_products', []); + if (empty($ids)) { + return collect(); + } + + // Remove except_ids from the list + $ids = array_diff($ids, (array)$except_ids); + + return Items::whereIn('id', $ids)->inRandomOrder()->take(10)->get(); + } } diff --git a/app/View/Components/Layout/NavbarMenu.php b/app/View/Components/Layout/NavbarMenu.php new file mode 100644 index 0000000..fb5a003 --- /dev/null +++ b/app/View/Components/Layout/NavbarMenu.php @@ -0,0 +1,25 @@ +viewedProducts = $productRepository->viewed_products($except_ids); + + } + + /** + * Get the view/contents that represent the component. + */ + public function render(): View + { + return view('components.shop.viewed-products'); + } +} diff --git a/lang/en/product_fashion.php b/lang/en/product_fashion.php new file mode 100644 index 0000000..5c5c696 --- /dev/null +++ b/lang/en/product_fashion.php @@ -0,0 +1,8 @@ + 'Description', + 'delivery' => 'Delivery', + 'and_returns' => 'and Returns', + 'review' => 'Review' +]; \ No newline at end of file diff --git a/lang/id/product_fashion.php b/lang/id/product_fashion.php new file mode 100644 index 0000000..076ce8b --- /dev/null +++ b/lang/id/product_fashion.php @@ -0,0 +1,8 @@ + 'Deskripsi', + 'delivery' => 'Pengiriman', + 'and_returns' => 'dan Retur', + 'review' => 'Ulasan' +]; \ No newline at end of file diff --git a/resources/views/components/layout/navbar-menu.blade.php b/resources/views/components/layout/navbar-menu.blade.php new file mode 100644 index 0000000..ecb2a12 --- /dev/null +++ b/resources/views/components/layout/navbar-menu.blade.php @@ -0,0 +1,222 @@ + +
diff --git a/resources/views/components/shop/viewed-products.blade.php b/resources/views/components/shop/viewed-products.blade.php new file mode 100644 index 0000000..8be88dd --- /dev/null +++ b/resources/views/components/shop/viewed-products.blade.php @@ -0,0 +1,52 @@ +@if (count($viewedProducts) > 0) +