Skip to content

Commit

Permalink
Merge pull request #19 from ghermans/main
Browse files Browse the repository at this point in the history
added status check
  • Loading branch information
ghermans authored Oct 20, 2021
2 parents 9894916 + 775a99c commit 7c94dbd
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Console/Commands/SendOutOfStockNotifcation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@ public function __construct()
*/
public function handle()
{
$query = DB::table('product_flat')
->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
->leftJoin('product_inventories', 'product_flat.product_id', '=', 'product_inventories.product_id')
->select(
'product_flat.product_id',
DB::raw('SUM(DISTINCT ' . DB::getTablePrefix() . 'product_inventories.qty) as quantity'),
'product_flat.locale',
'product_flat.channel'
)
->where('product_flat.status', '=', 1)
->where('product_inventories.qty', '=<', core()->getConfigData('catalog.inventory.notifications.min-stock'))
->orderBy('product_flat.id', 'DESC')->groupBy('product_flat.product_id', 'product_flat.locale', 'product_flat.channel')->exists();

if ($query) {
$admins = Admin::all();

foreach($admins as $admin) {
return Mail::to($admin->email)->send(new OutOfStock());
if (core()->getConfigData('catalog.inventory.notifications.status')) {
$query = DB::table('product_flat')
->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
->leftJoin('product_inventories', 'product_flat.product_id', '=', 'product_inventories.product_id')
->select(
'product_flat.product_id',
DB::raw('SUM(DISTINCT ' . DB::getTablePrefix() . 'product_inventories.qty) as quantity'),
'product_flat.locale',
'product_flat.channel'
)
->where('product_flat.status', '=', 1)
->where('product_inventories.qty', '=<', core()->getConfigData('catalog.inventory.notifications.min-stock'))
->orderBy('product_flat.id', 'DESC')->groupBy('product_flat.product_id', 'product_flat.locale', 'product_flat.channel')->exists();

if ($query) {
$admins = Admin::all();

foreach($admins as $admin) {
return Mail::to($admin->email)->send(new OutOfStock());
}
}
}
}
Expand Down

0 comments on commit 7c94dbd

Please sign in to comment.