Skip to content

Commit

Permalink
Dynamical delete products and show total price in cart view was added…
Browse files Browse the repository at this point in the history
…. Improvements in appearance and usage of local storage
  • Loading branch information
vilgefortzz committed Apr 28, 2017
1 parent 66b89fa commit 52fa2b1
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 207 deletions.
10 changes: 0 additions & 10 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ protected function create(array $data)
$user->password = bcrypt($data['password']);
$user->save();

/*
* Create cart for new user
*/
$cart = new Cart();

/*
* Add this cart to newly created user
*/
$user->cart()->save($cart);

return $user;
}
}
4 changes: 3 additions & 1 deletion 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 Session;

class UserController extends Controller
{
Expand Down Expand Up @@ -75,9 +76,10 @@ public function updateEmail(User $user, Request $request){
public function delete(User $user){

/*
* Very important - logout before delete
* Very important - logout before delete and remove items from session
*/
Auth::logout();
Session::flush();

$user->delete();

Expand Down
4 changes: 2 additions & 2 deletions config/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
|
*/

'lifetime' => 3600,
'lifetime' => 120,

'expire_on_close' => true,
'expire_on_close' => false,

/*
|--------------------------------------------------------------------------
Expand Down
78 changes: 70 additions & 8 deletions public/css/app.css

Large diffs are not rendered by default.

55 changes: 4 additions & 51 deletions public/js/add_to_cart_ajax.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
$(document).ready(function() {

if (sessionStorage.length > 0){
for (var i = 0; i < sessionStorage.length; i++){

$('#' + sessionStorage.getItem(sessionStorage.key(i))).removeClass('add_to_cart').addClass('remove_from_cart');
$('#' + sessionStorage.getItem(sessionStorage.key(i))).empty();
$('#' + sessionStorage.getItem(sessionStorage.key(i))).append('<div id="remove_from_cart_btn' + sessionStorage.getItem(sessionStorage.key(i)) + '">' + '<span class="glyphicon glyphicon-remove"></span><b>Added to cart</b>' + '</div>');
$('#' + sessionStorage.getItem(sessionStorage.key(i))).attr('href', '/cart/delete/' + sessionStorage.getItem(sessionStorage.key(i)));
}
}

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

var base_url = 'http://127.0.0.1:8000';
var url = $(this).attr("href");

$.ajax({
type: 'POST',
url: url,

success: function(data) {
$('#removed_from_cart').hide();
$('#added_to_cart').show();
$('#added_to_cart').delay(7000).fadeOut('slow');

Expand All @@ -29,47 +19,10 @@ $(document).ready(function() {

$badge.text(count + 1);

var added_btn= $('<div id="remove_from_cart_btn' + data.id + '">' + '<span class="glyphicon glyphicon-remove"></span><b>Added to cart</b>' + '</div>');

$('#' + data.id).removeClass('add_to_cart').addClass('remove_from_cart');
$('#' + data.id).empty();
$('#' + data.id).append(added_btn).hide().fadeIn(1000);
$('#' + data.id).attr('href', base_url + '/cart/delete/' + data.id);

// Add listener

$('#' + data.id).one('click', function (e) {
e.preventDefault();

var base_url = 'http://127.0.0.1:8000';
var url = $(this).attr("href");

$.ajax({
type: 'DELETE',
url: url,

success: function(data) {
$('#removed_from_cart').show();
$('#removed_from_cart').delay(7000).fadeOut('slow');

var $badge = $('.badge'),
count = Number($badge.text());

$badge.text(count - 1);

var removed_btn= $('<div id="add_to_cart_btn' + data.id + '">' + '<span class="glyphicon glyphicon-shopping-cart"></span><b>Add to cart</b>' + '</div>');

$('#' + data.id).removeClass('remove_from_cart').addClass('add_to_cart');
$('#' + data.id).empty();
$('#' + data.id).append(removed_btn).hide().fadeIn(1000);
$('#' + data.id).attr('href', base_url + '/cart/add/' + data.id);

sessionStorage.removeItem('product_' + data.id);
}
})
});
$('#add_' + data.id).hide();
$('#remove_' + data.id).show();

sessionStorage.setItem('product_' + data.id, data.id);
localStorage.setItem('product_' + data.id, data.id);
}
})
});
Expand Down
78 changes: 48 additions & 30 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
/******/ __webpack_require__.p = "./";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 47);
/******/ return __webpack_require__(__webpack_require__.s = 43);
/******/ })
/************************************************************************/
/******/ ([
Expand Down Expand Up @@ -11215,35 +11215,57 @@ module.exports = g;
/* 10 */
/***/ (function(module, exports, __webpack_require__) {


/* WEBPACK VAR INJECTION */(function($) {
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/

__webpack_require__(34);
__webpack_require__(33);

/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/

Vue.component('example', __webpack_require__(42));
Vue.component('example', __webpack_require__(38));

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

/**
* Load my scripts
*/

__webpack_require__(39);
__webpack_require__(38);
__webpack_require__(35);
__webpack_require__(34);
__webpack_require__(31);
__webpack_require__(33);
__webpack_require__(32);

/**
* Active tooltip - show etc.
*/
$('[data-toggle="tooltip"]').tooltip();

$(document).ready(function () {

if ($('#is_session').val() == '1') {
if (localStorage.length > 0) {
for (var i = 0; i < localStorage.length; i++) {

var id = localStorage.getItem(localStorage.key(i));
$('#add_' + id).hide();
$('#remove_' + id).show();
}
} else localStorage.clear();
} else {
localStorage.clear();
}
});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

/***/ }),
/* 11 */
Expand Down Expand Up @@ -12133,8 +12155,7 @@ $('td a').filter(function () {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

/***/ }),
/* 32 */,
/* 33 */
/* 32 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function($) {$.ajaxSetup({
Expand All @@ -12145,11 +12166,11 @@ $('td a').filter(function () {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

/***/ }),
/* 34 */
/* 33 */
/***/ (function(module, exports, __webpack_require__) {


window._ = __webpack_require__(41);
window._ = __webpack_require__(37);

/**
* We'll load jQuery and the Bootstrap jQuery plugin which provides support
Expand All @@ -12159,15 +12180,15 @@ window._ = __webpack_require__(41);

window.$ = window.jQuery = __webpack_require__(1);

__webpack_require__(40);
__webpack_require__(36);

/**
* Vue is a modern JavaScript library for building interactive web interfaces
* using reactive data binding and reusable components. Vue's API is clean
* and simple, leaving you to focus on building your next great project.
*/

window.Vue = __webpack_require__(45);
window.Vue = __webpack_require__(41);

/**
* We'll load the axios HTTP library which allows us to easily issue requests
Expand Down Expand Up @@ -12196,17 +12217,14 @@ window.axios.defaults.headers.common = {
// });

/***/ }),
/* 35 */,
/* 36 */,
/* 37 */,
/* 38 */
/* 34 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function($) {$('.alert').delay(7000).fadeOut('slow');
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

/***/ }),
/* 39 */
/* 35 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function($) {$('.dropdown').hover(function () {
Expand All @@ -12223,7 +12241,7 @@ $('.dropdown-menu').hover(function () {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

/***/ }),
/* 40 */
/* 36 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function(jQuery) {/*!
Expand Down Expand Up @@ -14607,7 +14625,7 @@ if (typeof jQuery === 'undefined') {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

/***/ }),
/* 41 */
/* 37 */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function(global, module) {var __WEBPACK_AMD_DEFINE_RESULT__;/**
Expand Down Expand Up @@ -31696,17 +31714,17 @@ if (typeof jQuery === 'undefined') {
}
}.call(this));

/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9), __webpack_require__(46)(module)))
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9), __webpack_require__(42)(module)))

/***/ }),
/* 42 */
/* 38 */
/***/ (function(module, exports, __webpack_require__) {

var Component = __webpack_require__(43)(
var Component = __webpack_require__(39)(
/* script */
__webpack_require__(30),
/* template */
__webpack_require__(44),
__webpack_require__(40),
/* scopeId */
null,
/* cssModules */
Expand All @@ -31733,7 +31751,7 @@ module.exports = Component.exports


/***/ }),
/* 43 */
/* 39 */
/***/ (function(module, exports) {

module.exports = function normalizeComponent (
Expand Down Expand Up @@ -31786,7 +31804,7 @@ module.exports = function normalizeComponent (


/***/ }),
/* 44 */
/* 40 */
/***/ (function(module, exports, __webpack_require__) {

module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
Expand Down Expand Up @@ -31815,7 +31833,7 @@ if (false) {
}

/***/ }),
/* 45 */
/* 41 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
Expand Down Expand Up @@ -41143,7 +41161,7 @@ module.exports = Vue$3;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3), __webpack_require__(9)))

/***/ }),
/* 46 */
/* 42 */
/***/ (function(module, exports) {

module.exports = function(module) {
Expand Down Expand Up @@ -41171,7 +41189,7 @@ module.exports = function(module) {


/***/ }),
/* 47 */
/* 43 */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(10);
Expand Down
5 changes: 2 additions & 3 deletions public/js/change_view.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
$(document).ready(function() {
$('#list').click(function(event){event.preventDefault();$('.btn-separator').show();$('.group_div').removeClass('col-xs-12');$('#list').addClass('active');$('#grid').removeClass('active');$('#products .item').addClass('list-group-item');});
$('#grid').click(function(event){event.preventDefault();$('.btn-separator').hide();$('.group_div').addClass('col-xs-12');$('#grid').addClass('active');$('#list').removeClass('active');$('#products .item').removeClass('list-group-item');$('#products .item').addClass('grid-group-item');});

$('#list').click(function(event){event.preventDefault();$('.group_div').removeClass('col-xs-12');$('#list').addClass('active');$('#grid').removeClass('active');$('#products .item').addClass('list-group-item');});
$('#grid').click(function(event){event.preventDefault();$('.group_div').addClass('col-xs-12');$('#grid').addClass('active');$('#list').removeClass('active');$('#products .item').removeClass('list-group-item');$('#products .item').addClass('grid-group-item');});
});
Loading

0 comments on commit 52fa2b1

Please sign in to comment.