PurchasableInterface

Type
Interface
Namespace
craft\commerce\base
Implemented by
craft\commerce\base\Purchasable, craft\commerce\elements\Donation, craft\commerce\elements\Variant
Since
2.0

Interface Purchasable

View source (opens new window)

# Public Methods

Method Description
afterOrderComplete() Runs any logic needed for this purchasable after it was on an order that was just completed (not when an order was paid, although paying an order will complete it).
getDescription() Returns your element's title or any additional descriptive information.
getId() Returns the element’s ID.
getIsAvailable() Returns whether the purchasable is currently available for purchase.
getIsPromotable() Returns whether this purchasable can be subject to discounts or sales.
getIsShippable() Returns whether this purchasable can be shipped and whether it is counted in shipping calculations.
getIsTaxable() Returns whether this purchasable is exempt from taxes.
getLineItemRules() Returns any validation rules this purchasable required the line item to have.
getPrice() Returns the base price the item will be added to the line item with.
getPromotionRelationSource() Returns the source param used for knowing if a promotion category is related to this purchasable.
getSalePrice() Returns the base price the item will be added to the line item with.
getShippingCategoryId() Returns the purchasable's shipping category ID.
getSku() Returns a unique code. Unique as per the commerce_purchasables table.
getSnapshot() Returns an array of data that is serializable to json for storing a line item at time of adding to the cart or order.
getTaxCategoryId() Returns the purchasable's tax category ID.
hasFreeShipping() Returns whether this purchasable has free shipping.
populateLineItem() Populates the line item when this purchasable is found on it. Called when Purchasable is added to the cart and when the cart recalculates.

# afterOrderComplete()

Runs any logic needed for this purchasable after it was on an order that was just completed (not when an order was paid, although paying an order will complete it).

This is called for each line item the purchasable was contained within.

View source (opens new window)

Arguments

Returns

void

# getDescription()

Returns your element's title or any additional descriptive information.

View source (opens new window)

Returns

string (opens new window)

# getId()

Returns the element’s ID.

View source (opens new window)

Returns

integer (opens new window), null (opens new window)

# getIsAvailable()

Returns whether the purchasable is currently available for purchase.

View source (opens new window)

Returns

boolean (opens new window)

# getIsPromotable()

Returns whether this purchasable can be subject to discounts or sales.

View source (opens new window)

Returns

boolean (opens new window)

# getIsShippable()

Returns whether this purchasable can be shipped and whether it is counted in shipping calculations.

View source (opens new window)

Returns

boolean (opens new window)

# getIsTaxable()

Returns whether this purchasable is exempt from taxes.

View source (opens new window)

Returns

boolean (opens new window)

# getLineItemRules()

Returns any validation rules this purchasable required the line item to have.

View source (opens new window)

Arguments

Returns

array (opens new window)

# getPrice()

Returns the base price the item will be added to the line item with.

View source (opens new window)

Returns

float (opens new window) – Decimal(14,4)

# getPromotionRelationSource()

Returns the source param used for knowing if a promotion category is related to this purchasable.

View source (opens new window)

Returns

mixed

# getSalePrice()

Returns the base price the item will be added to the line item with.

It provides opportunity to populate the salePrice if sales have not already been applied.

View source (opens new window)

Returns

float (opens new window) – Decimal(14,4)

# getShippingCategoryId()

Returns the purchasable's shipping category ID.

View source (opens new window)

Returns

integer (opens new window)

# getSku()

Returns a unique code. Unique as per the commerce_purchasables table.

View source (opens new window)

Returns

string (opens new window)

# getSnapshot()

Returns an array of data that is serializable to json for storing a line item at time of adding to the cart or order.

View source (opens new window)

Returns

array (opens new window)

# getTaxCategoryId()

Returns the purchasable's tax category ID.

View source (opens new window)

Returns

integer (opens new window)

# hasFreeShipping()

Returns whether this purchasable has free shipping.

View source (opens new window)

Returns

boolean (opens new window)

# populateLineItem()

Populates the line item when this purchasable is found on it. Called when Purchasable is added to the cart and when the cart recalculates.

This is your chance to modify the weight, height, width, length, price and saleAmount. This is called before any LineItems::EVENT_POPULATE_LINE_ITEM event listeners.

View source (opens new window)

Arguments