Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
onestartup-shop
Overview
Overview
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
Angel Martin
onestartup-shop
Commits
c2ae5a87
Commit
c2ae5a87
authored
May 09, 2018
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cart function
parent
3e3fd5db
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
6 deletions
+137
-6
CartController.php
src/controllers/CartController.php
+8
-1
layout.blade.php
src/views/public/layout.blade.php
+7
-1
list.blade.php
src/views/public/list.blade.php
+3
-3
show-cart.blade.php
src/views/public/show-cart.blade.php
+101
-0
single.blade.php
src/views/public/single.blade.php
+18
-1
No files found.
src/controllers/CartController.php
View file @
c2ae5a87
...
@@ -21,7 +21,11 @@ class CartController extends Controller
...
@@ -21,7 +21,11 @@ class CartController extends Controller
public
function
show
()
public
function
show
()
{
{
$total
=
$this
->
total
();
$total
=
$this
->
total
();
return
\Session
::
get
(
'cart'
);
$cart
=
\Session
::
get
(
'cart'
);
return
view
(
'shop-public::show-cart'
)
->
with
(
'cart'
,
$cart
)
->
with
(
'total'
,
$total
);
}
}
public
function
add
(
Product
$product
)
public
function
add
(
Product
$product
)
...
@@ -58,6 +62,9 @@ class CartController extends Controller
...
@@ -58,6 +62,9 @@ class CartController extends Controller
public
function
update
(
Product
$product
,
$quantity
)
public
function
update
(
Product
$product
,
$quantity
)
{
{
if
(
$quantity
<=
0
)
{
return
redirect
()
->
back
();
}
$cart
=
\Session
::
get
(
'cart'
);
$cart
=
\Session
::
get
(
'cart'
);
if
(
!
isset
(
$cart
[
$product
->
slug
]))
{
if
(
!
isset
(
$cart
[
$product
->
slug
]))
{
return
redirect
()
->
route
(
'cart.show'
);
return
redirect
()
->
route
(
'cart.show'
);
...
...
src/views/public/layout.blade.php
View file @
c2ae5a87
...
@@ -8,7 +8,9 @@
...
@@ -8,7 +8,9 @@
</head>
</head>
<body>
<body>
<p>
<p>
<a
href=
"#"
>
Ver carrito
<span>
0
</span></a>
<a
href=
"{{route('cart.show')}}"
>
Ver carrito
<span>
{{\Session::has('cart') ? count(\Session::get('cart')) : 0}}
</span>
</a>
</p>
</p>
{{-- Aqui toda la estructura del blog--}}
{{-- Aqui toda la estructura del blog--}}
...
@@ -18,6 +20,10 @@
...
@@ -18,6 +20,10 @@
<!-- Importante: scripts elementales no remover -->
<!-- Importante: scripts elementales no remover -->
<script
src=
'https://unpkg.com/sweetalert/dist/sweetalert.min.js'
></script>
<script
src=
'https://unpkg.com/sweetalert/dist/sweetalert.min.js'
></script>
<script
src=
"https://code.jquery.com/jquery-3.3.1.min.js"
integrity=
"sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin=
"anonymous"
></script>
<!-- ******************************************* -->
<!-- ******************************************* -->
...
...
src/views/public/list.blade.php
View file @
c2ae5a87
@
extends
(
'shop-public::layout'
)
@
extends
(
'shop-public::layout'
)
@
section
(
'pageTitle'
,
'Tiendita'
)
@
section
(
'content'
)
@
section
(
'content'
)
@
php
@
php
setlocale
(
LC_MONETARY
,
'en_US'
);
setlocale
(
LC_MONETARY
,
'en_US'
);
...
@@ -21,10 +21,10 @@
...
@@ -21,10 +21,10 @@
<
h4
>
Precio
:
{{
money_format
(
'%(#10n'
,
$product
->
infoSale
->
sale_price
)}}
</
h4
>
<
h4
>
Precio
:
{{
money_format
(
'%(#10n'
,
$product
->
infoSale
->
sale_price
)}}
</
h4
>
<
div
>
<
div
>
<
p
>
<
p
>
<
a
href
=
"
#
"
>
Agregar
al
carrito
</
a
>
<
a
href
=
"
{{route('cart.add',
$product->slug
)}}
"
>
Agregar
al
carrito
</
a
>
</
p
>
</
p
>
<
p
>
<
p
>
<
a
href
=
"
#
"
>
Ver
mas
informacion
</
a
>
<
a
href
=
"
{{route('show.shop',
$product->slug
)}}
"
>
Ver
mas
informacion
</
a
>
</
p
>
</
p
>
</
div
>
</
div
>
</
div
>
</
div
>
...
...
src/views/public/show-cart.blade.php
0 → 100644
View file @
c2ae5a87
@
extends
(
'shop-public::layout'
)
@
section
(
'pageTitle'
,
'Carrito'
)
@
section
(
'content'
)
@
php
setlocale
(
LC_MONETARY
,
'en_US'
);
@
endphp
<!--
code
>
Variables
disponibles
:
<
ul
>
<
li
>
$cart
</
li
>
<
li
>
$total
</
li
>
</
ul
>
</
code
-->
<
div
style
=
"width: 50%; margin: 0 auto;"
>
@
if
(
count
(
$cart
))
<
div
class
="
cart
">
<table class="
table
" style="
width
:
100
%
;
" align="
right
">
<thead>
<tr>
<th>Producto</th>
<th>Precio</th>
<th>Cantidad</th>
<th>Subtotal</th>
<th></th>
</tr>
</thead>
@foreach(
$cart
as
$product
)
<tbody>
<tr>
<td>
{
{$product->name}
}
</td>
<td>{{money_format('%(#10n',
$product->infoSale
->sale_price)}}</td>
<td>
<input
type="
number
"
min="
1
"
value="
{{
$product
->
quantity
}}
"
id="
product
-
{{
$product
->
slug
}}
">
<a
href="
#"
class
="
btn
-
update
"
data-href="
{{
route
(
'cart.update'
,
[
$product
->
slug
,
''
])
}}
"
data-slug = "
{{
$product
->
slug
}}
">
Cambiar
</a>
</td>
<td>{{money_format('%(#10n', (
$product->infoSale
->sale_price *
$product->quantity
))}}</td>
<td>
<p>
<a href="
{{
route
(
'show.shop'
,
$product
->
slug
)}}
">Detalle</a>
</p>
<p>
<a href="
{{
route
(
'cart.remove'
,
$product
->
slug
)}}
">Eliminar</a>
</p>
</td>
</tr>
</tbody>
@endforeach
<tr>
<td colspan="
4
" align="
right
">
{{money_format('%(#10n', (
$total
))}}
</td>
</tr>
</table>
<p>
<a href="
{{
route
(
'cart.trash'
)}}
">
Vaciar carrito de compras
</a>
</p>
<p>
<a href="
{{
route
(
'main.shop'
)}}
">Ver mas productos</a>
</p>
<p>
<a href="
#">Finalizar compra</a>
</
p
>
</
div
>
@
else
<
h1
>
No
hay
productos
agregados
</
h1
>
<
p
>
<
a
href
=
"
{
{route('main.shop')}
}
"
>
Visitar
productos
</
a
>
</
p
>
@
endif
</
div
>
@
endsection
@
section
(
'scripts_extra'
)
<
script
type
=
"text/javascript"
>
// Update item cart
$
(
".btn-update"
)
.
on
(
'click'
,
function
(
e
){
e
.
preventDefault
();
var
slug
=
$
(
this
)
.
data
(
'slug'
);
var
href
=
$
(
this
)
.
data
(
'href'
);
var
quantity
=
$
(
"#product-"
+
slug
)
.
val
();
window
.
location
.
href
=
href
+
"/"
+
quantity
;
});
</
script
>
@
endsection
\ No newline at end of file
src/views/public/single.blade.php
View file @
c2ae5a87
@
extends
(
'shop-public::layout'
)
@
extends
(
'shop-public::layout'
)
@
section
(
'pageTitle'
,
$product
->
name
)
@
section
(
'content'
)
@
section
(
'content'
)
@
php
setlocale
(
LC_MONETARY
,
'en_US'
);
@
endphp
<
code
>
<
code
>
<
ul
>
<
ul
>
...
@@ -10,5 +13,19 @@
...
@@ -10,5 +13,19 @@
<
li
>
$otros
</
li
>
<
li
>
$otros
</
li
>
</
ul
>
</
ul
>
</
code
>
</
code
>
<
div
style
=
"width: 150px; margin: 5px; float: left;"
>
<
img
src
=
"
{
{asset('storage/'.$product->cover)}
}
"
width
=
"100%"
alt
=
"Imagen no disponible"
>
<
h4
>
{{
$product
->
name
}}
</
h4
>
<
h4
>
Precio
:
{{
money_format
(
'%(#10n'
,
$product
->
infoSale
->
sale_price
)}}
</
h4
>
<
div
>
<
p
>
<
a
href
=
"{{route('cart.add',
$product->slug
)}}"
>
Agregar
al
carrito
</
a
>
</
p
>
<
p
>
<
a
href
=
"
{
{route('main.shop')}
}
"
>
Ver
mas
productos
</
a
>
</
p
>
</
div
>
</
div
>
@
endsection
@
endsection
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