Fix some enhancements & new features

This commit is contained in:
Ludovic CANDELLIER
2020-07-26 16:51:45 +02:00
parent fcd26d13de
commit 1179b5ca31
54 changed files with 975 additions and 341 deletions

View File

@@ -11,40 +11,37 @@ use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
class Article extends Model implements HasMedia
{
use Categorizable;
use Taggable;
use HasMediaTrait;
use EloquentJoin;
use Categorizable, Taggable, HasMediaTrait, EloquentJoin;
protected $guarded = ['id'];
protected $table = 'shop_articles';
public function Family()
public function article_family()
{
return $this->belongsTo('App\Models\Shop\ArticleFamily','article_family_id');
return $this->belongsTo('App\Models\Shop\ArticleFamily');
}
public function Inventories()
public function attributes()
{
return $this->hasMany('App\Models\Shop\ArticleAttribute');
}
public function prices()
{
return $this->hasManyThrough('App\Models\Shop\ArticlePrice','App\Models\Shop\ArticleAttribute');
}
public function inventories()
{
return $this->hasMany('App\Models\Shop\Inventory');
}
public function Prices()
{
return $this->hasMany('App\Models\Shop\ArticlePrice');
}
public function Attributes()
{
return $this->hasManyThrough('App\Models\Shop\ArticleAttribute','App\Models\Shop\ArticlePrice');
}
public function InvoiceItems()
public function invoiceItems()
{
return $this->hasMany('App\Models\Shop\InvoiceItem');
}
public function Product()
public function product()
{
return $this->belongsTo($this->model, 'model_id');
}

View File

@@ -9,23 +9,28 @@ class ArticleAttribute extends Model
protected $guarded = ['id'];
protected $table = 'shop_article_attributes';
public function Price()
public function article()
{
return $this->belongsTo('App\Models\Shop\Article');
}
public function attribute_value()
{
return $this->belongsTo('App\Models\Shop\ArticlePrice','article_price_id');
return $this->belongsTo('App\Models\Shop\ArticleAttributeValue');
}
public function Value()
public function prices()
{
return $this->belongsTo('App\Models\Shop\ArticleAttributeValue','attribute_value_id');
return $this->hasMany('App\Models\Shop\ArticlePrice');
}
public function scopeByPrice($query, $article_price_id)
public function scopeByArticle($query, $id)
{
return $query->where('article_price_id', $article_price_id);
return $query->where('article_id', $id);
}
public function scopeByAttribueValue($query, $article_value_id)
public function scopeByAttributeValue($query, $id)
{
return $query->where('article_value_id', $article_value_id);
return $query->where('attribute_value_id', $id);
}
}

View File

@@ -3,15 +3,23 @@
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
class ArticleAttributeFamily extends Model
{
use HasRelationships;
protected $guarded = ['id'];
protected $table = 'shop_article_attribute_families';
public function Attributes()
public function values()
{
return $this->hasMany('App\Models\Shop\ArticleAttributeValue');
}
public function articles()
{
return $this->hasManyThrough('App\Models\Shop\ArticleAttribute','App\Models\Shop\ArticleAttributeValue');
}
}

View File

@@ -9,14 +9,24 @@ class ArticleAttributeValue extends Model
protected $guarded = ['id'];
protected $table = 'shop_article_attribute_values';
public function ArticleAttributeFamily()
public function article_attribute_family()
{
return $this->belongsTo('App\Models\Shop\ArticleAttributeFamily');
}
public function scopeByFamily($query, $attribute_family_id)
public function attributes()
{
return $this->hasMany('App\Models\Shop\ArticleAttribute');
}
public function articles()
{
return $this->hasMany('App\Models\Shop\ArticleAttribute')->groupBy('article_id');
}
public function scopeByFamily($query, $id)
{
return $query->where('article_attribute_family_id', $attribute_family_id);
return $query->where('article_attribute_family_id', $id);
}
}

View File

@@ -9,12 +9,12 @@ class ArticleCategory extends Model
protected $guarded = ['id'];
protected $table = 'shop_article_categories';
public function Article()
public function article()
{
return $this->belongsTo('App\Models\Shop\Article');
}
public function Category()
public function category()
{
return $this->belongsTo('App\Models\Shop\Category');
}

View File

@@ -9,10 +9,7 @@ class ArticleFamily extends Model
protected $guarded = ['id'];
protected $table = 'shop_article_families';
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function Articles()
public function articles()
{
return $this->hasMany('App\Models\Shop\Article');
}

View File

@@ -9,19 +9,14 @@ class ArticlePrice extends Model
protected $guarded = ['id'];
protected $table = 'shop_article_prices';
public function Article()
public function article_attribute()
{
return $this->belongsTo('App\Models\Shop\ArticleAttribute');
}
public function article()
{
return $this->belongsTo('App\Models\Shop\Article');
}
public function ArticleAttributes()
{
return $this->hasMany('App\Models\Shop\ArticleAttribute');
}
public function scopeByArticle($query, $id)
{
return $query->where('article_id', $id);
}
}