PHP Trait Stevebauman\Inventory\Traits\InventoryVariantTrait

显示文件 Open project: stevebauman/inventory

Public Methods

Method Description
createVariant ( string $name = '', string $description = '', integer | string $categoryId = null, integer | string $metricId = null ) : boolean | Model Creates a new variant instance, saves it, and returns the resulting variant.
getParent ( ) : Model Returns the parent item record for the current variant.
getTotalVariantStock ( boolean $recursive = true ) : integer | float Returns the total sum of the item variants stock. This method is recursive by default, and includes variants of variants total stock.
getVariants ( boolean $recursive = false ) : Illuminate\Database\Eloquent\Collection Returns all variants of the current item.
hasVariants ( ) : boolean Returns true / false if the current item has variants.
isVariant ( ) : boolean Returns true / false if the current item is a variant of another item.
makeVariantOf ( Model $item ) Makes the current item a variant of the specified item.
newVariant ( string $name = '' ) : Model Returns a new Inventory model instance with it's parent ID, category ID, and metric ID set to the current item's for the creation of a variant.
parent ( ) : BelongsTo The belongsTo parent relationship.
variants ( ) : Illuminate\Database\Eloquent\Relations\HasMany The hasMany variants relationship.
variantsRecursive ( ) : Illuminate\Database\Eloquent\Relations\HasMany The hasMany recursive variants relationship.

Protected Methods

Method Description
processMakeVariant ( integer | string $itemId ) Processes making the current item a variant of the specified item ID.

Method Details

createVariant() public method

Creates a new variant instance, saves it, and returns the resulting variant.
public createVariant ( string $name = '', string $description = '', integer | string $categoryId = null, integer | string $metricId = null ) : boolean | Model
$name string
$description string
$categoryId integer | string
$metricId integer | string
return boolean | Illuminate\Database\Eloquent\Model

getParent() public method

Returns the parent item record for the current variant.
public getParent ( ) : Model
return Illuminate\Database\Eloquent\Model

getTotalVariantStock() public method

Returns the total sum of the item variants stock. This method is recursive by default, and includes variants of variants total stock.
public getTotalVariantStock ( boolean $recursive = true ) : integer | float
$recursive boolean
return integer | float

getVariants() public method

This method does not retrieve variants recursively.
public getVariants ( boolean $recursive = false ) : Illuminate\Database\Eloquent\Collection
$recursive boolean
return Illuminate\Database\Eloquent\Collection

hasVariants() public method

Returns true / false if the current item has variants.
public hasVariants ( ) : boolean
return boolean

isVariant() public method

Returns true / false if the current item is a variant of another item.
public isVariant ( ) : boolean
return boolean

makeVariantOf() public method

Makes the current item a variant of the specified item.
public makeVariantOf ( Model $item )
$item Illuminate\Database\Eloquent\Model

newVariant() public method

Returns a new Inventory model instance with it's parent ID, category ID, and metric ID set to the current item's for the creation of a variant.
public newVariant ( string $name = '' ) : Model
$name string
return Illuminate\Database\Eloquent\Model

parent() public method

The belongsTo parent relationship.
public parent ( ) : BelongsTo
return Illuminate\Database\Eloquent\Relations\BelongsTo

processMakeVariant() protected method

Processes making the current item a variant of the specified item ID.
protected processMakeVariant ( integer | string $itemId )
$itemId integer | string

variants() public method

The hasMany variants relationship.
public variants ( ) : Illuminate\Database\Eloquent\Relations\HasMany
return Illuminate\Database\Eloquent\Relations\HasMany

variantsRecursive() public method

The hasMany recursive variants relationship.
public variantsRecursive ( ) : Illuminate\Database\Eloquent\Relations\HasMany
return Illuminate\Database\Eloquent\Relations\HasMany