django_program.registration.services.cart¶
Cart management service for conference registration.
Handles cart lifecycle, item management, voucher application, and pricing summary computation. All functions are stateless and operate on Cart model instances directly.
Functions
|
Add an add-on to the cart or increase its quantity. |
|
Add a ticket to the cart or increase its quantity. |
|
Apply a voucher code to the cart. |
|
Return the user's open cart, creating one if none exists. |
|
Compute a full pricing summary of the cart. |
|
Compute pricing summary using a pre-fetched cart-item snapshot. |
|
Remove an item from the cart, cascading add-on removals if needed. |
|
Update the quantity of a cart item. |
Classes
Full pricing summary of a cart including voucher discounts. |
|
Pricing breakdown for a single cart item. |
- class django_program.registration.services.cart.LineItemSummary[source]¶
Bases:
objectPricing breakdown for a single cart item.
- Parameters:
- class django_program.registration.services.cart.CartSummary[source]¶
Bases:
objectFull pricing summary of a cart including voucher discounts.
- Parameters:
items (
list[LineItemSummary])subtotal (
Decimal)discount (
Decimal)total (
Decimal)
- items: list[LineItemSummary]¶
- django_program.registration.services.cart.get_or_create_cart(user, conference)[source]¶
Return the user’s open cart, creating one if none exists.
Expires any stale open carts for this user and conference before looking up or creating a fresh cart.
- django_program.registration.services.cart.add_ticket(cart, ticket_type, qty=1)[source]¶
Add a ticket to the cart or increase its quantity.
Validates availability, stock limits, per-user limits, and voucher requirements before modifying the cart.
- Parameters:
cart (
Cart) – The open cart to add the ticket to.ticket_type (
TicketType) – The ticket type to add.qty (
int) – Number of tickets to add (must be >= 1).
- Return type:
- Returns:
The created or updated CartItem.
- Raises:
ValidationError – If the ticket cannot be added due to business rule violations (unavailable, out of stock, limit exceeded, or voucher required).
- django_program.registration.services.cart.add_addon(cart, addon, qty=1)[source]¶
Add an add-on to the cart or increase its quantity.
Validates availability, stock, and ticket-type prerequisites before modifying the cart.
- Parameters:
- Return type:
- Returns:
The created or updated CartItem.
- Raises:
ValidationError – If the add-on cannot be added due to business rule violations (inactive, out of window, prerequisite ticket missing, or out of stock).
- django_program.registration.services.cart.remove_item(cart, item_id)[source]¶
Remove an item from the cart, cascading add-on removals if needed.
When removing a ticket type, any add-ons that require that ticket type (and no other qualifying ticket type remains in the cart) are also removed.
- django_program.registration.services.cart.update_quantity(cart, item_id, qty)[source]¶
Update the quantity of a cart item.
If the new quantity is zero or negative the item is removed instead. Re-validates stock and per-user limits for the new quantity.
- Parameters:
- Return type:
- Returns:
The updated CartItem, or
Noneif the item was removed.- Raises:
ValidationError – If the new quantity violates stock or per-user limits, or if the item does not belong to this cart.
- django_program.registration.services.cart.apply_voucher(cart, code)[source]¶
Apply a voucher code to the cart.
- Parameters:
- Return type:
- Returns:
The validated Voucher instance now attached to the cart.
- Raises:
ValidationError – If the voucher code is not found, not valid, or does not belong to this cart’s conference.
- django_program.registration.services.cart.get_summary(cart)[source]¶
Compute a full pricing summary of the cart.
Iterates all cart items, applies any voucher discounts, and returns a structured summary with per-item and aggregate totals.
- Parameters:
cart (
Cart) – The cart to summarise.- Return type:
- Returns:
A CartSummary with line items, subtotal, discount, and total.