Skip to content

Order Operation Model

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

Attributes

AttributeData TypeComment
idIntegerPrimary Key
order_idIntegerReference to order
created_viaStringHow the order was created
has_taxBooleanWhether order has tax
has_discountBooleanWhether order has discount
coupons_countedIntegerNumber of coupons applied
emails_sentIntegerNumber of emails sent
sales_recordedBooleanWhether sales were recorded
utm_campaignStringUTM campaign parameter
utm_termStringUTM term parameter
utm_sourceStringUTM source parameter
utm_contentStringUTM content parameter
utm_mediumStringUTM medium parameter
utm_idStringUTM ID parameter
cart_hashStringCart hash identifier
refer_urlStringReferral URL
metaJSONAdditional operation data
created_atDate TimeCreation timestamp
updated_atDate TimeLast update timestamp

Usage

Please check Model Basic for Common methods.

Accessing Attributes

php
$orderOperation = FluentCart\App\Models\OrderOperation::find(1);

$orderOperation->id; // returns id
$orderOperation->order_id; // returns order ID
$orderOperation->created_via; // returns creation method
$orderOperation->has_tax; // returns tax status

Relations

This model has the following relationships that you can use

order

Access the associated order

  • return FluentCart\App\Models\Order Model

Example:

php
// Accessing Order
$order = $orderOperation->order;

// For Filtering by order relationship
$orderOperations = FluentCart\App\Models\OrderOperation::whereHas('order', function($query) {
    $query->where('status', 'completed');
})->get();

Methods

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

setMetaAttribute($value)

Set meta from array (mutator)

  • Parameters
    • $value - array|object
  • Returns void

Usage

php
$orderOperation->meta = ['analytics_data' => 'value', 'tracking_info' => 'data'];

getMetaAttribute($value)

Get meta as array (accessor)

  • Parameters
    • $value - mixed
  • Returns array

Usage

php
$meta = $orderOperation->meta; // Returns array

Usage Examples

Get Order Operations

php
$order = FluentCart\App\Models\Order::find(123);
$operations = $order->order_operations;

foreach ($operations as $operation) {
    echo "Created via: " . $operation->created_via;
    echo "UTM Campaign: " . $operation->utm_campaign;
}

Get Operations by UTM Source

php
$googleOperations = FluentCart\App\Models\OrderOperation::where('utm_source', 'google')->get();
$facebookOperations = FluentCart\App\Models\OrderOperation::where('utm_source', 'facebook')->get();

Create Order Operation

php
$orderOperation = FluentCart\App\Models\OrderOperation::create([
    'order_id' => 123,
    'created_via' => 'checkout',
    'has_tax' => true,
    'has_discount' => true,
    'coupons_counted' => 2,
    'emails_sent' => 3,
    'sales_recorded' => true,
    'utm_campaign' => 'summer_sale',
    'utm_source' => 'google',
    'utm_medium' => 'cpc',
    'cart_hash' => 'abc123def456',
    'refer_url' => 'https://example.com/products'
]);

Track UTM Parameters

php
$orderOperation = FluentCart\App\Models\OrderOperation::create([
    'order_id' => 123,
    'utm_campaign' => 'black_friday',
    'utm_source' => 'facebook',
    'utm_medium' => 'social',
    'utm_content' => 'banner_ad',
    'utm_term' => 'discount',
    'utm_id' => 'fb_123'
]);

FluentCart developer documentation