Skip to content

Commit

Permalink
Making orders was added
Browse files Browse the repository at this point in the history
  • Loading branch information
vilgefortzz committed May 19, 2017
1 parent ad3ba52 commit 068b08d
Show file tree
Hide file tree
Showing 31 changed files with 1,555 additions and 250 deletions.
84 changes: 84 additions & 0 deletions app/Http/Controllers/OrderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Http\Controllers;

use App\Cart;
use App\Order;
use Auth;
use Illuminate\Http\Request;
use Session;

class OrderController extends Controller
{
public function showCheckout(){

if (!Session::has('cart')){
return back();
}

$oldCart = Session::get('cart');
$cart = new Cart($oldCart);

return view('orders.checkout', ['products' => $cart->products, 'totalPrice' => $cart->totalPrice]);
}

public function showPlaceAnOrder(){

if (!Session::has('cart')){
return back();
}

$oldCart = Session::get('cart');
$cart = new Cart($oldCart);

return view('orders.place_an_order', ['products' => $cart->products, 'totalPrice' => $cart->totalPrice]);
}

public function store(Request $request){

/*
* Validate data
*/

$this->validate($request, [
'email' => 'required|email|max:255',
'first_name' => 'required|min:3|max:30',
'last_name' => 'required|min:5|max:50',
'street' => 'required|min:5|max:50',
'postal_code' => 'required|min:5|max:20',
'city' => 'required|min:5|max:15',
'phone_number' => 'required'
]);

/*
* Get items, total price from shopping cart
*/
if (!Session::has('cart')){
return back();
}

$oldCart = Session::get('cart');
$cart = new Cart($oldCart);

// Create order
$order = new Order();

if (Auth::check()){
$order->user_id = Auth::user()->id;
}

$order->total_paid = $cart->totalPrice;
$order->delivery_method = $request->delivery_methods;
$order->payment_method = $request->payment_methods;
$order->status = "New";
$order->save();

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

public function showMadeAnOrder(){

return view('orders.made_order');
}
}
22 changes: 0 additions & 22 deletions app/Http/Controllers/ShopController.php

This file was deleted.

55 changes: 48 additions & 7 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\User;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Session;

class UserController extends Controller
Expand All @@ -13,22 +14,34 @@ class UserController extends Controller
public function showSettings(User $user){

return view('users.settings', compact('user'));
}

public function showPersonalData(User $user){

return view('users.personal_data', compact('user'));
}

/**
* Ajax request
*/
public function getPersonalData(User $user){

return response()->json($user);
}

public function updateName(User $user, Request $request){
public function updateUsername(User $user, Request $request){

/*
* Validate name correctness
* Validate username correctness
*/
$this->validate($request, [
'name' => 'required|min:5|max:30',
'username' => 'required|min:5|max:30',
]);

$user->name = $request->name;
$user->username = $request->username;
$user->save();

session()->flash('changed_name', 'You have succesfully changed your name');
session()->flash('changed_username', 'You have successfully changed your username');

return back();
}
Expand All @@ -45,7 +58,7 @@ public function updatePassword(User $user, Request $request){
$user->password = bcrypt($request->password);
$user->save();

session()->flash('changed_password', 'You have succesfully changed your password');
session()->flash('changed_password', 'You have successfully changed your password');

return back();
}
Expand All @@ -62,7 +75,35 @@ public function updateEmail(User $user, Request $request){
$user->email = $request->email;
$user->save();

session()->flash('changed_email', 'You have succesfully changed your e-mail address');
session()->flash('changed_email', 'You have successfully changed your e-mail address');

return back();
}

public function updatePersonalData(User $user, Request $request){

/*
* Validate data
*/
$this->validate($request, [
'first_name' => 'required|min:3|max:30',
'last_name' => 'required|min:5|max:50',
'street' => 'required|min:5|max:50',
'postal_code' => 'required|min:5|max:20',
'city' => 'required|min:5|max:15',
'phone_number' => 'required'
]);

$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->street = $request->street;
$user->postal_code = $request->postal_code;
$user->city = $request->city;
$user->country = $request->country;
$user->phone_number = $request->phone_number;
$user->save();

session()->flash('changed_personal_data', 'You have successfully changed your personal data');

return back();
}
Expand Down
2 changes: 1 addition & 1 deletion database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
static $password;

return [
'name' => $faker->name,
'username' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
Expand Down
9 changes: 8 additions & 1 deletion database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('username');
$table->string('email')->unique();
$table->string('password');
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('street')->nullable();
$table->string('postal_code')->nullable();
$table->string('city')->nullable();
$table->string('country')->nullable();
$table->string('phone_number')->nullable();
$table->rememberToken();
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->float('total_paid')->unsigned();
$table->string('delivery_method');
$table->string('payment_method');
$table->string('status');
$table->timestamps();

$table->integer('user_id')->index()->unsigned();
$table->integer('user_id')->index()->unsigned()->nullable();
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade');
});
Expand Down
2 changes: 1 addition & 1 deletion database/seeds/UsersTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function run()

factory(User::class)->create([

'name' => 'grzesiek',
'username' => 'vilgefortzz',
'email' => 'greghause123@gmail.com',
'password' => bcrypt('witampana')

Expand Down
78 changes: 69 additions & 9 deletions public/css/app.css

Large diffs are not rendered by default.

Binary file added public/images/icons/credit_card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icons/inPost_courier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icons/inPost_paczkomat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icons/poczta_polska.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icons/ups.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/icons/usual_transfer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 1 addition & 76 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11233,7 +11233,7 @@ __webpack_require__(33);
Vue.component('example', __webpack_require__(38));

var app = new Vue({
el: '#app'
el: '#app'
});

/**
Expand All @@ -11249,81 +11249,6 @@ __webpack_require__(32);
* Active tooltip - show etc.
*/
$('[data-toggle="tooltip"]').tooltip();

$(document).ready(function () {

var orig_height = $('#review_text_area').height();
var new_height = 150;

$('#review_text_area').on('focus', function () {

$(this).animate({ height: new_height + 'px' });
});

$('#review_text_area').on('blur', function () {

$(this).animate({ height: orig_height + 'px' });
});

$('#give_review_this_page').on('click', function () {

if ($('#write_review').length != 0) {
$('html, body').animate({
scrollTop: $('#write_review').offset().top - 170
}, 800);

$('#review_text_area').focus();
} else {
$('html, body').animate({
scrollTop: $('#review_given').offset().top - 170
}, 800);
}
});

/**
* FAQ
*/

$('.faq_group').on('click', function () {

var faq_id = $(this).attr('id');
var id = faq_id.split('_')[1];

$('#answer_' + id).slideDown();
});

/**
* Subcategory menu from main page
*/

$('.dropdown_cat').on('click', function (e) {
e.preventDefault();

var cat_id = $(this).attr('id');
var id = cat_id.split('_')[1];

$('.sub_cat_menu').hide();

$('#sub_cat_' + id).fadeIn();
});

if (localStorage.length > 0) {

if ($('#write_review').length != 0) {
$('html, body').animate({
scrollTop: $('#write_review').offset().top - 170
}, 800);

$('#review_text_area').focus();
} else {
$('html, body').animate({
scrollTop: $('#review_given').offset().top - 170
}, 800);
}

localStorage.clear();
}
});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

/***/ }),
Expand Down
Loading

0 comments on commit 068b08d

Please sign in to comment.