Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
T
test-webshop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Artem
test-webshop
Commits
01ca406c
Commit
01ca406c
authored
May 15, 2020
by
Artem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change behavior in cart, when delete all products or clear cart redirect is to homepage
parent
ce9bbd5e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
CartController.php
app/Http/Controllers/CartController.php
+4
-2
cart.js
public/js/cart.js
+12
-2
No files found.
app/Http/Controllers/CartController.php
View file @
01ca406c
...
...
@@ -21,7 +21,7 @@ class CartController extends Controller
$cart
->
updateCurrentItems
();
$products
=
$cart
->
items
;
return
view
(
'cart'
,
compact
(
'cart'
,
'products'
));
return
view
(
'cart'
,
compact
(
'cart'
,
'products'
));
}
public
function
addToCart
(
Product
$product
)
...
...
@@ -47,6 +47,7 @@ class CartController extends Controller
if
(
!
$cart
->
total_qty
)
{
Session
::
forget
(
'cart'
);
return
route
(
'homepage'
);
}
}
...
...
@@ -58,12 +59,13 @@ class CartController extends Controller
if
(
!
$cart
->
total_qty
)
{
Session
::
forget
(
'cart'
);
return
route
(
'homepage'
);
}
}
public
function
clearCart
()
{
Session
::
forget
(
'cart'
);
return
redirect
(
'cart'
);
return
redirect
(
route
(
'homepage'
)
);
}
}
public/js/cart.js
View file @
01ca406c
...
...
@@ -16,7 +16,12 @@ function setUpdateCartQtyEventListener() {
productsQty
:
JSON
.
stringify
(
productsQty
)
})
.
then
(
function
(
response
)
{
document
.
location
.
reload
(
true
);
const
redirectLinkWhenCartIsEmpty
=
response
.
data
;
if
(
redirectLinkWhenCartIsEmpty
)
{
window
.
location
.
replace
(
redirectLinkWhenCartIsEmpty
);
}
else
{
document
.
location
.
reload
(
true
);
}
})
.
catch
(
function
(
error
)
{
console
.
log
(
error
);
...
...
@@ -31,7 +36,12 @@ function setRemoveItemEventListener() {
axios
.
post
(
actionUrl
)
.
then
(
function
(
response
)
{
document
.
location
.
reload
(
true
);
const
redirectLinkWhenCartIsEmpty
=
response
.
data
;
if
(
redirectLinkWhenCartIsEmpty
)
{
window
.
location
.
replace
(
redirectLinkWhenCartIsEmpty
);
}
else
{
document
.
location
.
reload
(
true
);
}
})
.
catch
(
function
(
error
)
{
console
.
log
(
error
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment