PHP Class Overtrue\LaravelShoppingCart\Cart

Afficher le fichier Open project: overtrue/laravel-shopping-cart

Protected Properties

Свойство Type Description
$event Illuminate\Contracts\Events\Dispatcher Event dispatcher.
$model string Associated model name.
$name string Current cart name.
$session Illuminate\Session\SessionManager Session manager.

Méthodes publiques

Méthode Description
__construct ( Illuminate\Session\SessionManager $session, Illuminate\Contracts\Events\Dispatcher $event ) Constructor.
add ( integer | string $id, string $name = null, integer $qty = null, float $price = null, array $attributes = [] ) : string Add a row to the cart.
all ( ) : Collection Get all items.
associate ( string $model ) : Cart Associated model.
clean ( ) : boolean Alias of destory().
count ( boolean $totalItems = true ) : integer Get the number of items in the cart.
countRows ( ) : integer Get rows count.
destroy ( ) : boolean Clean the cart.
get ( string $rawId ) : Item Get a row of the cart by its ID.
getModel ( ) : string Get current associated model.
getName ( ) : string Get current cart name.
isEmpty ( ) : boolean Return whether the shopping cart is empty.
name ( string $name ) : Cart Set the current cart name.
remove ( string $rawId ) : boolean Remove a row from the cart.
search ( array $search ) : array Search if the cart has a item.
total ( ) : float Get the price total.
totalPrice ( ) Return total price of cart.
update ( string $rawId, integer | array $attribute ) : Item | boolean Update the quantity of one row of the cart.

Méthodes protégées

Méthode Description
addRow ( string $id, string $name, integer $qty, float $price, array $attributes = [] ) : string Add row to the cart.
generateRawId ( string $id, array $attributes ) : string Generate a unique id for the new row.
getCart ( ) : Collection Get the carts content.
insertRow ( string $rawId, string $id, string $name, integer $qty, float $price, array $attributes = [] ) : Item Create a new row Object.
makeRow ( string $rawId, mixed $id, string $name, integer $qty, float $price, array $attributes = [] ) : Item Make a row item.
save ( Collection | null $cart ) : Collection Sync the cart to session.
updateAttribute ( string $rawId, array $attributes ) : Item Update an attribute of the row.
updateQty ( string $rawId, integer $qty ) : Item | boolean Update the quantity of a row.
updateRow ( string $rawId, array $attributes ) : Item Update a row if the rawId already exists.

Method Details

__construct() public méthode

Constructor.
public __construct ( Illuminate\Session\SessionManager $session, Illuminate\Contracts\Events\Dispatcher $event )
$session Illuminate\Session\SessionManager Session class name
$event Illuminate\Contracts\Events\Dispatcher Event class name

add() public méthode

Add a row to the cart.
public add ( integer | string $id, string $name = null, integer $qty = null, float $price = null, array $attributes = [] ) : string
$id integer | string Unique ID of the item
$name string Name of the item
$qty integer Item qty to add to the cart
$price float Price of one item
$attributes array Array of additional attributes, such as 'size' or 'color'...
Résultat string

addRow() protected méthode

Add row to the cart.
protected addRow ( string $id, string $name, integer $qty, float $price, array $attributes = [] ) : string
$id string Unique ID of the item
$name string Name of the item
$qty integer Item qty to add to the cart
$price float Price of one item
$attributes array Array of additional options, such as 'size' or 'color'
Résultat string

all() public méthode

Get all items.
public all ( ) : Collection
Résultat Illuminate\Support\Collection

associate() public méthode

Associated model.
public associate ( string $model ) : Cart
$model string The name of the model
Résultat Cart

clean() public méthode

Alias of destory().
public clean ( ) : boolean
Résultat boolean

count() public méthode

Get the number of items in the cart.
public count ( boolean $totalItems = true ) : integer
$totalItems boolean Get all the items (when false, will return the number of rows)
Résultat integer

countRows() public méthode

Get rows count.
public countRows ( ) : integer
Résultat integer

destroy() public méthode

Clean the cart.
public destroy ( ) : boolean
Résultat boolean

generateRawId() protected méthode

Generate a unique id for the new row.
protected generateRawId ( string $id, array $attributes ) : string
$id string Unique ID of the item
$attributes array Array of additional options, such as 'size' or 'color'
Résultat string

get() public méthode

Get a row of the cart by its ID.
public get ( string $rawId ) : Item
$rawId string The ID of the row to fetch
Résultat Item

getCart() protected méthode

Get the carts content.
protected getCart ( ) : Collection
Résultat Illuminate\Support\Collection

getModel() public méthode

Get current associated model.
public getModel ( ) : string
Résultat string

getName() public méthode

Get current cart name.
public getName ( ) : string
Résultat string

insertRow() protected méthode

Create a new row Object.
protected insertRow ( string $rawId, string $id, string $name, integer $qty, float $price, array $attributes = [] ) : Item
$rawId string The ID of the new row
$id string Unique ID of the item
$name string Name of the item
$qty integer Item qty to add to the cart
$price float Price of one item
$attributes array Array of additional options, such as 'size' or 'color'
Résultat Item

isEmpty() public méthode

Return whether the shopping cart is empty.
public isEmpty ( ) : boolean
Résultat boolean

makeRow() protected méthode

Make a row item.
protected makeRow ( string $rawId, mixed $id, string $name, integer $qty, float $price, array $attributes = [] ) : Item
$rawId string Raw id.
$id mixed Item id.
$name string Item name.
$qty integer Quantity.
$price float Price.
$attributes array Other attributes.
Résultat Item

name() public méthode

Set the current cart name.
public name ( string $name ) : Cart
$name string Cart name name
Résultat Cart

remove() public méthode

Remove a row from the cart.
public remove ( string $rawId ) : boolean
$rawId string The __raw_id of the item
Résultat boolean

save() protected méthode

Sync the cart to session.
protected save ( Collection | null $cart ) : Collection
$cart Illuminate\Support\Collection | null The new cart content
Résultat Illuminate\Support\Collection

total() public méthode

Get the price total.
public total ( ) : float
Résultat float

totalPrice() public méthode

Return total price of cart.
public totalPrice ( )

update() public méthode

Update the quantity of one row of the cart.
public update ( string $rawId, integer | array $attribute ) : Item | boolean
$rawId string The __raw_id of the item you want to update
$attribute integer | array New quantity of the item|Array of attributes to update
Résultat Item | boolean

updateAttribute() protected méthode

Update an attribute of the row.
protected updateAttribute ( string $rawId, array $attributes ) : Item
$rawId string The ID of the row
$attributes array An array of attributes to update
Résultat Item

updateQty() protected méthode

Update the quantity of a row.
protected updateQty ( string $rawId, integer $qty ) : Item | boolean
$rawId string The ID of the row
$qty integer The qty to add
Résultat Item | boolean

updateRow() protected méthode

Update a row if the rawId already exists.
protected updateRow ( string $rawId, array $attributes ) : Item
$rawId string The ID of the row to update
$attributes array The quantity to add to the row
Résultat Item

Property Details

$event protected_oe property

Event dispatcher.
protected Dispatcher,Illuminate\Contracts\Events $event
Résultat Illuminate\Contracts\Events\Dispatcher

$model protected_oe property

Associated model name.
protected string $model
Résultat string

$name protected_oe property

Current cart name.
protected string $name
Résultat string

$session protected_oe property

Session manager.
protected SessionManager,Illuminate\Session $session
Résultat Illuminate\Session\SessionManager