refactoring on Articles, minor fixes
This commit is contained in:
25
app/Repositories/Shop/OfferStocks.php
Normal file
25
app/Repositories/Shop/OfferStocks.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class OfferStocks
|
||||
{
|
||||
public static function decreaseStock($item)
|
||||
{
|
||||
$offer = Offers::get($item['offer_id']);
|
||||
$offer->stock_current = $offer->stock_current - $item['quantity'];
|
||||
if ($offer->stock_current <= 0) {
|
||||
$offer->stock_current = 0;
|
||||
}
|
||||
|
||||
return $offer->save();
|
||||
}
|
||||
|
||||
public static function getStockCurrent($id)
|
||||
{
|
||||
return Offers::getField($id, 'stock_current');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user