Class

CartService

CartService()

Constructor

# new CartService()

CartService - Service for managing carts data.

View Source src/carts/CartService.js, line 7

Methods

# async addItemToCart()

Add (or upsert) a line item to a user’s pending cart. This writes cart_items via our own repository AND updates cart totals.

View Source src/carts/bak-CartService.js, line 125

# async applyCartItemsDiscount()

Create per-item discount rows (optional; depends on your schema).

View Source src/carts/bak-CartService.js, line 299

# async applyDiscount()

Apply a coupon to a cart:

  • Validate via couponCodeService
  • Create a “cart” discount row (via CartRepository upsertDiscount if you keep that)
  • Optionally create per-item discount rows
  • Update cart.total

View Source src/carts/bak-CartService.js, line 249

# calculateDiscount()

Very simple discount math; most teams move this to the coupon service. Expects coupon entities to expose getType()/getAmount() or you adapt here.

View Source src/carts/bak-CartService.js, line 325

# async clearCart()

Clear all items and reset totals.

View Source src/carts/bak-CartService.js, line 211

# async deleteCartItem()

Delete a single item and refresh totals.

View Source src/carts/bak-CartService.js, line 199

# async findOrCreatePendingCart()

Find or create a pending cart for the user.

View Source src/carts/bak-CartService.js, line 101

# async findPendingCartForUser()

Find the user’s pending cart, with items. If none, returns null.

View Source src/carts/bak-CartService.js, line 82

# async getCartWithItems()

Get a cart by id with user + items. Returns raw with relations (or you can wrap if you prefer Entities here).

View Source src/carts/bak-CartService.js, line 66

# getProductService()

Map entity_type -> service used to read that product. Throws if a service is not configured.

View Source src/carts/bak-CartService.js, line 353

# async updateTotals()

Recompute totals from the current cart_items rows. (This is a placeholder; customize your tax/discount strategy as needed.)

View Source src/carts/bak-CartService.js, line 223

# async upsertCartWithItems()

Upsert a batch of items into a user’s pending cart.

View Source src/carts/bak-CartService.js, line 157

CartService(opts)

CartService class

Constructor

# new CartService(opts)

Parameters:
Name Type Attributes Description
opts Object
repository CartRepository <optional>

repository for carts

entityClass function <optional>

entity class for carts

cartItemRepository CartItemRepository <optional>
services Object <optional>

cross-module service registry (initService() instances) { iconService, illustrationService, setService, familyService, creditsService, subscriptionService, couponCodeService, }

View Source src/carts/bak-CartService.js, line 32

Extends

  • BaseService,

Methods

# async addItemToCart()

Add (or upsert) a line item to a user’s pending cart. This writes cart_items via our own repository AND updates cart totals.

View Source src/carts/bak-CartService.js, line 125

# async applyCartItemsDiscount()

Create per-item discount rows (optional; depends on your schema).

View Source src/carts/bak-CartService.js, line 299

# async applyDiscount()

Apply a coupon to a cart:

  • Validate via couponCodeService
  • Create a “cart” discount row (via CartRepository upsertDiscount if you keep that)
  • Optionally create per-item discount rows
  • Update cart.total

View Source src/carts/bak-CartService.js, line 249

# calculateDiscount()

Very simple discount math; most teams move this to the coupon service. Expects coupon entities to expose getType()/getAmount() or you adapt here.

View Source src/carts/bak-CartService.js, line 325

# async clearCart()

Clear all items and reset totals.

View Source src/carts/bak-CartService.js, line 211

# async deleteCartItem()

Delete a single item and refresh totals.

View Source src/carts/bak-CartService.js, line 199

# async findOrCreatePendingCart()

Find or create a pending cart for the user.

View Source src/carts/bak-CartService.js, line 101

# async findPendingCartForUser()

Find the user’s pending cart, with items. If none, returns null.

View Source src/carts/bak-CartService.js, line 82

# async getCartWithItems()

Get a cart by id with user + items. Returns raw with relations (or you can wrap if you prefer Entities here).

View Source src/carts/bak-CartService.js, line 66

# getProductService()

Map entity_type -> service used to read that product. Throws if a service is not configured.

View Source src/carts/bak-CartService.js, line 353

# async updateTotals()

Recompute totals from the current cart_items rows. (This is a placeholder; customize your tax/discount strategy as needed.)

View Source src/carts/bak-CartService.js, line 223

# async upsertCartWithItems()

Upsert a batch of items into a user’s pending cart.

View Source src/carts/bak-CartService.js, line 157