Skip to content

API Overview

Plugin access

php
use johnhenry\containerdeposits\ContainerDeposits;

$plugin = ContainerDeposits::getInstance();

Service components

ComponentClassPurpose
depositTypesservices\DepositTypeServiceCRUD for deposit types and their underlying purchasable elements.
depositCartservices\DepositCartServiceReconciles 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
priceDepositType::$amount
sku'deposit-' ~ DepositType::$handle
descriptionDepositType::$name
taxCategoryIdcontainerDeposit category
isPromotablefalse
hasFreeShippingtrue

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
min1Enforced at the validation layer - negative counts are rejected.
decimals0Integer counts only.
defaultValue1Applied when the field is missing from a layout.
defaultContainerCount1Fallback 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.

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/re-turn-invoice-block' ignore missing with {
    order: order,
} only %}