class Cart extends BaseModel (View source)

Traits

HasFactory
LogsActivity
Macroable

Properties

array $cachableProperties

Array of cachable class properties.

$subTotal

The cart sub total.

$subTotalDiscounted

The cart sub total.

$shippingSubTotal

The shipping sub total for the cart.

$shippingTotal

The shipping total for the cart.

$taxTotal

The cart tax total.

$discountTotal

The discount total.

null|DiscountBreakdown> $discountBreakdown

All the discount breakdowns for the cart.

$shippingBreakdown

All the shipping breakdowns for the cart.

$total

The cart total.

null|TaxBreakdown> $taxBreakdown

All the tax breakdowns for the cart.

null|Promotion> $promotions

The cart-level promotions.

null|Discount> $discounts

The cart-level discounts.

null|FreeItem> $freeItems

Qualifying promotional free items.

protected array $guarded

Define which attributes should be protected from mass assignment.

protected array $casts

The attributes that should be cast.

int $id
?int $user_id
?int $customer_id
?int $merged_id
int $currency_id
int $channel_id
?int $order_id
?string $coupon_code
Carbon $completed_at
Carbon $created_at
Carbon $updated_at

Methods

Model
newInstance(array $attributes = [], bool $exists = false)

Get new instance of the registered model.

mixed
__call(string $method, array $parameters)

Handle dynamic and static method calls into the model.

Model
swap(string $newModelClass)

Swap the model implementation.

string
getMorphClass()

Get the class name of the base model.

bool
forwardCallsWhen(string $method, Model $model)

Forward a method call to the model only when calling a method on the model.

static void
registerModelEvent(string $event, QueuedClosure|Closure|string $callback)

Register a model event with the dispatcher.

mixed
fireModelEvent(string $event, bool $halt = true)

Fire the given event for the model.

static void
flushEventListeners()

Remove all the event listeners for the model.

__construct(array $attributes = [])

Create a new instance of the Model.

LogOptions
getActivitylogOptions()

Get the log options for the activity log.

static mixed
__callStatic(string $method, array $parameters)

Handle dynamic static method calls into the model.

static 
bootCachesProperties()

No description

refresh()

No description

string
cachePropertiesPrefix()

Returns a unique key for the cache.

void
cacheProperties()

Cache properties for reuse in same request.

void
restoreProperties()

Restores properties from the same request.

static CartFactory
newFactory()

Return a new factory instance for the model.

HasMany
lines()

Return the cart lines relationship.

BelongsTo
currency()

Return the currency relationship.

BelongsTo
user()

Return the user relationship.

BelongsTo
customer()

Return the customer relationship.

scopeUnmerged($query)

No description

HasMany
addresses()

Return the addresses relationship.

HasOne
shippingAddress()

Return the shipping address relationship.

HasOne
billingAddress()

Return the billing address relationship.

HasMany
orders()

Return the order relationship.

Builder
scopeActive(Builder $query)

Apply scope to get active cart.

HasOne
draftOrder(int $draftOrderId = null)

Return the draft order relationship.

HasOne
completedOrder(int $completedOrderId = null)

Return the completed order relationship.

HasMany
completedOrders()

Return the carts completed order.

bool
hasCompletedOrders()

Return whether the cart has any completed order.

calculate()

Calculate the cart totals and cache the result.

add(Purchasable $purchasable, int $quantity = 1, array $meta = [], bool $refresh = true)

Add or update a purchasable item to the cart

bool
addLines(iterable $lines)

Add cart lines.

remove(int $cartLineId, bool $refresh = true)

Remove a cart line

updateLine(int $cartLineId, int $quantity, array $meta = null, bool $refresh = true)

Update cart line

updateLines(Collection $lines)

Update cart lines.

clear()

Deletes all cart lines.

associate(User $user, string $policy = 'merge', bool $refresh = true)

Associate a user to the cart

setCustomer(Customer $customer)

Associate a customer to the cart

addAddress(Addressable $address, string $type, bool $refresh = true)

Add an address to the Cart.

setShippingAddress(Addressable $address)

Set the shipping address.

setBillingAddress(Addressable $address)

Set the billing address.

setShippingOption(ShippingOption $option, $refresh = true)

Set the shipping option to the shipping address.

ShippingOption|null
getShippingOption()

Get the shipping option for the cart

bool
isShippable()

Returns whether the cart has shippable items.

createOrder(bool $allowMultipleOrders = false, int $orderIdToUpdate = null)

Create an order from the Cart.

bool
canCreateOrder()

Returns whether a cart has enough info to create an order.

string
fingerprint()

Get a unique fingerprint for the cart to identify if the contents have changed.

bool
checkFingerprint(string $fingerprint)

Check whether a given fingerprint matches the one being generated for the cart.

Details

Model newInstance(array $attributes = [], bool $exists = false)

Get new instance of the registered model.

Parameters

array $attributes
bool $exists

Return Value

Model

mixed __call(string $method, array $parameters)

Handle dynamic and static method calls into the model.

Parameters

string $method
array $parameters

Return Value

mixed

Model swap(string $newModelClass)

Swap the model implementation.

Parameters

string $newModelClass

Return Value

Model

string getMorphClass()

Get the class name of the base model.

Return Value

string

protected bool forwardCallsWhen(string $method, Model $model)

Forward a method call to the model only when calling a method on the model.

Parameters

string $method
Model $model

Return Value

bool

static protected void registerModelEvent(string $event, QueuedClosure|Closure|string $callback)

Register a model event with the dispatcher.

Parameters

string $event
QueuedClosure|Closure|string $callback

Return Value

void

protected mixed fireModelEvent(string $event, bool $halt = true)

Fire the given event for the model.

Parameters

string $event
bool $halt

Return Value

mixed

static void flushEventListeners()

Remove all the event listeners for the model.

Return Value

void

__construct(array $attributes = [])

Create a new instance of the Model.

Parameters

array $attributes

LogOptions getActivitylogOptions()

Get the log options for the activity log.

Return Value

LogOptions

static mixed __callStatic(string $method, array $parameters)

Handle dynamic static method calls into the model.

Parameters

string $method
array $parameters

Return Value

mixed

static bootCachesProperties()

No description

refresh()

No description

protected string cachePropertiesPrefix()

Returns a unique key for the cache.

Return Value

string

void cacheProperties()

Cache properties for reuse in same request.

Return Value

void

void restoreProperties()

Restores properties from the same request.

Return Value

void

static protected CartFactory newFactory()

Return a new factory instance for the model.

Return Value

CartFactory

HasMany lines()

Return the cart lines relationship.

Return Value

HasMany

BelongsTo currency()

Return the currency relationship.

Return Value

BelongsTo

BelongsTo user()

Return the user relationship.

Return Value

BelongsTo

BelongsTo customer()

Return the customer relationship.

Return Value

BelongsTo

scopeUnmerged($query)

No description

Parameters

$query

HasMany addresses()

Return the addresses relationship.

Return Value

HasMany

HasOne shippingAddress()

Return the shipping address relationship.

Return Value

HasOne

HasOne billingAddress()

Return the billing address relationship.

Return Value

HasOne

HasMany orders()

Return the order relationship.

Return Value

HasMany

Builder scopeActive(Builder $query)

Apply scope to get active cart.

Parameters

Builder $query

Return Value

Builder

HasOne draftOrder(int $draftOrderId = null)

Return the draft order relationship.

Parameters

int $draftOrderId

Return Value

HasOne

HasOne completedOrder(int $completedOrderId = null)

Return the completed order relationship.

Parameters

int $completedOrderId

Return Value

HasOne

HasMany completedOrders()

Return the carts completed order.

Return Value

HasMany

bool hasCompletedOrders()

Return whether the cart has any completed order.

Return Value

bool

Cart calculate()

Calculate the cart totals and cache the result.

Return Value

Cart

Cart add(Purchasable $purchasable, int $quantity = 1, array $meta = [], bool $refresh = true)

Add or update a purchasable item to the cart

Parameters

Purchasable $purchasable
int $quantity
array $meta
bool $refresh

Return Value

Cart

bool addLines(iterable $lines)

Add cart lines.

Parameters

iterable $lines

Return Value

bool

Cart remove(int $cartLineId, bool $refresh = true)

Remove a cart line

Parameters

int $cartLineId
bool $refresh

Return Value

Cart

Cart updateLine(int $cartLineId, int $quantity, array $meta = null, bool $refresh = true)

Update cart line

Parameters

int $cartLineId
int $quantity
array $meta
bool $refresh

Return Value

Cart

Cart updateLines(Collection $lines)

Update cart lines.

Parameters

Collection $lines

Return Value

Cart

clear()

Deletes all cart lines.

Cart associate(User $user, string $policy = 'merge', bool $refresh = true)

Associate a user to the cart

Parameters

User $user
string $policy
bool $refresh

Return Value

Cart

Cart setCustomer(Customer $customer)

Associate a customer to the cart

Parameters

Customer $customer

Return Value

Cart

Cart addAddress(Addressable $address, string $type, bool $refresh = true)

Add an address to the Cart.

Parameters

Addressable $address
string $type
bool $refresh

Return Value

Cart

Cart setShippingAddress(Addressable $address)

Set the shipping address.

Parameters

Addressable $address

Return Value

Cart

Cart setBillingAddress(Addressable $address)

Set the billing address.

Parameters

Addressable $address

Return Value

Cart

Cart setShippingOption(ShippingOption $option, $refresh = true)

Set the shipping option to the shipping address.

Parameters

ShippingOption $option
$refresh

Return Value

Cart

ShippingOption|null getShippingOption()

Get the shipping option for the cart

Return Value

ShippingOption|null

bool isShippable()

Returns whether the cart has shippable items.

Return Value

bool

Order createOrder(bool $allowMultipleOrders = false, int $orderIdToUpdate = null)

Create an order from the Cart.

Parameters

bool $allowMultipleOrders
int $orderIdToUpdate

Return Value

Order

bool canCreateOrder()

Returns whether a cart has enough info to create an order.

Return Value

bool

string fingerprint()

Get a unique fingerprint for the cart to identify if the contents have changed.

Return Value

string

bool checkFingerprint(string $fingerprint)

Check whether a given fingerprint matches the one being generated for the cart.

Parameters

string $fingerprint

Return Value

bool

Exceptions

FingerprintMismatchException