Skip to Content
Account
Enter the email address on your account.
Forgot Your Username?
Enter your password.
Forgot Your Password?

Or continue with

Developer

Invoicetype Form Field

3 Min Read
On This Page

InvoicetypeField is a ListField subclass that renders a dropdown of document types used when creating invoice templates. Three types are built in: invoice, receipt, and packingslip. Plugins can register additional types via the onJ2CommerceGetInvoiceTypes event.

Key Classes

ClassFilePurpose
InvoicetypeFieldadministrator/components/com_j2commerce/src/Field/InvoicetypeField.phpRenders built-in types and collects plugin types

Built-in Types

ValueLanguage KeyDisplay Label
invoiceCOM_J2COMMERCE_INVOICETEMPLATE_TYPE_INVOICEInvoice
receiptCOM_J2COMMERCE_INVOICETEMPLATE_TYPE_RECEIPTReceipt
packingslipCOM_J2COMMERCE_INVOICETEMPLATE_TYPE_PACKINGSLIPPacking Slip

Plugin Event: onJ2CommerceGetInvoiceTypes

After adding the built-in types, the field dispatches onJ2CommerceGetInvoiceTypes to all enabled j2commerce plugins. Plugins receive a types array by reference (via GenericEvent) and append their custom document types.

DetailValue
Event classJoomla\CMS\Event\GenericEvent
Event nameonJ2CommerceGetInvoiceTypes
Argumenttypes — associative array ['value' => 'LANG_KEY', ...]
Plugin groupj2commerce

Registering a Custom Invoice Type

// File: plugins/j2commerce/app_yourplugin/src/Extension/AppYourPlugin.php

declare(strict_types=1);

namespace J2Commerce\Plugin\J2Commerce\App\YourPlugin\Extension;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\Event;
use Joomla\Event\SubscriberInterface;

class AppYourPlugin extends CMSPlugin implements SubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            'onJ2CommerceGetInvoiceTypes' => 'onJ2CommerceGetInvoiceTypes',
        ];
    }

    public function onJ2CommerceGetInvoiceTypes(Event $event): void
    {
        $types = $event->getArgument('types', []);
        $types['delivery_note'] = 'PLG_J2COMMERCE_APP_YOURPLUGIN_INVOICETYPE_DELIVERY_NOTE';
        $event->setArgument('types', $types);
    }
}

The value (e.g. delivery_note) is stored in the database. The language key (e.g. PLG_J2COMMERCE_APP_YOURPLUGIN_INVOICETYPE_DELIVERY_NOTE) is translated via Text::_() when building the dropdown option.

Note: InvoicetypeField uses GenericEvent with a types argument passed by reference. Plugins must call $event->setArgument('types', $types) to return modified data — returning from the handler is silently discarded.

XML Usage

<!-- File: administrator/components/com_j2commerce/forms/invoicetemplate.xml (excerpt) -->

<form addfieldprefix="J2Commerce\Component\J2commerce\Administrator\Field">
    <fieldset name="basic">
        <field
            name="invoice_type"
            type="Invoicetype"
            label="COM_J2COMMERCE_INVOICETEMPLATE_TYPE"
            description="COM_J2COMMERCE_INVOICETEMPLATE_TYPE_DESC"
            addfieldprefix="J2Commerce\Component\J2commerce\Administrator\Field"
            class="form-select"
            default="invoice"
            required="true"
        />
    </fieldset>
</form>

XML Attributes

AttributeTypeDefaultDescription
typestring—Must be Invoicetype
addfieldprefixstring—Must be J2Commerce\Component\J2commerce\Administrator\Field
defaultstringinvoicePreselected type value
requiredboolfalseMark field as required
classstring—CSS classes on the <select> element

All standard Joomla ListField attributes also apply. The field does not support static <option> XML children — all options are generated in getOptions().

Where It Is Used

Form fileField namePurpose
forms/invoicetemplate.xmlinvoice_typeSets the document type for an invoice template record

How the Type Value Is Used

The stored invoice_type value determines which template is applied when generating a document for an order. The invoicing system queries invoice templates filtered by type and matches them against the order's payment method and status. A plugin adding a custom type should also implement the rendering logic that responds to that type value during document generation.

Still stuck? Our team can help.

Back to Top