From 11370fa043dc1efcfe3aad70ca8362bae8ba73b1 Mon Sep 17 00:00:00 2001 From: Shohrat Date: Tue, 3 Oct 2023 17:10:50 +0500 Subject: [PATCH] scopes --- plugins/tps/birzha/models/Category.php | 19 ++++++++++++++++++- plugins/tps/birzha/models/Product.php | 12 ++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/plugins/tps/birzha/models/Category.php b/plugins/tps/birzha/models/Category.php index 8bbab70..ff3a3ca 100644 --- a/plugins/tps/birzha/models/Category.php +++ b/plugins/tps/birzha/models/Category.php @@ -36,9 +36,10 @@ class Category extends Model ]; public $translatable = ['name',['slug', 'index' => true]]; - + public $hasMany = [ 'filter_group' => ['TPS\Birzha\Models\FilterGroups', 'key' => 'category_id'], + 'subs' => ['TPS\Birzha\Models\Category', 'key' => 'primary_key'] ]; @@ -60,6 +61,22 @@ class Category extends Model return $query->where('status', 1); } + public function scopeActiveAndParent($query) + { + return $query->where('status', 1)->where('primary_key',0); + } + + + public function scopeActiveAndParentFirstFour($query) + { + return $query->where('status', 1)->where('primary_key', 0)->offset(0)->limit(4); + } + + public function scopeActiveAndParentLastFour($query) + { + return $query->where('status', 1)->where('primary_key', 0)->offset(4)->limit(8); + } + public static function getMenuTypeInfo($type){ $result = []; diff --git a/plugins/tps/birzha/models/Product.php b/plugins/tps/birzha/models/Product.php index 86013ef..6736ccb 100644 --- a/plugins/tps/birzha/models/Product.php +++ b/plugins/tps/birzha/models/Product.php @@ -49,20 +49,20 @@ class Product extends Model public $belongsToMany = [ 'categories' => ['TPS\Birzha\Models\Category','table' => 'tps_birzha_product_categories'], //'favourites' => ['TPS\Birzha\Models\Favourites','table' => 'tps_birzha_favourites'], - + ]; public $belongsTo = [ - //'place' => City::class, + 'place' => City::class, 'order_item' => OrderItems::class, - 'place' => ['TPS\Birzha\Models\City','key' => 'place_id'], + //'measure' => ['TPS\Birzha\Models\Measure','key' => 'measure_id'], //'currency' => ['TPS\Birzha\Models\Currency'], //'payment_term' => ['TPS\Birzha\Models\Term','key' => 'payment_term_id'], //'delivery_term' => ['TPS\Birzha\Models\Term','key' => 'delivery_term_id'], 'vendor' => User::class, //'payment' => ['TPS\Birzha\Models\Payment'], ]; - + public $hasMany = [ 'favourites' => ['TPS\Birzha\Models\Favourites', 'table' => 'tps_birzha_favourites'], 'comments' => ['TPS\Birzha\Models\Comment','table' => 'tps_birzha_comments'], @@ -100,6 +100,10 @@ class Product extends Model return $query->where('status', 'approved'); } + public function scopeVipProducts($query, $type) { + return $query->where('type', $type)->where('status', 'approved')->withCount("images"); + } + public function scopeSearched($query, $locale, $queryString) { if($locale == 'tm') {