add shipping rules

This commit is contained in:
Ludovic CANDELLIER
2023-07-16 14:45:42 +02:00
parent 72a7b270f9
commit 0879b0abf0
459 changed files with 6219 additions and 5416 deletions

View File

@@ -2,30 +2,51 @@
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia;
use Rinvex\Categories\Traits\Categorizable;
use Rinvex\Tags\Traits\Taggable;
use Kirschbaum\PowerJoins\PowerJoins;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
use Wildside\Userstamps\Userstamps;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use App\Models\Botanic\Specie;
use App\Models\Botanic\Variety;
use App\Traits\Model\HasComments;
use App\Traits\Model\Imageable;
use App\Models\Botanic\Variety;
use App\Models\Botanic\Specie;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kirschbaum\PowerJoins\PowerJoins;
use Rinvex\Categories\Traits\Categorizable;
use Rinvex\Tags\Traits\Taggable;
use Spatie\MediaLibrary\HasMedia;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use \Venturecraft\Revisionable\RevisionableTrait;
use Wildside\Userstamps\Userstamps;
class Article extends Model implements HasMedia
{
use Categorizable, EloquentJoin, HasComments, HasRelationships, Imageable, Powerjoins, Taggable, SoftDeletes, UserStamps;
use Categorizable;
use EloquentJoin;
use HasComments;
use HasRelationships;
use Imageable;
use Powerjoins;
use RevisionableTrait;
use Taggable;
use SoftDeletes;
use UserStamps;
protected $guarded = ['id'];
protected $table = 'shop_articles';
protected $revisionEnabled = true;
protected $keepRevisionOf = [
'article_nature_id',
'product_type',
'product_id',
'ref',
'name',
'description',
'visible',
'homepage',
];
public function article_nature()
{
return $this->belongsTo(ArticleNature::class);
@@ -84,54 +105,55 @@ class Article extends Model implements HasMedia
public function scopeByArticle($query, $id)
{
return $query->where($this->table . '.id', $id);
return $query->where($this->table.'.id', $id);
}
public function scopeByAutocomplete($query, $str)
{
return $query->where($this->table . '.name', 'LIKE', '%' . $str .'%');
return $query->where($this->table.'.name', 'LIKE', '%'.$str.'%');
}
public function scopeSearch($query, $str)
{
return $query->where($this->table . '.name', 'LIKE', '%' . $str .'%');
return $query->where($this->table.'.name', 'LIKE', '%'.$str.'%');
}
public function scopeByArticleNature($query, $id)
{
return $id ? $query->where($this->table . '.article_nature_id', $id) : $query;
return $id ? $query->where($this->table.'.article_nature_id', $id) : $query;
}
public function scopeByArticleNatures($query, $ids)
{
return $ids ? $query->whereIn($this->table . '.article_nature_id', $ids) : $query;
return $ids ? $query->whereIn($this->table.'.article_nature_id', $ids) : $query;
}
public function scopeByCategories($query, $categories_id)
public function scopeByCategories($query, $categoriesId)
{
return $categories_id ? $query->whereHas('categories', function ($query) use ($categories_id) {
$query->whereIn('id', $categories_id);
return $categoriesId ? $query->whereHas('categories', function ($query) use ($categoriesId) {
$query->whereIn('id', $categoriesId);
}) : $query;
}
public function scopeByCategoryParent($query, $category_id)
public function scopeByCategoryParent($query, $categoryId)
{
$category = Category::find($category_id);
return $category_id ? $query->whereHas('categories', function ($query) use ($category) {
$category = Category::find($categoryId);
return $categoryId ? $query->whereHas('categories', function ($query) use ($category) {
$query->where('_lft', '>=', $category->_lft)->where('_rgt', '<=', $category->_rgt);
}) : $query;
}
public function scopeByCategory($query, $category_id)
public function scopeByCategory($query, $categoryId)
{
return $category_id ? $query->whereHas('categories', function ($query) use ($category_id) {
$query->where('id', $category_id);
return $categoryId ? $query->whereHas('categories', function ($query) use ($categoryId) {
$query->where('id', $categoryId);
}) : $query;
}
public function scopeBotanic($query)
{
return $query->whereIn($this->table . '.product_type', [Variety::class, Specie::class]);
return $query->whereIn($this->table.'.product_type', [Variety::class, Specie::class]);
}
public function scopeMerchandise($query)
@@ -141,18 +163,18 @@ class Article extends Model implements HasMedia
public function scopeByProduct($query, $model)
{
return $model ? $query->where($this->table . '.product_type', $model) : $query;
return $model ? $query->where($this->table.'.product_type', $model) : $query;
}
public function scopeByProductId($query, $product_id)
public function scopeByProductId($query, $productId)
{
return $product_id ? $query->where($this->table . '.product_id', $product_id) : $query;
return $productId ? $query->where($this->table.'.product_id', $productId) : $query;
}
public function scopeByTag($query, $tag_id)
public function scopeByTag($query, $tagId)
{
return $tag_id ? $query->whereHas('tags', function ($query) use ($tag_id) {
$query->where('id', $tag_id);
return $tagId ? $query->whereHas('tags', function ($query) use ($tagId) {
$query->where('id', $tagId);
}) : $query;
}
@@ -177,20 +199,20 @@ class Article extends Model implements HasMedia
return $query->has('offers');
}
public function scopeWithAvailableOffers($query, $sale_channel_id = false)
public function scopeWithAvailableOffers($query, $saleChannelId = false)
{
return $query->whereHas('offers', function ($query) use ($sale_channel_id) {
$query->active()->byStockAvailable()->bySaleChannel($sale_channel_id);
return $query->whereHas('offers', function ($query) use ($saleChannelId) {
$query->active()->byStockAvailable()->bySaleChannel($saleChannelId);
});
}
public function scopeVisible($query)
{
return $query->where($this->table . '.visible', 1);
return $query->where($this->table.'.visible', 1);
}
public function scopeHomepage($query)
{
return $query->where($this->table . '.homepage', 1);
return $query->where($this->table.'.homepage', 1);
}
}