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
ae761b2a
Commit
ae761b2a
authored
Jun 01, 2018
by
Angel MAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notify products stock
parent
6e5a34af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
0 deletions
+79
-0
Util.php
src/lib/Util.php
+9
-0
StockNotify.php
src/notifications/StockNotify.php
+70
-0
No files found.
src/lib/Util.php
View file @
ae761b2a
...
...
@@ -3,6 +3,8 @@
namespace
Onestartup\Shop\Libs
;
use
Onestartup\Shop\Model\ProductShop
as
Product
;
use
Onestartup\Shop\Notifications\StockNotify
;
use
App\User
;
class
Util
{
...
...
@@ -24,12 +26,19 @@ class Util
public
function
stock_change
(
$sale
,
$old
)
{
$products
=
$sale
->
products
;
$admin
=
User
::
first
();
if
(
$sale
->
status
==
2
)
{
foreach
(
$products
as
$product
)
{
$aux
=
Product
::
find
(
$product
->
id
);
$aux
->
infoSale
()
->
decrement
(
'quantity'
,
$product
->
pivot
->
quantity
);
$info
=
$aux
->
infoSale
;
if
(
$info
->
quantity
<=
$info
->
reserve_amount
)
{
$admin
->
notify
(
new
StockNotify
(
$product
));
}
}
}
else
{
...
...
src/notifications/StockNotify.php
0 → 100644
View file @
ae761b2a
<?php
namespace
Onestartup\Shop\Notifications
;
use
Illuminate\Bus\Queueable
;
use
Illuminate\Notifications\Notification
;
use
Illuminate\Contracts\Queue\ShouldQueue
;
use
Illuminate\Notifications\Messages\MailMessage
;
use
Onestartup\Shop\Model\ProductShop
as
Product
;
class
StockNotify
extends
Notification
{
use
Queueable
;
protected
$product
;
/**
* Create a new notification instance.
*
* @return void
*/
public
function
__construct
(
Product
$product
)
{
$this
->
product
=
$product
;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public
function
via
(
$notifiable
)
{
return
[
'mail'
];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public
function
toMail
(
$notifiable
)
{
return
(
new
MailMessage
)
->
greeting
(
'Hola apreciable administrador'
)
->
subject
(
'Verificar existencia de producto: '
.
$this
->
product
->
name
)
->
line
(
'El producto '
.
$this
->
product
->
name
.
' esta agotado o proximo a agotarse'
)
->
line
(
'Verifica la existencia del producto y actualiza su información'
)
->
action
(
'Ver producto'
,
route
(
'admin.shop.product.edit'
,
$this
->
product
->
id
));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public
function
toArray
(
$notifiable
)
{
return
[
//
];
}
}
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