Skip to content

Order Item Model

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

Attributes

AttributeData TypeComment
idIntegerPrimary Key
order_idIntegerReference to order
post_idIntegerWordPress post ID (product)
fulfillment_typeStringFulfillment type (physical, digital, service)
payment_typeStringPayment type (onetime, subscription, signup_fee)
post_titleTextProduct title
titleTextItem title (variation)
object_idIntegerVariation ID
cart_indexIntegerPosition in cart
quantityIntegerItem quantity
unit_priceBigintPrice per unit in cents
costBigintCost in cents
subtotalBigintLine subtotal
tax_amountBigintTax amount for this line
shipping_chargeBigintShipping charge
discount_totalBigintDiscount amount
line_totalBigintTotal line amount
refund_totalBigintRefunded amount
rateBigintExchange rate
other_infoJSONAdditional item data
line_metaJSONLine-specific metadata
fulfilled_quantityIntegerQuantity fulfilled
referrerTextReferral information
object_typeStringObject type
created_atDate TimeCreation timestamp
updated_atDate TimeLast update timestamp

Usage

Please check Model Basic for Common methods.

Accessing Attributes

php
$orderItem = FluentCart\App\Models\OrderItem::find(1);

$orderItem->id; // returns id
$orderItem->order_id; // returns order ID
$orderItem->quantity; // returns quantity
$orderItem->unit_price; // returns unit price
$orderItem->line_total; // returns line total

Scopes

This model has the following scopes that you can use

ofOrder($orderId)

Filter order items by order ID

  • Parameters
    • $orderId - integer

Usage:

php
// Get all items for a specific order
$orderItems = FluentCart\App\Models\OrderItem::ofOrder(123)->get();

ofProduct($productId)

Filter order items by product ID

  • Parameters
    • $productId - integer

Usage:

php
// Get all order items for a specific product
$orderItems = FluentCart\App\Models\OrderItem::ofProduct(456)->get();

ofFulfillmentType($type)

Filter order items by fulfillment type

  • Parameters
    • $type - string

Usage:

php
// Get all digital order items
$orderItems = FluentCart\App\Models\OrderItem::ofFulfillmentType('digital')->get();

ofPaymentType($type)

Filter order items by payment type

  • Parameters
    • $type - string

Usage:

php
// Get all subscription order items
$orderItems = FluentCart\App\Models\OrderItem::ofPaymentType('subscription')->get();

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 = $orderItem->order;

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

product

Access the associated product

  • return FluentCart\App\Models\Product Model

Example:

php
// Accessing Product
$product = $orderItem->product;

// For Filtering by product relationship
$orderItems = FluentCart\App\Models\OrderItem::whereHas('product', function($query) {
    $query->where('post_status', 'publish');
})->get();

variation

Access the associated product variation

  • return FluentCart\App\Models\ProductVariation Model

Example:

php
// Accessing Product Variation
$variation = $orderItem->variation;

Methods

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

getFormattedTotalAttribute()

Get formatted line total (accessor)

  • Parameters
    • none
  • Returns float

Usage

php
$formattedTotal = $orderItem->formatted_total; // Returns: 99.99

getPaymentInfoAttribute()

Get payment information (accessor)

  • Parameters
    • none
  • Returns array

Usage

php
$paymentInfo = $orderItem->payment_info;

getSetupInfoAttribute()

Get setup information (accessor)

  • Parameters
    • none
  • Returns array

Usage

php
$setupInfo = $orderItem->setup_info;

getOtherInfoAttribute($value)

Get other info as array (accessor)

  • Parameters
    • $value - mixed
  • Returns array

Usage

php
$otherInfo = $orderItem->other_info; // Returns array

setOtherInfoAttribute($value)

Set other info from array (mutator)

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

Usage

php
$orderItem->other_info = ['custom_field' => 'value'];

getLineMetaAttribute($value)

Get line meta as array (accessor)

  • Parameters
    • $value - mixed
  • Returns array

Usage

php
$lineMeta = $orderItem->line_meta; // Returns array

setLineMetaAttribute($value)

Set line meta from array (mutator)

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

Usage

php
$orderItem->line_meta = ['custom_meta' => 'value'];

getTotalAmount()

Get total amount for this line item

  • Parameters
    • none
  • Returns float

Usage

php
$totalAmount = $orderItem->getTotalAmount();

getFormattedUnitPrice()

Get formatted unit price with currency

  • Parameters
    • none
  • Returns string

Usage

php
$formattedPrice = $orderItem->getFormattedUnitPrice(); // Returns: "$29.99"

getFormattedLineTotal()

Get formatted line total with currency

  • Parameters
    • none
  • Returns string

Usage

php
$formattedTotal = $orderItem->getFormattedLineTotal(); // Returns: "$59.98"

isFulfilled()

Check if order item is fully fulfilled

  • Parameters
    • none
  • Returns boolean

Usage

php
$isFulfilled = $orderItem->isFulfilled();

isPartiallyFulfilled()

Check if order item is partially fulfilled

  • Parameters
    • none
  • Returns boolean

Usage

php
$isPartiallyFulfilled = $orderItem->isPartiallyFulfilled();

getRemainingQuantity()

Get remaining quantity to fulfill

  • Parameters
    • none
  • Returns integer

Usage

php
$remainingQuantity = $orderItem->getRemainingQuantity();

isSubscription()

Check if order item is a subscription

  • Parameters
    • none
  • Returns boolean

Usage

php
$isSubscription = $orderItem->isSubscription();

isDigital()

Check if order item is digital

  • Parameters
    • none
  • Returns boolean

Usage

php
$isDigital = $orderItem->isDigital();

isPhysical()

Check if order item is physical

  • Parameters
    • none
  • Returns boolean

Usage

php
$isPhysical = $orderItem->isPhysical();

FluentCart developer documentation