Skip to content

Commit

Permalink
Changing quantity of products on stock in admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
vilgefortzz committed Jun 16, 2017
1 parent 685e002 commit 4779899
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
10 changes: 10 additions & 0 deletions app/Http/Controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ public function index(){
$products = Product::paginate(5);
return view('admin.products.products', compact('products'));
}

public function changeQuantity(Product $product, Request $request){

if ($request->quantity >= 0 && $request->quantity <= 100){

$product->quantity = $request->quantity;
$product->save();
}
return back();
}
}
5 changes: 5 additions & 0 deletions app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public function images()
{
return $this->belongsToMany('App\Image', 'products_images');
}

public function ratings()
{
return $this->hasMany('App\Rating');
}
}
2 changes: 1 addition & 1 deletion resources/views/admin/layouts/side_bar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div id="dropdown-1" class="panel-collapse collapse">
<div class="panel-body">
<ul class="nav navbar-nav">
<li><a href="{{ url('/admin/products') }}">All products ( show, edit, delete )</a></li>
<li><a href="{{ url('/admin/products') }}">All products ( show, edit, delete, change quantity )</a></li>
<li><a href="#">Add product</a></li>
</ul>
</div>
Expand Down
10 changes: 5 additions & 5 deletions resources/views/admin/orders/orders.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
$(document).ready(function() {
$('.navbar-toggle-sidebar').click(function () {
$('.navbar-nav').toggleClass('slide-in');
$('.side-body').toggleClass('body-slide-in');
});
$('.order_status').on('change', function() {
var order_id = $(this).attr('id');
Expand All @@ -135,11 +140,6 @@
$('#order_details_' + id).slideDown();
});
$('.give_review').on('click', function () {
localStorage.setItem('animate', 'animate');
})
});
</script>
Expand Down
26 changes: 23 additions & 3 deletions resources/views/admin/products/products.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@
<td class="text-center"><img src="{{$product->path_to_thumbnail}}" width="50" height="50"></td>
<td class="text-center">{{$product->description}}</td>
<td class="text-center">${{$product->price}}</td>
<td class="text-center">{{$product->quantity}}</td>
<td class="text-center">
{{-- Change quantity of products --}}
<form id="change_quantity_{{$product->id}}" name="change_quantity" method="POST" action="{{ url('/admin/products/'.$product->id.'/update/quantity') }}">
{{csrf_field()}}
{{method_field('PUT')}}

<input id="quantity_{{$product['id']}}" type="text"
class="text-center form-control quantity_number"
name="quantity" value="{{$product->quantity}}" min="0" max="1000">
<label for="quantity_{{$product['id']}}" class="control-label">Change quantity<span class="glyphicon glyphicon-triangle-top"></span></label>
</form>
</td>
</tr>
@endforeach
</tbody>
Expand All @@ -38,13 +49,22 @@

<script type="text/javascript">
$(function () {
$(document).ready(function() {
$('.navbar-toggle-sidebar').click(function () {
$('.navbar-nav').toggleClass('slide-in');
$('.side-body').toggleClass('body-slide-in');
});
});
$('.quantity_number').on('change', function() {
var quantity_id = $(this).attr('id');
var id = quantity_id.split('_')[1];
// Submit form to change product quantity
$('#change_quantity_' + id).submit();
});
});
</script>

@endsection
5 changes: 5 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
*/
Route::put('/orders/{order}/update/status', 'OrderController@updateStatus');

/**
* Change quantity of products
*/
Route::put('/products/{product}/update/quantity', 'ProductController@changeQuantity');

});


Expand Down

0 comments on commit 4779899

Please sign in to comment.