LineItem

Type
Class
Namespace
craft\commerce\models
Inherits
craft\commerce\models\LineItem » craft\commerce\base\Model » craft\base\Model » yii\base\Model » yii\base\Component » yii\base\BaseObject
Implements
ArrayAccess, IteratorAggregate, yii\base\Arrayable, yii\base\Configurable, yii\base\StaticInstanceInterface
Uses traits
craft\base\ClonefixTrait, yii\base\ArrayableTrait, yii\base\StaticInstanceTrait
Since
2.0

Line Item model representing a line item on an order.

View source

Public Properties

PropertyDescription
$activeValidatorsyii\validators\Validator – The validators applicable to the current $scenario.
$adjustmentscraft\commerce\models\OrderAdjustment[]
$adjustmentsTotalfloat
$attributesarray – Attribute values (name => value).
$behaviorsyii\base\Behavior – List of behaviors attached to this component
$description
$discountfloat
$errorsarray – Errors for all attributes or the specified attribute.
$firstErrorsarray – The first errors.
$heightfloat – Height
$idinteger – ID
$iteratorArrayIterator – An iterator for traversing the items in the list.
$lengthfloat – Length
$notestring – Note
$onSaleboolean
$options
$optionsSignature
$ordercraft\commerce\elements\Order, null
$orderIdinteger – Order ID
$pricefloat – Price
$purchasablecraft\commerce\base\PurchasableInterface, null
$purchasableIdinteger – Purchasable ID
$qtyinteger – Quantity
$saleAmountfloat – Sale amount
$salePricefloat – Sale price
$scenariostring – The scenario that this model is in.
$shippingCategorycraft\commerce\models\ShippingCategory
$shippingCategoryIdinteger – Shipping category ID
$shippingCostfloat
$sku
$snapshotmixed – Snapshot
$subtotalfloat
$taxfloat
$taxCategorycraft\commerce\models\TaxCategory
$taxCategoryIdinteger – Tax category ID
$taxIncludedfloat
$totalfloat
$validatorsArrayObject, yii\validators\Validator – All the validators declared in the model.
$weightfloat – Weight
$widthfloat – Width

$adjustments

Signature

public craft\commerce\models\OrderAdjustment[] getAdjustments ( )

$adjustmentsTotal

Type
float
Access
Read-only

View source

Signature

public float getAdjustmentsTotal ( $included = false )

$description

Type

:

Access
Read-only

View source

Signature

public void getDescription ( )

$discount

Type
float
Access
Read-only

View source

Signature

public float getDiscount ( )

$height

Signature

public float $height = 0

$id

Signature

public integer $id = null

$length

Signature

public float $length = 0

$note

Signature

public string $note = null

$onSale

Type
boolean
Access
Read-only

View source

Signature

public boolean getOnSale ( )

$options

Signature

public void getOptions ( )
public void setOptions ( $options )

$optionsSignature

Type

:

Access
Read-only

View source

Signature

public void getOptionsSignature ( )

$order

Signature

public craft\commerce\elements\Order, null getOrder ( )
public void setOrder ( craft\commerce\elements\Order $order )

$orderId

Type
integer

Order ID

View source

Signature

public integer $orderId = null

$price

Signature

public float $price = 0

$purchasable

Signature

public craft\commerce\base\PurchasableInterface, null getPurchasable ( )
public void setPurchasable ( craft\base\Element $purchasable )

$purchasableId

Type
integer

Purchasable ID

View source

Signature

public integer $purchasableId = null

$qty

Type
integer

Quantity

View source

Signature

public integer $qty = null

$saleAmount

Type
float

Sale amount

View source

Signature

public float $saleAmount = 0

$salePrice

Type
float

Sale price

View source

Signature

public float $salePrice = 0

$shippingCategory

Signature

public craft\commerce\models\ShippingCategory getShippingCategory ( )

$shippingCategoryId

Type
integer

Shipping category ID

View source

Signature

public integer $shippingCategoryId = null

$shippingCost

Type
float
Access
Read-only

View source

Signature

public float getShippingCost ( )

$sku

Type

:

Access
Read-only

View source

Signature

public void getSku ( )

$snapshot

Type
mixed

Snapshot

View source

Signature

public mixed $snapshot = null

$subtotal

Type
float
Access
Read-only

View source

Signature

public float getSubtotal ( )

$tax

Type
float
Access
Read-only

View source

Signature

public float getTax ( )

$taxCategory

Signature

public craft\commerce\models\TaxCategory getTaxCategory ( )

$taxCategoryId

Type
integer

Tax category ID

View source

Signature

public integer $taxCategoryId = null

$taxIncluded

Type
float
Access
Read-only

View source

Signature

public float getTaxIncluded ( )

$total

Type
float
Access
Read-only

View source

Signature

public float getTotal ( )

$weight

Signature

public float $weight = 0

$width

Signature

public float $width = 0

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__clone()
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
activeAttributes()Returns the attribute names that are subject to validation in the current scenario.
addError()Adds a new error to the specified attribute.
addErrors()Adds a list of errors.
addModelErrors()Adds errors from another model, with a given attribute name prefix.
afterValidate()This method is invoked after validation ends.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attributeHints()Returns the attribute hints.
attributeLabels()Returns the attribute labels.
attributes()Returns the list of attribute names.
beforeValidate()This method is invoked before validation starts.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
clearErrors()Removes errors for all attributes or a single attribute.
createValidators()Creates validator objects based on the validation rules specified in rules().
datetimeAttributes()Returns the names of any attributes that should hold DateTime values.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
extraFields()Returns the list of fields that can be expanded further and returned by toArray().
fields()Returns the list of fields that should be returned by default by toArray() when no specific fields are specified.
fillFromPurchasable()
formName()Returns the form name that this model class should use.
generateAttributeLabel()Generates a user friendly attribute label based on the give attribute name.
getActiveValidators()Returns the validators applicable to the current $scenario.
getAdjustments()
getAdjustmentsTotal()
getAdjustmentsTotalByType()
getAttributeHint()Returns the text hint for the specified attribute.
getAttributeLabel()Returns the text label for the specified attribute.
getAttributes()Returns attribute values.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getDescription()Returns the description from the snapshot of the purchasable
getDiscount()
getError()Returns the first error of the specified attribute.
getErrorSummary()Returns the errors for all attributes as a one-dimensional array.
getErrors()Returns the errors for all attributes or a single attribute.
getFirstError()Returns the first error of the specified attribute.
getFirstErrors()Returns the first error of every attribute in the model.
getIterator()Returns an iterator for traversing the attributes in the model.
getOnSale()
getOptions()Gets the options for the line item.
getOptionsSignature()Returns a unique hash of the line item options
getOrder()
getPurchasable()
getScenario()Returns the scenario that this model is used in.
getShippingCategory()
getShippingCost()
getSku()Returns the Sku from the snapshot of the purchasable
getSubtotal()
getTax()
getTaxCategory()
getTaxIncluded()
getTaxableSubtotal()
getTotal()Returns the Purchasable’s sale price multiplied by the quantity of the line item, plus any adjustment belonging to this lineitem.
getValidators()Returns all the validators declared in rules().
hasErrors()Returns a value indicating whether there is any validation error.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
instance()Returns static class instance, which can be used to obtain meta information.
isAttributeActive()Returns a value indicating whether the attribute is active in the current scenario.
isAttributeRequired()Returns a value indicating whether the attribute is required.
isAttributeSafe()Returns a value indicating whether the attribute is safe for massive assignments.
load()Populates the model with input data.
loadMultiple()Populates a set of models with the data from end user.
off()Detaches an existing event handler from this component.
offsetExists()Returns whether there is an element at the specified offset.
offsetGet()Returns the element at the specified offset.
offsetSet()Sets the element at the specified offset.
offsetUnset()Sets the element value at the specified offset to null.
on()Attaches an event handler to an event.
onUnsafeAttribute()This method is invoked when an unsafe attribute is being massively assigned.
populateFromPurchasable()
refreshFromPurchasable()
rules()
safeAttributes()Returns the attribute names that are safe to be massively assigned in the current scenario.
scenarios()Returns a list of scenarios and the corresponding active attributes.
setAttributes()Sets the attribute values in a massive way.
setOptions()Set the options array on the line item.
setOrder()
setPurchasable()
setScenario()Sets the scenario for the model.
toArray()Converts the model into an array.
trigger()Triggers an event.
validate()Performs the data validation.
validateMultiple()Validates multiple models.

attributes()

Returns the list of attribute names.

By default, this method returns all public non-static properties of the class. You may override this method to change the default behavior.

View source

Returns

array – List of attribute names.

Signature

public array attributes ( )

extraFields()

Returns the list of fields that can be expanded further and returned by toArray().

This method is similar to fields() except that the list of fields returned by this method are not returned by default by toArray(). Only when field names to be expanded are explicitly specified when calling toArray(), will their values be exported.

The default implementation returns an empty array.

You may override this method to return a list of expandable fields based on some context information (e.g. the current application user).

View source

Returns

array – The list of expandable field names or field definitions. Please refer to fields() on the format of the return value.

Signature

public array extraFields ( )

fillFromPurchasable()

DEPRECATED

Deprecated in 2.0 Use populateFromPurchasable() instead.

View source

Arguments

Signature

public void fillFromPurchasable ( craft\commerce\base\PurchasableInterface $purchasable )

getAdjustments()

Signature

public craft\commerce\models\OrderAdjustment[] getAdjustments ( )

getAdjustmentsTotal()

View source

Arguments

Returns

float

Signature

public float getAdjustmentsTotal ( $included = false )

getAdjustmentsTotalByType()

View source

Arguments

Returns

float, integer

Signature

public float, integer getAdjustmentsTotalByType ( $type, $included = false )

getDescription()

Returns the description from the snapshot of the purchasable

View source

Signature

public void getDescription ( )

getDiscount()

DEPRECATED

Deprecated since 2.0

View source

Returns

float

Signature

public float getDiscount ( )

getOnSale()

Signature

public boolean getOnSale ( )

getOptions()

Gets the options for the line item.

View source

Signature

public void getOptions ( )

getOptionsSignature()

Returns a unique hash of the line item options

View source

Signature

public void getOptionsSignature ( )

getOrder()

Signature

public craft\commerce\elements\Order, null getOrder ( )

getPurchasable()

Signature

public craft\commerce\base\PurchasableInterface, null getPurchasable ( )

getShippingCategory()

Signature

public craft\commerce\models\ShippingCategory getShippingCategory ( )

getShippingCost()

DEPRECATED

Deprecated since 2.0

View source

Returns

float

Signature

public float getShippingCost ( )

getSku()

Returns the Sku from the snapshot of the purchasable

View source

Signature

public void getSku ( )

getSubtotal()

Signature

public float getSubtotal ( )

getTax()

DEPRECATED

Deprecated since 2.0

View source

Returns

float

Signature

public float getTax ( )

getTaxCategory()

Signature

public craft\commerce\models\TaxCategory getTaxCategory ( )

getTaxIncluded()

DEPRECATED

Deprecated since 2.0

View source

Returns

float

Signature

public float getTaxIncluded ( )

getTaxableSubtotal()

View source

Arguments

  • $taxable

Returns

float, integer

Signature

public float, integer getTaxableSubtotal ( $taxable )

getTotal()

Returns the Purchasable’s sale price multiplied by the quantity of the line item, plus any adjustment belonging to this lineitem.

View source

Returns

float

Signature

public float getTotal ( )

populateFromPurchasable()

Signature

public void populateFromPurchasable ( craft\commerce\base\PurchasableInterface $purchasable )

refreshFromPurchasable()

View source

Returns

boolean – False when no related purchasable exists

Signature

public boolean refreshFromPurchasable ( )

rules()

Signature

public array rules ( )

setOptions()

Set the options array on the line item.

View source

Arguments

Signature

public void setOptions ( $options )

setOrder()

Signature

public void setOrder ( craft\commerce\elements\Order $order )

setPurchasable()

View source

Arguments

  • $purchasable (\craft\commerce\base\Element)

Signature

public void setPurchasable ( craft\base\Element $purchasable )

Protected Methods

MethodDescription
extractFieldsFor()Extract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "id".
extractRootFields()Extracts the root field names from nested fields.
resolveFields()Determines which fields can be returned by toArray().

Constants

ConstantDescription
SCENARIO_DEFAULTThe name of the default scenario.