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
3e3fd5db
Commit
3e3fd5db
authored
May 09, 2018
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
actions cart
parent
8eb3175a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
149 additions
and
54 deletions
+149
-54
ShopServiceProvider.php
src/ShopServiceProvider.php
+1
-0
CartController.php
src/controllers/CartController.php
+88
-0
routes.php
src/routes.php
+17
-1
layout.blade.php
src/views/public/layout.blade.php
+5
-4
list.blade.php
src/views/public/list.blade.php
+29
-22
single.blade.php
src/views/public/single.blade.php
+9
-27
No files found.
src/ShopServiceProvider.php
View file @
3e3fd5db
...
...
@@ -46,6 +46,7 @@ class ShopServiceProvider extends ServiceProvider
$this
->
app
->
make
(
'Onestartup\Shop\Controller\AdminProductController'
);
$this
->
app
->
make
(
'Onestartup\Shop\Controller\CategoryController'
);
$this
->
app
->
make
(
'Onestartup\Shop\Controller\ProductController'
);
$this
->
app
->
make
(
'Onestartup\Shop\Controller\CartController'
);
}
}
src/controllers/CartController.php
0 → 100644
View file @
3e3fd5db
<?php
namespace
Onestartup\Shop\Controller
;
use
Illuminate\Http\Request
;
use
App\Http\Requests
;
use
App\Http\Controllers\Controller
;
use
Yajra\Datatables\Datatables
;
use
Onestartup\Shop\Model\ProductShop
as
Product
;
use
Onestartup\Shop\Model\ProductCategoryShop
as
Category
;
class
CartController
extends
Controller
{
public
function
__construct
()
{
if
(
!
\Session
::
has
(
'cart'
))
{
\Session
::
put
(
'cart'
,
array
());
}
}
public
function
show
()
{
$total
=
$this
->
total
();
return
\Session
::
get
(
'cart'
);
}
public
function
add
(
Product
$product
)
{
$cart
=
\Session
::
get
(
'cart'
);
$quantity
=
1
;
if
(
isset
(
$cart
[
$product
->
slug
]))
{
$quantity
=
$cart
[
$product
->
slug
]
->
quantity
+
1
;
}
$product
->
quantity
=
$quantity
;
$cart
[
$product
->
slug
]
=
$product
;
\Session
::
put
(
'cart'
,
$cart
);
return
redirect
()
->
route
(
'cart.show'
);
}
public
function
remove
(
Product
$product
)
{
$cart
=
\Session
::
get
(
'cart'
);
if
(
!
isset
(
$cart
[
$product
->
slug
]))
{
return
redirect
()
->
route
(
'cart.show'
);
}
unset
(
$cart
[
$product
->
slug
]);
\Session
::
put
(
'cart'
,
$cart
);
return
redirect
()
->
route
(
'cart.show'
);
}
public
function
update
(
Product
$product
,
$quantity
)
{
$cart
=
\Session
::
get
(
'cart'
);
if
(
!
isset
(
$cart
[
$product
->
slug
]))
{
return
redirect
()
->
route
(
'cart.show'
);
}
$cart
[
$product
->
slug
]
->
quantity
=
$quantity
;
\Session
::
put
(
'cart'
,
$cart
);
return
redirect
()
->
route
(
'cart.show'
);
}
public
function
trash
()
{
\Session
::
forget
(
'cart'
);
return
redirect
()
->
route
(
'cart.show'
);
}
private
function
total
()
{
$cart
=
\Session
::
get
(
'cart'
);
$total
=
0
;
foreach
(
$cart
as
$product
){
$total
+=
$product
->
infoSale
->
sale_price
*
$product
->
quantity
;
}
return
$total
;
}
}
src/routes.php
View file @
3e3fd5db
...
...
@@ -42,6 +42,22 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
});
Route
::
group
([
'middleware'
=>
[
'web'
]],
function
(){
Route
::
bind
(
'product_slug'
,
function
(
$slug
)
{
return
Onestartup\Shop\Model\ProductShop
::
where
(
'slug'
,
$slug
)
->
first
();
});
Route
::
get
(
'cart/show'
,
'Onestartup\Shop\Controller\CartController@show'
)
->
name
(
'cart.show'
);
Route
::
get
(
'cart/add/{product_slug}'
,
'Onestartup\Shop\Controller\CartController@add'
)
->
name
(
'cart.add'
);
Route
::
get
(
'cart/remove/{product_slug}'
,
'Onestartup\Shop\Controller\CartController@remove'
)
->
name
(
'cart.remove'
);
Route
::
get
(
'cart/trash'
,
'Onestartup\Shop\Controller\CartController@trash'
)
->
name
(
'cart.trash'
);
Route
::
get
(
'cart/update/{product_slug}/{quantity}'
,
'Onestartup\Shop\Controller\CartController@update'
)
->
where
(
'quantity'
,
'[0-9]+'
)
->
name
(
'cart.update'
);
Route
::
get
(
'producto/{slug}'
,
'Onestartup\Shop\Controller\ProductController@show'
)
->
name
(
'show.shop'
);
Route
::
get
(
'productos'
,
'Onestartup\Shop\Controller\ProductController@index'
)
->
name
(
'main.shop'
);
Route
::
get
(
'shop'
,
'Onestartup\Shop\Controller\ProductController@index'
)
->
name
(
'main.shop'
);
//Route::get('cart/{product_id}')
});
src/views/public/layout.blade.php
View file @
3e3fd5db
...
...
@@ -2,11 +2,14 @@
<html>
<head>
<title>
{{$product->name or "PCatalogo de proeudtos"}}
@yield('pageTitle', '')
</title>
@include('
product
-public::metatags')
@include('
shop
-public::metatags')
</head>
<body>
<p>
<a
href=
"#"
>
Ver carrito
<span>
0
</span></a>
</p>
{{-- Aqui toda la estructura del blog--}}
@yield('content')
...
...
@@ -15,8 +18,6 @@
<!-- Importante: scripts elementales no remover -->
<script
src=
'https://unpkg.com/sweetalert/dist/sweetalert.min.js'
></script>
<script
src=
'https://cdn.jsdelivr.net/jquery.jssocials/1.4.0/jssocials.min.js'
type=
'text/javascript'
></script>
<script
src=
'//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5a139cd3addf2e26'
type=
'text/javascript'
></script>
<!-- ******************************************* -->
...
...
src/views/public/list.blade.php
View file @
3e3fd5db
@
extends
(
'
product
-public::layout'
)
@
extends
(
'
shop
-public::layout'
)
@
section
(
'content'
)
@
php
setlocale
(
LC_MONETARY
,
'en_US'
);
@
endphp
<!--
code
>
Variables
disponibles
:
<
ul
>
<
li
>
$categories
</
li
>
<
li
>
$products
</
li
>
<
li
>
$otros
</
li
>
</
ul
>
</
code
-->
Listado
de
entradas
<
p
>
Categorias
:
{{
$categories
}}
</
p
>
<
div
style
=
"width: 100%; margin: 0 auto;"
>
@
foreach
(
$products
as
$product
)
<
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
=
"#"
>
Agregar
al
carrito
</
a
>
</
p
>
<
p
>
<
a
href
=
"#"
>
Ver
mas
informacion
</
a
>
</
p
>
</
div
>
</
div
>
@
endforeach
</
div
>
<
p
>
Productos
todas
{{
$products
}}
</
p
>
<
p
>
Productos
al
azar
{{
$otros
}}
</
p
>
<
p
>
Paginacion
:
{
!!
$products
->
links
()
!!
}
</
p
>
@
endsection
\ No newline at end of file
src/views/public/single.blade.php
View file @
3e3fd5db
@
extends
(
'
product
-public::layout'
)
@
extends
(
'
shop
-public::layout'
)
@
section
(
'content'
)
<
p
>
Producto
:
{{
$product
}}
</
p
>
<
p
>
Categoria
:
{{
$product
->
category
}}
</
p
>
<
p
>
Categorias
:
Listado
de
categorias
:
</
p
>
<
p
>
{{
$categories
}}
</
p
>
<
p
>
Listado
de
productos
relacionados
con
sus
categorias
:
</
p
>
<
p
>
{{
$otros
}}
</
p
>
{{
--
Caja
de
compartir
con
redes
sociales
--
}}
<
div
class
="
addthis_inline_share_toolbox_le2j
"></div>
{{-- *********************************** --}}
<
code
>
<
ul
>
<
li
>
$product
</
li
>
<
li
>
$product
->
category
->
name
</
li
>
<
li
>
$categories
</
li
>
<
li
>
$otros
</
li
>
</
ul
>
</
code
>
@
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