diff --git a/app/Cart/TransactionDraft.php b/app/Cart/TransactionDraft.php index f6635d4..e2be1a5 100644 --- a/app/Cart/TransactionDraft.php +++ b/app/Cart/TransactionDraft.php @@ -33,7 +33,7 @@ abstract class TransactionDraft public function items() { - return collect($this->items); + return collect($this->items)->sortBy('name'); } public function addItem(Item $item) diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index 8a317ae..d9c829d 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -62,8 +62,14 @@ class CartController extends Controller $item = new Item($product, $request->qty); $this->cart->addItemToDraft($draftKey, $item); - if ($request->has('query')); + flash(trans('cart.item_added', [ + 'product_name' => $product->name . ' (' . $product->unit->name . ')', + 'qty' => $request->qty, + ])); + + if ($request->has('query')) { return redirect()->route('cart.show', [$draftKey, 'query' => $request->get('query')]); + } return back(); } diff --git a/resources/lang/id/cart.php b/resources/lang/id/cart.php index 62cbe40..2953b27 100644 --- a/resources/lang/id/cart.php +++ b/resources/lang/id/cart.php @@ -2,6 +2,9 @@ return [ // Labels - 'product_search' => 'Cari Produk', - 'list' => 'Transaksi', + 'product_search' => 'Cari Produk', + 'list' => 'Transaksi', + 'item_added' => 'Produk :product_name telah ditambahkan :qty item', + 'min_search_query' => 'Min. 3 huruf...', + 'search_box_cleanup' => 'Bersihkan Pencarian', ]; diff --git a/resources/views/cart/index.blade.php b/resources/views/cart/index.blade.php index 808c222..905f715 100644 --- a/resources/views/cart/index.blade.php +++ b/resources/views/cart/index.blade.php @@ -27,6 +27,7 @@ @endif @endsection +@if ($draft) @section('script') -@endsection \ No newline at end of file +@endsection +@endif \ No newline at end of file diff --git a/resources/views/cart/partials/draft-item-list.blade.php b/resources/views/cart/partials/draft-item-list.blade.php index 80f95dd..7029cae 100644 --- a/resources/views/cart/partials/draft-item-list.blade.php +++ b/resources/views/cart/partials/draft-item-list.blade.php @@ -19,9 +19,10 @@ + @forelse($draft->items() as $key => $item) - {{ $key + 1 }} + {{ $no }} {{ $item->name }}
({{ $item->unit }}) diff --git a/resources/views/cart/partials/product-search-box.blade.php b/resources/views/cart/partials/product-search-box.blade.php index 678e75c..414ffcd 100644 --- a/resources/views/cart/partials/product-search-box.blade.php +++ b/resources/views/cart/partials/product-search-box.blade.php @@ -2,9 +2,11 @@
- + - {{ link_to_route('cart.show', 'Bersihkan Pencarian', [$draft->draftKey], ['class' => 'btn btn-sm']) }} + @if ($queriedProducts) + {{ link_to_route('cart.show', trans('cart.search_box_cleanup'), [$draft->draftKey], ['class' => 'btn btn-sm']) }} + @endif
diff --git a/resources/views/cart/partials/product-search-result-box.blade.php b/resources/views/cart/partials/product-search-result-box.blade.php index c843c9e..60e050c 100644 --- a/resources/views/cart/partials/product-search-result-box.blade.php +++ b/resources/views/cart/partials/product-search-result-box.blade.php @@ -21,6 +21,11 @@ + @if ($loop->last) + {{ link_to_route('cart.show', trans('cart.search_box_cleanup'), [$draftKey], [ + 'class' => 'btn btn-sm btn-default pull-right' + ]) }} + @endif @empty diff --git a/tests/Feature/TransactionEntryTest.php b/tests/Feature/TransactionEntryTest.php index 0ddf0a6..7de0739 100644 --- a/tests/Feature/TransactionEntryTest.php +++ b/tests/Feature/TransactionEntryTest.php @@ -90,8 +90,18 @@ class TransactionEntryTest extends BrowserKitTestCase $this->type(2, 'qty'); $this->press('add-product-'.$product1->id); + $this->see(trans('cart.item_added', [ + 'product_name' => $product1->name . ' (' . $product1->unit->name . ')', + 'qty' => 2 + ])); + $this->type(3, 'qty'); $this->press('add-product-'.$product2->id); + $this->see(trans('cart.item_added', [ + 'product_name' => $product2->name . ' (' . $product2->unit->name . ')', + 'qty' => 3 + ])); + $this->seePageIs(route('cart.show', [$draft->draftKey, 'query' => 'testing'])); $this->assertTrue($cart->draftHasItem($draft, $product1)); $this->assertTrue($cart->draftHasItem($draft, $product2));