Skip to content

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 - check $model->getErrors().

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.