Skip to content

Attribute Term Model

DB Table Name{wp_db_prefix}_fct_atts_terms
SchemaCheck Schema
Source Filefluent-cart/app/Models/AttributeTerm.php
Name SpaceFluentCart\App\Models
ClassFluentCart\App\Models\AttributeTerm

Attributes

AttributeData TypeComment
idIntegerPrimary Key
group_idIntegerReference to attribute group
serialIntegerSerial number for ordering
titleStringAttribute term title (e.g., Red, Small, Large)
slugStringAttribute term slug
descriptionTextAttribute term description
settingsJSONAttribute term settings
created_atDate TimeCreation timestamp
updated_atDate TimeLast update timestamp

Usage

Please check Model Basic for Common methods.

Accessing Attributes

php
$attributeTerm = FluentCart\App\Models\AttributeTerm::find(1);

$attributeTerm->id; // returns id
$attributeTerm->group_id; // returns group ID
$attributeTerm->title; // returns title
$attributeTerm->slug; // returns slug

Scopes

This model has the following scopes that you can use

applyCustomFilters($filters)

Apply custom filters to the query

  • Parameters
    • $filters - array

Usage:

php
// Apply custom filters
$filteredTerms = FluentCart\App\Models\AttributeTerm::applyCustomFilters([
    'title' => ['value' => 'Red', 'operator' => 'includes'],
    'group_id' => ['value' => 1, 'operator' => '=']
])->get();

Relations

This model has the following relationships that you can use

group

Access the associated attribute group

  • return FluentCart\App\Models\AttributeGroup Model

Example:

php
// Accessing Group
$group = $attributeTerm->group;

// For Filtering by group relationship
$attributeTerms = FluentCart\App\Models\AttributeTerm::whereHas('group', function($query) {
    $query->where('title', 'Color');
})->get();

Methods

Along with Global Model methods, this model has few helper methods.

setSettingsAttribute($value)

Set settings with automatic JSON encoding (mutator)

  • Parameters
    • $value - mixed (array, object, or string)
  • Returns void

Usage

php
$attributeTerm->settings = ['color_code' => '#FF0000', 'display_order' => 1];
// Automatically JSON encodes arrays and objects

getSettingsAttribute($value)

Get settings with automatic JSON decoding (accessor)

  • Parameters
    • $value - mixed
  • Returns mixed

Usage

php
$settings = $attributeTerm->settings; // Returns decoded value (array, object, or string)

Usage Examples

Get Attribute Terms

php
$attributeTerm = FluentCart\App\Models\AttributeTerm::find(1);
echo "Title: " . $attributeTerm->title;
echo "Slug: " . $attributeTerm->slug;
echo "Group ID: " . $attributeTerm->group_id;

Create Attribute Term

php
$attributeTerm = FluentCart\App\Models\AttributeTerm::create([
    'group_id' => 1,
    'serial' => 1,
    'title' => 'Red',
    'slug' => 'red',
    'description' => 'Red color variant',
    'settings' => [
        'color_code' => '#FF0000',
        'display_order' => 1,
        'is_default' => false
    ]
]);

Get Terms by Group

php
$colorTerms = FluentCart\App\Models\AttributeTerm::where('group_id', 1)->get();
$sizeTerms = FluentCart\App\Models\AttributeTerm::where('group_id', 2)->get();

Get Terms with Group Information

php
$attributeTerms = FluentCart\App\Models\AttributeTerm::with('group')->get();

foreach ($attributeTerms as $term) {
    echo "Term: " . $term->title;
    echo "Group: " . $term->group->title;
}

Apply Custom Filters

php
$filters = [
    'title' => ['value' => 'Red', 'operator' => 'includes'],
    'group_id' => ['value' => 1, 'operator' => '=']
];

$filteredTerms = FluentCart\App\Models\AttributeTerm::applyCustomFilters($filters)->get();

Get Terms by Title

php
$redTerms = FluentCart\App\Models\AttributeTerm::where('title', 'Red')->get();
$smallTerms = FluentCart\App\Models\AttributeTerm::where('title', 'Small')->get();

Get Terms Ordered by Serial

php
$orderedTerms = FluentCart\App\Models\AttributeTerm::where('group_id', 1)
    ->orderBy('serial', 'asc')
    ->get();

Update Attribute Term

php
$attributeTerm = FluentCart\App\Models\AttributeTerm::find(1);
$attributeTerm->update([
    'title' => 'Bright Red',
    'settings' => ['color_code' => '#CC0000', 'display_order' => 2]
]);

Get Terms with Settings

php
$termsWithSettings = FluentCart\App\Models\AttributeTerm::where('group_id', 1)->get();

foreach ($termsWithSettings as $term) {
    $settings = $term->settings;
    if (isset($settings['color_code'])) {
        echo "Term: " . $term->title . " - Color: " . $settings['color_code'];
    }
}

FluentCart developer documentation