A purchasable is a custom Element Type that can be sold through the cart.
is an element type)
implements the Purchasable interface found at
can inherit from the base Purchasable abstract class located at:
To implement the Purchasable interface, these core methods need to exist on the element type’s model.
This is the description of the purchasable. Would usually be the title, or name of the product.
Whether the purchasable can be subject to discounts or sales.
The price of the purchasable in the primary currency.
The element ID of the purchasable.
The stock keeping unit number of the purchasable. Must be unique based on the
An array of data that is serialized as JSON on the line item when the purchasable is added to the cart. This is useful when the purchasable is later deleted, but the cart can still have all relevant data about the purchasable stored within it.
The tax category ID of the purchasable. Defaults to the default tax category ID if not supplied.
The shipping category ID of the purchasable. Defaults to the default shipping category ID if not supplied.
Stops the shipping engine from adding shipping costs to a line that contains this purchasable.
Gives the purchasable the chance to change the saleAmount and price of the line item when it is added to the cart, or the cart recalculates.
Gives the purchasable the chance to validate the line item model.
Add errors to the lineItem like so:
$lineItem->addError(['options'=>'not valid options submitted for this purchasable']);
Purchasables are able to be discounted by discount promotions as long as the discount conditions do not include conditions around product type or product. Your discount can not currently target a specific purchasable or purchasables, only the order as a whole.
Since sales apply to products before they are added to the cart, purchasables are not currently integrated with the sales promotion engine. We hope to improve this restriction in a future version of Craft Commerce.