A purchasable is a custom Element Type that can be sold through the cart.
Is a custom Element Type (See Craft docs on Element Types)
Its element type’s model inherits from the Base Purchasable Abstract Class located at:
Its element type’s model meets the
Purchasableinterface. The Interface class is found in
- Persists itself as an Element with the
craft()->commerce_purchasables->saveElement()method anywhere you would usually use
To meet 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.
populateLineItem(Commerce_LineItemModel $lineItem) #
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.
validateLineItem(Commerce_LineItemModel $lineItem) #
Gived 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']);
Promotions Caveats #
Discount Promotions #
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.
Sale Promotions #
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.