Skip to content

Commit

Permalink
Client can view it orders, see their status, make filtration by status
Browse files Browse the repository at this point in the history
  • Loading branch information
vilgefortzz committed May 19, 2017
1 parent 068b08d commit effa807
Show file tree
Hide file tree
Showing 21 changed files with 385 additions and 39 deletions.
27 changes: 25 additions & 2 deletions app/Http/Controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Cart;
use App\Order;
use App\OrderProduct;
use App\Product;
use Auth;
use Illuminate\Http\Request;
use Session;
Expand Down Expand Up @@ -70,10 +72,31 @@ public function store(Request $request){
$order->total_paid = $cart->totalPrice;
$order->delivery_method = $request->delivery_methods;
$order->payment_method = $request->payment_methods;
$order->status = "New";
$order->status = "Pending";
$order->save();

Session::flush();
// Create order products

foreach ($cart->products as $product){

$orderProduct = new OrderProduct();
$orderProduct->order_id = $order->id;
$orderProduct->product_id = $product['id'];

$orderProduct->quantity = $product['quantity'];
$orderProduct->priceForAllItems = $product['priceForAllItems'];
$orderProduct->save();

// Decrease quantity of products on stock

$dbProduct = Product::find($product['id']);
$dbProduct->quantity -= $product['quantity'];
$dbProduct->save();
}

// Clear shopping cart after making order
Session::forget('cart');

return redirect()->to('/madeAnOrder');
}

Expand Down
26 changes: 26 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Order;
use App\User;
use Auth;
use Illuminate\Http\Request;
Expand All @@ -21,6 +22,31 @@ public function showPersonalData(User $user){
return view('users.personal_data', compact('user'));
}

public function showOrders(User $user){

$orders = Order::where('user_id', $user->id)->orderBy('created_at', 'desc')->paginate(2);

return view('users.orders', compact('orders'));
}

public function showPendingOrders(User $user){

$orders = Order::where('user_id', $user->id)
->where('status', 'Pending')
->orderBy('created_at', 'desc')->paginate(2);

return view('users.orders', compact('orders'));
}

public function showCompletedOrders(User $user){

$orders = Order::where('user_id', $user->id)
->where('status', 'Completed')
->orderBy('created_at', 'desc')->paginate(2);

return view('users.orders', compact('orders'));
}

/**
* Ajax request
*/
Expand Down
5 changes: 5 additions & 0 deletions app/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public function user()
{
return $this->belongsTo('App\User');
}

public function orderProducts()
{
return $this->hasMany('App\OrderProduct');
}
}
18 changes: 18 additions & 0 deletions app/OrderProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class OrderProduct extends Model
{
public function product()
{
return $this->belongsTo('App\Product');
}

public function order()
{
return $this->belongsTo('App\Order');
}
}
4 changes: 2 additions & 2 deletions app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function reviews()
return $this->hasMany('App\Review');
}

public function items()
public function orderProducts()
{
return $this->hasMany('App\Item');
return $this->hasMany('App\OrderProduct');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrderProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('order_products', function (Blueprint $table) {
$table->increments('id');
$table->integer('quantity')->unsigned();
$table->float('priceForAllItems')->unsigned();
$table->timestamps();

$table->integer('order_id')->index()->unsigned();
$table->foreign('order_id')->references('id')->on('orders')
->onDelete('cascade');

$table->integer('product_id')->index()->unsigned();
$table->foreign('product_id')->references('id')->on('products')
->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('order_products');
}
}
65 changes: 60 additions & 5 deletions public/css/app.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12211,13 +12211,13 @@ window.axios.defaults.headers.common = {
/* 35 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function($) {$('.dropdown').hover(function () {
$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn();
/* WEBPACK VAR INJECTION */(function($) {$('.dropdown-dynamic').hover(function () {
$(this).find('.dropdown-menu-dynamic').stop(true, true).delay(200).fadeIn();
}, function () {
$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut();
$(this).find('.dropdown-menu-dynamic').stop(true, true).delay(200).fadeOut();
});

$('.dropdown-menu').hover(function () {
$('.dropdown-menu-dynamic').hover(function () {
$(this).stop(true, true);
}, function () {
$(this).stop(true, true).delay(200).fadeOut();
Expand Down
8 changes: 4 additions & 4 deletions resources/assets/js/hover_menu.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
$('.dropdown').hover(
$('.dropdown-dynamic').hover(
function() {
$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn();
$(this).find('.dropdown-menu-dynamic').stop(true, true).delay(200).fadeIn();
},
function() {
$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut();
$(this).find('.dropdown-menu-dynamic').stop(true, true).delay(200).fadeOut();
}
);

$('.dropdown-menu').hover(
$('.dropdown-menu-dynamic').hover(
function() {
$(this).stop(true, true);
},
Expand Down
56 changes: 51 additions & 5 deletions resources/assets/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ body{
text-align: center;
}

.dropdown{
.dropdown-dynamic{
display: inline-block;
}

.dropdown a{
.dropdown-dynamic a{
display: block;
color: #59585b;
padding: 14px 16px;
Expand Down Expand Up @@ -118,7 +118,7 @@ body{
margin-bottom: 10px;
}

.dropdown-menu li a{
.dropdown-menu-dynamic li a{
display: block;
text-align: left;
}
Expand Down Expand Up @@ -299,7 +299,7 @@ body{
margin-top: 4px;
}

.panel-heading{
.panel-heading-fix{
font-size: 14px;
border: none;
}
Expand Down Expand Up @@ -471,7 +471,7 @@ body{

.cc-selector input:checked +.radio_nice{
-webkit-filter: none;
-moz-filter: none;
-moz-filter : none;
filter: none;
}

Expand All @@ -498,4 +498,50 @@ body{
#place_an_order_btn:hover{
background-color: #d77c1f;
color: black;
}

// Orders history

.panel-order {
/* used to change default values without adding additional class */
}
.panel-order .row {
border-bottom: 1px solid #ccc;
}
.panel-order .row:last-child {
border: 0;
}
.panel-order .row .col-md-1 {
text-align: center;
padding-top: 15px;
}
.panel-order .row .col-md-1 img {
width: 50px;
max-height: 50px;
}
.panel-order .row .row {
border-bottom: 0;
}
.panel-order .row .col-md-11 {
border-left: 1px solid #ccc;
}
.panel-order .row .row .col-md-12 {
padding-top: 7px;
padding-bottom: 7px;
}
.panel-order .row .row .col-md-12:last-child {
font-size: 13px;
color: #555;
background: #efefef;
}
.panel-order .btn-group {
margin: 0;
padding: 0;
}
.panel-order .panel-body {
padding-top: 0;
padding-bottom: 0;
}
.panel-order .panel-deading {
margin-bottom: 0;
}
2 changes: 1 addition & 1 deletion resources/views/cart.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel_without_border panel-default">
<div class="panel-heading text-center">
<div class="panel-heading panel-heading-fix text-center">
<h2 style="margin-top: 0"><span class="glyphicon glyphicon-shopping-cart"></span>Products in cart:</h2>
</div>

Expand Down
12 changes: 6 additions & 6 deletions resources/views/layouts/nav_bar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
<ul class="nav navbar-nav navbar-right">

<!-- Cart -->
<li class="dropdown">
<li class="dropdown dropdown-dynamic">
<a id="shopping_cart" href="{{ url('/cart') }}">
<span class="glyphicon glyphicon-shopping-cart glyphicon-fix"></span>
{{--Number of products--}}
<span class="badge cart_counter">{{ Session::has('cart') ? Session::get('cart')->numberOfProducts : '0' }}</span>
</a>

@if(Session::has('cart'))
<ul id="cart_list" class="dropdown-menu" role="menu">
<ul id="cart_list" class="dropdown-menu dropdown-menu-dynamic" role="menu">
@if(Session::get('cart')->numberOfProducts == 0)
<li>
<h5 class="text-center">Cart is empty</h5>
Expand All @@ -80,7 +80,7 @@
</ul>
@else

<ul id="cart_list" class="dropdown-menu" role="menu">
<ul id="cart_list" class="dropdown-menu dropdown-menu-dynamic" role="menu">
<li>
<h5 class="text-center">Cart is empty</h5>
</li>
Expand All @@ -96,12 +96,12 @@
@else

<!-- Authentication Links -->
<li class="dropdown">
<li class="dropdown dropdown-dynamic">
<a href="#">
<span class="glyphicon glyphicon-user"></span>{{ Auth::user()->username }}
</a>

<ul class="dropdown-menu" role="menu">
<ul class="dropdown-menu dropdown-menu-dynamic" role="menu">
<li>
<a href="{{ url('users/'.Auth::user()->id.'/personalData') }}">
<span class="glyphicon glyphicon-briefcase"></span>Your personal data
Expand All @@ -113,7 +113,7 @@
</a>
</li>
<li>
<a href="#">
<a href="{{ url('/users/'.Auth::user()->id.'/orders') }}">
<span class="glyphicon glyphicon-modal-window"></span>Your orders
</a>
</li>
Expand Down
9 changes: 9 additions & 0 deletions resources/views/main_page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@
$('#sub_cat_' + id).fadeIn();
});
/**
* Animate from another page - set
*/
$('.give_review').on('click', function () {
localStorage.setItem('animate', 'animate');
})
</script>

@endsection
2 changes: 1 addition & 1 deletion resources/views/orders/checkout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel_without_border panel-default">
<div class="panel-heading text-center">
<div class="panel-heading panel-heading-fix text-center">
<h2 style="margin-top: 0"><span class="glyphicon glyphicon-pencil"></span>Checkout:</h2>
</div>

Expand Down
Loading

0 comments on commit effa807

Please sign in to comment.