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') - @if (! CartCollection::isEmpty()) -
@endif @if ($draft) - {{ $draft ? $draft->type : '' }} -
- - -
- @if (isset($queriedProducts)) - - @endif + + @if ($queriedProducts) +
+ + + + + + + + + + @forelse($queriedProducts as $product) + + + + + + @empty + + + + @endforelse + +
ProdukHarga Satuan ({{ $draft->type }})Action
{{ $product->name }}{{ $draft->type == 'cash' ? $product->cash_price : $product->credit_price }} +
+ {{ csrf_field() }} + + +
+
+ Produk tidak ditemukan dengan keyword : {{ request('query') }} +
+
+ @endif + + + + + + + + + + + + + + @forelse($draft->items() as $key => $item) + + + + + + + {{-- + + {{ csrf_field() }} {{ method_field('patch') }} + + + + --}} + + + + @empty + @endforelse +
#Nama ItemHarga SatuanQtyDiskonSubtotalAction
{{ $key + 1 }}{{ $item->name }}{{ formatRp($item->price) }}{{ $item->qty }}{{ $item->item_discount }}
{{ formatRp($item->subtotal) }} +
+ {{ csrf_field() }} {{ method_field('delete') }} + + +
+
@endif @endsection \ No newline at end of file diff --git a/tests/Feature/TransactionEntryTest.php b/tests/Feature/TransactionEntryTest.php index 8b43acb..e6edbd0 100644 --- a/tests/Feature/TransactionEntryTest.php +++ b/tests/Feature/TransactionEntryTest.php @@ -59,7 +59,7 @@ class TransactionEntryTest extends BrowserKitTestCase $this->visit(route('cart.index')); // Visit search for products - $this->submitForm(trans('product.search'), [ + $this->submitForm(trans('cart.product_search'), [ 'query' => 'testing', ]); @@ -91,5 +91,10 @@ class TransactionEntryTest extends BrowserKitTestCase $this->seePageIs(route('cart.show', [$draft->draftKey, 'query' => 'testing'])); $this->assertTrue($cart->draftHasItem($draft, $product)); $this->assertEquals(800, $draft->getTotal()); + + $this->see(formatRp(800)); + // $this->seeElement('input', ['id' => 'qty' . 0]); + // $this->seeElement('input', ['id' => 'item_discount-' . 0]); + $this->seeElement('input', ['id' => 'remove-item-' . 0]); } }