| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Models\WpModels; |
| 4 |
|
| 5 |
use FluentCart\App\Models\Concerns\CanSearch; |
| 6 |
use FluentCart\App\Models\Model; |
| 7 |
use FluentCart\App\Models\Product; |
| 8 |
|
| 9 |
class TermTaxonomy extends Model |
| 10 |
{ |
| 11 |
use CanSearch; |
| 12 |
protected $table = 'term_taxonomy'; |
| 13 |
protected $primaryKey = 'term_id'; |
| 14 |
|
| 15 |
|
| 16 |
public function termRelationships() |
| 17 |
{ |
| 18 |
return $this->hasMany(TermRelationship::class, 'term_taxonomy_id', 'term_taxonomy_id'); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Get the term that owns the taxonomy |
| 23 |
*/ |
| 24 |
public function term() |
| 25 |
{ |
| 26 |
return $this->belongsTo(Term::class, 'term_id', 'term_id'); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Get the parent taxonomy |
| 31 |
*/ |
| 32 |
public function parent() |
| 33 |
{ |
| 34 |
return $this->belongsTo(TermTaxonomy::class, 'parent', 'term_taxonomy_id'); |
| 35 |
} |
| 36 |
|
| 37 |
public function taxonomy() |
| 38 |
{ |
| 39 |
return $this->belongsTo(Term::class, 'term_id', 'term_id'); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* Get child taxonomies |
| 45 |
*/ |
| 46 |
public function children() |
| 47 |
{ |
| 48 |
return $this->hasMany(TermTaxonomy::class, 'parent', 'term_taxonomy_id'); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Get all relationships for this taxonomy |
| 53 |
*/ |
| 54 |
public function relationships() |
| 55 |
{ |
| 56 |
return $this->hasMany(TermRelationship::class, 'term_taxonomy_id', 'term_taxonomy_id'); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Get all products for this taxonomy |
| 61 |
*/ |
| 62 |
public function products() |
| 63 |
{ |
| 64 |
return $this->hasManyThrough( |
| 65 |
Product::class, |
| 66 |
TermRelationship::class, |
| 67 |
'term_taxonomy_id', // Foreign key on term_relationships |
| 68 |
'ID', // Foreign key on products |
| 69 |
'term_taxonomy_id', // Local key on term_taxonomy |
| 70 |
'object_id' // Local key on term_relationships |
| 71 |
); |
| 72 |
} |
| 73 |
} |
| 74 |
|