add constaint on stock

This commit is contained in:
Ludovic CANDELLIER
2022-03-07 20:17:50 +01:00
parent 5794cbb045
commit 30876ba67d
6 changed files with 9 additions and 122 deletions

View File

@@ -123,7 +123,7 @@ class Article extends Model implements HasMedia
public function scopeWithAvailableOffers($query, $sale_channel_id = false)
{
return $query->whereHas('offers', function ($query) use ($sale_channel_id) {
$query->active()->bySaleChannel($sale_channel_id);
$query->active()->byStockAvailable()->bySaleChannel($sale_channel_id);
});
}

View File

@@ -97,6 +97,11 @@ class Offer extends Model
return $query->where($this->table . '.variation_id', $id);
}
public function scopeByStockAvailable($query)
{
return $query->where($this->table . '.stock_current', '>', 0);
}
public function scopeByArticleNature($query, $article_nature_id)
{
return $query->whereHas('article.article_nature', function ($query) use ($article_nature_id) {
@@ -145,5 +150,4 @@ class Offer extends Model
$query->active()->bySaleChannel($sale_channel_id);
});
}
}

View File

@@ -143,6 +143,9 @@ class Articles
'product',
'article_nature',
'offers.variation.package',
'offers.tariff.price_lists' => function($query) use ($sale_channel_id) {
$query->bySaleChannel($sale_channel_id);
},
'offers.tariff.price_lists.price_list_values',
])->get();
}