Skip to content

AffiliateGroup PRO

Affiliate groups let you assign custom commission rates to sets of affiliates. Groups are stored in the fa_meta table with object_type = 'affiliate_group'.

Table: fa_meta (polymorphic via object_type = 'affiliate_group')
Class: FluentAffiliate\App\Models\AffiliateGroup

Storage Layout

ColumnUsage
meta_keyThe group name (human-readable label).
valueSerialized JSON: { rate_type, rate, status, notes }
object_typeAlways affiliate_group.
object_idAlways 0 (not linked to a parent object).

Value Fields

FieldTypeDescription
rate_typestringCommission type: percentage, flat, or default (inherit global).
ratefloatCommission rate value.
statusstringGroup status: active or inactive.
notesstringInternal notes about the group.

Relationships

MethodTypeTargetDescription
affiliates()hasManyAffiliateAffiliates assigned to this group via group_id.

Query Scopes

ScopeDescription
search($query)Full-text search on meta_key and value content.

Usage Example

php
use FluentAffiliate\App\Models\AffiliateGroup;

// List all active groups
$groups = AffiliateGroup::all()->filter(function($g) {
    return ($g->value['status'] ?? '') === 'active';
});

// Get all affiliates in a specific group
$group = AffiliateGroup::find($groupId);
$affiliates = $group->affiliates()->ofStatus('active')->get();

// Assign an affiliate to a group
$affiliate->update(['group_id' => $group->id]);

Commission Override Hierarchy

When calculating commission for an affiliate in a group, the rate is resolved in this order:

  1. Affiliate's individual rate and rate_type (if set).
  2. Group's rate and rate_type (if rate_type !== 'default').
  3. Global referral program defaults.

Released under the GPL-2.0 License.