diff --git a/app/Cart/Item.php b/app/Cart/Item.php index 0004e9a..8481563 100644 --- a/app/Cart/Item.php +++ b/app/Cart/Item.php @@ -20,10 +20,11 @@ class Item public function __construct(Product $product, $qty) { - $this->id = $product->id; - $this->product = $product; - $this->qty = $qty; - $this->price = $product->getPrice(); + $this->id = $product->id; + $this->name = $product->name; + $this->product = $product; + $this->qty = $qty; + $this->price = $product->getPrice(); $this->subtotal = $product->getPrice() * $qty; } diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php new file mode 100755 index 0000000..7c1abc3 --- /dev/null +++ b/app/Helpers/helpers.php @@ -0,0 +1,12 @@ +cart->content()->last(); + $queriedProducts = []; + $draft = $this->cart->content()->first(); - return view('cart.index', compact('draft')); + return view('cart.index', compact('draft','queriedProducts')); } public function show(Request $request, $draftKey) { - $queriedProducts = Product::where(function ($query) use ($request) { - return $query->where('name', 'like', '%'.$request->get('query').'%'); - })->get(); + $query = $request->get('query'); + $queriedProducts = []; + if ($query) { + $queriedProducts = Product::where(function ($q) use ($query) { + $q->where('name', 'like', '%'.$query.'%'); + })->get(); + } $draft = $this->cart->get($draftKey); @@ -59,14 +64,14 @@ class CartController extends Controller { $this->cart->updateDraftItem($draftKey, $request->item_key, $request->only('qty', 'item_discount')); - return redirect()->route('cart.index', $draftKey); + return back(); } public function removeDraftItem(Request $request, $draftKey) { $this->cart->removeItemFromDraft($draftKey, $request->item_index); - return redirect()->route('cart.index', $draftKey); + return back(); } public function empty($draftKey) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 35471f6..ddaae42 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -13,7 +13,7 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - // + require_once app_path() . '/Helpers/helpers.php'; } /** diff --git a/config/app.php b/config/app.php index 288387a..b162354 100644 --- a/config/app.php +++ b/config/app.php @@ -64,7 +64,7 @@ return [ | */ - 'timezone' => 'UTC', + 'timezone' => 'Asia/Jakarta', /* |-------------------------------------------------------------------------- @@ -77,7 +77,7 @@ return [ | */ - 'locale' => 'en', + 'locale' => 'id', /* |-------------------------------------------------------------------------- diff --git a/resources/lang/id/cart.php b/resources/lang/id/cart.php new file mode 100644 index 0000000..19bd903 --- /dev/null +++ b/resources/lang/id/cart.php @@ -0,0 +1,5 @@ + 'Cari Produk' +]; \ No newline at end of file diff --git a/resources/views/cart/index.blade.php b/resources/views/cart/index.blade.php index 1302f70..fc238dc 100644 --- a/resources/views/cart/index.blade.php +++ b/resources/views/cart/index.blade.php @@ -3,7 +3,6 @@ @section('content') -