PHP Class Overtrue\LaravelShoppingCart\Cart

Datei anzeigen Open project: overtrue/laravel-shopping-cart

Protected Properties

Property 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.

Public Methods

Method 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.

Protected Methods

Method 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 method

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 method

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'...
return string

addRow() protected method

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'
return string

all() public method

Get all items.
public all ( ) : Collection
return Illuminate\Support\Collection

associate() public method

Associated model.
public associate ( string $model ) : Cart
$model string The name of the model
return Cart

clean() public method

Alias of destory().
public clean ( ) : boolean
return boolean

count() public method

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)
return integer

countRows() public method

Get rows count.
public countRows ( ) : integer
return integer

destroy() public method

Clean the cart.
public destroy ( ) : boolean
return boolean

generateRawId() protected method

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'
return string

get() public method

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

getCart() protected method

Get the carts content.
protected getCart ( ) : Collection
return Illuminate\Support\Collection

getModel() public method

Get current associated model.
public getModel ( ) : string
return string

getName() public method

Get current cart name.
public getName ( ) : string
return string

insertRow() protected method

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'
return Item

isEmpty() public method

Return whether the shopping cart is empty.
public isEmpty ( ) : boolean
return boolean

makeRow() protected method

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.
return Item

name() public method

Set the current cart name.
public name ( string $name ) : Cart
$name string Cart name name
return Cart

remove() public method

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

save() protected method

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

total() public method

Get the price total.
public total ( ) : float
return float

totalPrice() public method

Return total price of cart.
public totalPrice ( )

update() public method

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
return Item | boolean

updateAttribute() protected method

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
return Item

updateQty() protected method

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
return Item | boolean

updateRow() protected method

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
return Item

Property Details

$event protected_oe property

Event dispatcher.
protected Dispatcher,Illuminate\Contracts\Events $event
return Illuminate\Contracts\Events\Dispatcher

$model protected_oe property

Associated model name.
protected string $model
return string

$name protected_oe property

Current cart name.
protected string $name
return string

$session protected_oe property

Session manager.
protected SessionManager,Illuminate\Session $session
return Illuminate\Session\SessionManager