---
title: Services
date: 2026-06-13T16:11:00+01:00
author: John Henry Donovan
canonical_url: "https://johnhenry.ie/plugins/container-deposits/docs/api/services"
section: Plugins
---
esc

↑↓ to navigate↵ to selectesc to close

Menu On this page 

- [Return to top](#)

Documentation

Documentation

# Services

## DepositTypeService

`johnhenry\containerdeposits\services\DepositTypeService` - CRUD for deposit types.

```php
$service = ContainerDeposits::getInstance()->depositTypes;
```

### `getAllDepositTypes(): DepositType[]`

Returns every deposit type ordered by `sortOrder` then `name`. Results are cached for the lifetime of the request.

### `getDepositTypeById(int $id): ?DepositType`

Returns the deposit type with the given ID, or `null`.

### `getDepositTypeByHandle(string $handle): ?DepositType`

Returns the deposit type with the given handle, or `null`. Useful for picking out a specific tier from front-end Twig:

```php
$small = ContainerDeposits::getInstance()->depositTypes->getDepositTypeByHandle('smallContainer');
```

### `saveDepositType(DepositType $model): bool`

Validates and saves the model. On first save, creates the matching `DepositPurchasable` element and writes its ID back onto `$model->purchasableId`. On update, the existing purchasable is re-saved so its cached price/SKU regenerate.

Returns `false` if validation fails, or if the underlying purchasable element fails to save - check `$model->getErrors()` either way. The record save and purchasable sync happen inside a single transaction, so a failure never leaves a deposit type saved without its purchasable.

### `deleteDepositTypeById(int $id): bool`

Deletes the deposit type **and** its associated `DepositPurchasable` element. Existing line items on completed orders retain their snapshot data.

## DepositCartService

`johnhenry\containerdeposits\services\DepositCartService` - cart line item reconciliation.

```php
$cart = ContainerDeposits::getInstance()->depositCart;
```

### `syncDepositLineItems(Order $order): void`

Reconciles deposit line items against the order's current non-deposit line items. The plugin calls this from `Order::EVENT_BEFORE_SAVE`; you normally do not need to call it manually.

Skips completed orders. Re-entrant calls during the same save cycle are guarded against.

On this page
