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
cbdc4da2
Commit
cbdc4da2
authored
May 31, 2018
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reserva de productos activa
parent
8ffbb955
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
2 deletions
+76
-2
CartController.php
src/controllers/CartController.php
+58
-0
ProductController.php
src/controllers/ProductController.php
+2
-2
layout.blade.php
src/views/public/layout.blade.php
+16
-0
No files found.
src/controllers/CartController.php
View file @
cbdc4da2
...
...
@@ -60,6 +60,7 @@ public function add(Product $product)
$sale
->
save
();
\Session
::
forget
(
'sale'
);
}
$cart
=
\Session
::
get
(
'cart'
);
$quantity
=
1
;
...
...
@@ -68,6 +69,10 @@ public function add(Product $product)
$quantity
=
$cart
[
$product
->
slug
]
->
quantity
+
1
;
}
if
(
$this
->
existencia
(
$product
)
<
$quantity
)
{
return
redirect
()
->
back
()
->
with
(
'maximo'
,
$this
->
existencia
(
$product
));
}
$product
->
quantity
=
$quantity
;
$cart
[
$product
->
slug
]
=
$product
;
...
...
@@ -106,8 +111,17 @@ public function update(Product $product, $quantity)
if
(
!
isset
(
$cart
[
$product
->
slug
]))
{
return
redirect
()
->
route
(
'cart.show'
);
}
if
(
$this
->
existencia
(
$product
)
>=
$quantity
){
$cart
[
$product
->
slug
]
->
quantity
=
$quantity
;
\Session
::
put
(
'cart'
,
$cart
);
}
else
{
//return "maximo ".$this->existencia($product);
return
redirect
()
->
back
()
->
with
(
'maximo'
,
$this
->
existencia
(
$product
));
}
return
redirect
()
->
route
(
'cart.show'
);
}
...
...
@@ -655,6 +669,30 @@ public function shipping()
public
function
testmail
()
{
$product
=
Product
::
find
(
3
);
$quantity
=
0
;
$sales
=
Sale
::
where
(
'status'
,
1
)
->
orWhere
(
'status'
,
3
)
->
get
();
foreach
(
$sales
as
$order
)
{
$products
=
$order
->
products
;
foreach
(
$products
as
$aux
){
if
(
$product
->
id
==
$aux
->
id
)
{
$quantity
+=
$aux
->
pivot
->
quantity
;
}
}
}
return
$product
->
infoSale
->
quantity
-
$quantity
;
//return $quantity;
//return $sales;
//return $product;
/*$user = \App\User::first();
$orden = Sale::find(27);
...
...
@@ -671,5 +709,25 @@ public function shipping()
}
public
function
existencia
(
$product
)
{
$quantity
=
0
;
$sales
=
Sale
::
where
(
'status'
,
3
)
->
get
();
foreach
(
$sales
as
$order
)
{
$products
=
$order
->
products
;
foreach
(
$products
as
$aux
){
if
(
$product
->
id
==
$aux
->
id
)
{
$quantity
+=
$aux
->
pivot
->
quantity
;
}
}
}
return
$product
->
infoSale
->
quantity
-
$quantity
;
}
}
src/controllers/ProductController.php
View file @
cbdc4da2
...
...
@@ -19,9 +19,9 @@ class ProductController extends Controller
$products
=
$category
->
products
()
->
where
(
'active'
,
true
)
->
paginate
(
15
);
}
else
{
$products
=
Product
::
where
(
'active'
,
true
)
->
paginate
(
3
);
$products
=
Product
::
where
(
'active'
,
true
)
->
paginate
(
15
);
}
$otros
=
Product
::
where
(
'active'
,
true
)
->
inRandomOrder
()
->
take
(
3
)
->
get
();
$otros
=
Product
::
where
(
'active'
,
true
)
->
inRandomOrder
()
->
take
(
15
)
->
get
();
$categories
=
Category
::
where
(
'active'
,
true
)
->
get
();
return
view
(
'shop-public::list'
)
...
...
src/views/public/layout.blade.php
View file @
cbdc4da2
...
...
@@ -70,6 +70,22 @@ $util = new Onestartup\Shop\Libs\Util();
</script>
@endif
@if(Session::has('maximo'))
<script
type=
"text/javascript"
>
swal
(
"Problemas de existencia en inventario"
,
"Solo puedes agregar máximo {{Session::get('maximo')}} unidades de este producto"
,
"warning"
)
</script>
@endif
@if(Session::has('agotado'))
<script
type=
"text/javascript"
>
swal
(
"Problemas de existencia en inventario"
,
"Sentimos las inconveniencias, el producto se encuentra agotado por el momento, puedes enviarnos un correo y nosotos nos comunicaremos a la brevedad"
,
"warning"
)
</script>
@endif
@if(Session::has('url_ficha'))
<script>
...
...
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