PhoenixKit.Modules.Shop.Cart (phoenix_kit v1.7.42)

Copy Markdown View Source

Shopping cart schema with support for guest and authenticated users.

Status Lifecycle

  • active - Cart is active and can be modified
  • merged - Guest cart was merged into user cart after login
  • converted - Cart was converted to an order
  • abandoned - Cart was marked as abandoned (no activity)
  • expired - Cart expired (past expires_at)

Identity

Each cart has either user_id (for authenticated users) or session_id (for guests). Guest carts have an expires_at timestamp (30 days by default). When a guest logs in, their cart is either converted to a user cart or merged with an existing user cart.

Summary

Functions

Returns true if cart is active.

Changeset for cart creation and updates.

Returns true if cart can be converted to order.

Returns true if cart is empty.

Returns true if cart has expired.

Returns true if cart is a guest cart (no user_id).

Changeset for setting payment option.

Changeset for setting shipping.

Changeset for status transitions.

Returns list of valid status values.

Changeset for updating cart totals.

Functions

active?(arg1)

Returns true if cart is active.

changeset(cart, attrs)

Changeset for cart creation and updates.

convertible?(arg1)

Returns true if cart can be converted to order.

empty?(arg1)

Returns true if cart is empty.

expired?(cart)

Returns true if cart has expired.

guest?(arg1)

Returns true if cart is a guest cart (no user_id).

payment_changeset(cart, attrs)

Changeset for setting payment option.

shipping_changeset(cart, attrs)

Changeset for setting shipping.

status_changeset(cart, new_status, extra_attrs \\ %{})

Changeset for status transitions.

statuses()

Returns list of valid status values.

totals_changeset(cart, attrs)

Changeset for updating cart totals.