PurchasableInterface

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

Interface Purchasable

View source

Public Methods

MethodDescription
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.
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

Arguments

Returns

void

Signature

public abstract void afterOrderComplete ( craft\commerce\elements\Order $order, craft\commerce\models\LineItem $lineItem )

getDescription()

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

View source

Returns

string

Signature

public abstract string getDescription ( )

getId()

Returns the element’s ID.

View source

Returns

integer, null

Signature

public abstract integer, null getId ( )

getIsAvailable()

Returns whether the purchasable is currently available for purchase.

View source

Returns

boolean

Signature

public abstract boolean getIsAvailable ( )

getIsPromotable()

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

View source

Returns

boolean

Signature

public abstract boolean getIsPromotable ( )

getLineItemRules()

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

View source

Arguments

Returns

array

Signature

public abstract array getLineItemRules ( craft\commerce\models\LineItem $lineItem )

getPrice()

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

View source

Returns

float – Decimal(14,4)

Signature

public abstract float getPrice ( )

getPromotionRelationSource()

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

View source

Returns

mixed

Signature

public abstract mixed getPromotionRelationSource ( )

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

Returns

float – Decimal(14,4)

Signature

public abstract float getSalePrice ( )

getShippingCategoryId()

Returns the purchasable's shipping category ID.

View source

Returns

integer

Signature

public abstract integer getShippingCategoryId ( )

getSku()

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

View source

Returns

string

Signature

public abstract string getSku ( )

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

Returns

array

Signature

public abstract array getSnapshot ( )

getTaxCategoryId()

Returns the purchasable's tax category ID.

View source

Returns

integer

Signature

public abstract integer getTaxCategoryId ( )

hasFreeShipping()

Returns whether this purchasable has free shipping.

View source

Returns

boolean

Signature

public abstract boolean hasFreeShipping ( )

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

Arguments

Signature

public abstract void populateLineItem ( craft\commerce\models\LineItem $lineItem )