change construction of articles/offers
This commit is contained in:
@@ -38,12 +38,15 @@ class Article extends Model implements HasMedia
|
||||
return $this->hasMany(Offer::class);
|
||||
}
|
||||
|
||||
/*
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasManyDeep(PriceListValue::class, [Offer::class, Tariff::class, PriceList::class]);
|
||||
return $this->hasManyDeep(
|
||||
PriceListValue::class,
|
||||
[Offer::class, Tariff::class, PriceList::class],
|
||||
['article_id', 'id', 'tariff_id'],
|
||||
['id', 'tariff_id', 'id'],
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
public function product()
|
||||
{
|
||||
@@ -120,7 +123,7 @@ class Article extends Model implements HasMedia
|
||||
public function scopeWithAvailableOffers($query)
|
||||
{
|
||||
return $query->whereHas('offers', function ($query) {
|
||||
$query->byStatus(1);
|
||||
$query->active();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class Offer extends Model
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where($this->table . '.status_id', 1);
|
||||
return $query->byStatus(1)->byTariffActive();
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
@@ -77,6 +77,11 @@ class Offer extends Model
|
||||
return $query->whereIn($this->table . '.article_id', $ids);
|
||||
}
|
||||
|
||||
public function scopeByID($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.id', $id);
|
||||
}
|
||||
|
||||
public function scopeByOffer($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.id', $id);
|
||||
@@ -126,4 +131,11 @@ class Offer extends Model
|
||||
$query->whereIn('tag_id', $tags);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByTariffActive($query)
|
||||
{
|
||||
return $query->whereHas('tariff', function ($query) {
|
||||
$query->active();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,15 @@ class PriceList extends Model
|
||||
return $query->where($this->table . '.status_id', $id);
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->byStatus(0)->has('price_list_values');
|
||||
}
|
||||
|
||||
public function scopeByOffer($query, $id)
|
||||
{
|
||||
return $query->whereHas('offers', function ($query) use ($id) {
|
||||
$query->byOffer($id);
|
||||
$query->byID($id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ class Tariff extends Model
|
||||
public function scopeByAutocomplete($query, $str)
|
||||
{
|
||||
return $query->where($this->table . '.name', 'LIKE', "%${str}%")
|
||||
->orWhere($this->table . '.ref', 'LIKE', "${str}%")
|
||||
->orWhere($this->table . '.code', 'LIKE', "${str}%");
|
||||
->orWhere($this->table . '.ref', 'LIKE', "${str}%")
|
||||
->orWhere($this->table . '.code', 'LIKE', "${str}%");
|
||||
}
|
||||
|
||||
public function scopeBySaleChanel($query, $id)
|
||||
@@ -67,7 +67,19 @@ class Tariff extends Model
|
||||
public function scopeByOffer($query, $id)
|
||||
{
|
||||
return $query->whereHas('offers', function ($query) use ($id) {
|
||||
$query->where('id', $id);
|
||||
$query->byID($id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->byStatus(0)->byPriceListsActive();
|
||||
}
|
||||
|
||||
public function scopeByPriceListsActive($query)
|
||||
{
|
||||
return $query->whereHas('price_lists', function ($query) {
|
||||
$query->active();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user