Overview

Plugin access

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:

$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 for the full list and example layouts.

{# 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 %}