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

↑↓ to navigate↵ to selectesc to close

Menu On this page 

- [Return to top](#)

Documentation

Documentation

# Overview

## Plugin access

```php
use johnhenry\containerdeposits\ContainerDeposits;

$plugin = ContainerDeposits::getInstance();
```

## Service components

ComponentClassPurpose`depositTypes``services\DepositTypeService`CRUD for deposit types and their underlying purchasable elements.`depositCart``services\DepositCartService`Reconciles deposit line items on order save.

Access them via the plugin instance:

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

## Elements

`elements\DepositPurchasable` extends `craft\commerce\base\Purchasable`. One element exists per deposit type and is automatically managed - you should not create or delete instances directly.

PropertySource`price``DepositType::$amount``sku``'deposit-' ~ DepositType::$handle``description``DepositType::$name``taxCategoryId``containerDeposit category``isPromotable``false``hasFreeShipping``true`

## Fields

### `fields\DepositTypeField`

A select field. Place it on any product/variant field layout. It normalises to a `DepositType` model on read and serialises to an integer ID on save.

### `fields\ContainerCountField`

A numeric field (extends `craft\fields\Number`) that captures how many deposit-bearing containers are inside a single purchasable unit. Examples: `1` for a 500 ml bottle, `6` for a six-pack, `24` for a tray of cans.

The cart service multiplies a line item's `qty` by this value when summing deposit quantities - two six-packs produce 12 deposits. Defaults to `1` when the field is absent, so existing products remain backwards-compatible.

SettingDefaultNotes`min``1`Enforced at the validation layer - negative counts are rejected.`decimals``0`Integer counts only.`defaultValue``1`Applied when the field is missing from a layout`defaultContainerCount``1`Fallback used during `normalizeValue()` when the stored value is `null` or empty.

## Twig

The plugin registers a `craft.containerDeposits` variable. See [Producer Invoices](https://johnhenry.ie/plugins/container-deposits/docs/guide/producer-invoices) for the full list and example layouts.

```twig
{# Sum of all deposit line items #}
{{ craft.containerDeposits.totalFor(cart) }}

{# Just the deposit line items #}
{% for item in craft.containerDeposits.lineItemsFor(order) %}…{% endfor %}

{# Render the Re-turn-compliant invoice block #}
{% include 'store/_partials/invoice-block' ignore missing with {
    order: order,
} only %}
```

On this page
