Skip to content

VariantCollection ​

Type
Class
Namespace
craft\commerce\elements
Inherits
craft\commerce\elements\VariantCollection » craft\elements\ElementCollection » Illuminate\Support\Collection
Since
5.0.0

VariantCollection represents a collection of Variant elements.

View source

Public Methods ​

MethodDescription
cheapest()Returns the cheapest variant in the collection.
collapse()
contains()Returns whether an element exists within the collection.
countBy()
diff()Returns a new collection with the elements that are not present in the given array.
except()Returns a new collection with all elements except those with the specified keys.
find()Finds an element in the collection.
flatten()
flip()
fresh()Reloads fresh element instances from the database for all the elements.
ids()Returns a collection of the elements’ IDs.
intersect()Returns a new collection with all the elements present in this collection and the provided array.
keys()
make()Creates a VariantCollection from an array of Variant attributes.
map()Runs a map over each of the items.
mapWithKeys()Runs an associative map over each of the items.
merge()Merge the collection with the given elements.
one()
only()Returns a new collection with only the elements with the specified keys.
pad()
pluck()
render()Renders the elements using their partial templates.
unique()Return only unique items from the collection.
with()Eager-loads related elements for the collected elements.
zip()

cheapest() ​

Returns the cheapest variant in the collection.

View source

Returns ​

craft\commerce\elements\Variant, null – The cheapest variant in the collection, or null if there aren't any

make() ​

Creates a VariantCollection from an array of Variant attributes.

View source

Arguments ​

Returns ​

static