Plugin

Type
Class
Namespace
craft\commerce
Inherits
craft\commerce\Plugin » craft\base\Plugin (opens new window) » yii\base\Module (opens new window) » yii\di\ServiceLocator (opens new window) » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
craft\base\PluginInterface (opens new window), yii\base\Configurable (opens new window)
Uses traits
craft\base\PluginTrait (opens new window), craft\commerce\plugin\Routes, craft\commerce\plugin\Services, craft\commerce\plugin\Variables
Since
2.0

View source (opens new window)

# Public Properties

Property Description
addresses craft\commerce\services\Addresses – the address service
aliases (opens new window) array (opens new window) – List of path aliases to be defined.
basePath (opens new window) string (opens new window) – The root directory of the module.
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component.
cart craft\commerce\services\Carts – the cart service
carts craft\commerce\services\Carts – The cart service
changelogUrl (opens new window) string (opens new window), null (opens new window) – The plugin’s changelog URL.
components (opens new window) array (opens new window) – The list of the component definitions or the loaded component instances (ID => definition or instance).
controllerMap (opens new window) array (opens new window) – Mapping from controller ID to controller configurations.
controllerNamespace (opens new window) string (opens new window), null (opens new window) – The namespace that controller classes are in.
controllerPath (opens new window) string (opens new window) – The directory that contains the controller classes.
countries craft\commerce\services\Countries – the countries service
cpNavItem array (opens new window) – the control panel navigation menu
currencies craft\commerce\services\Currencies – the currencies service
customers craft\commerce\services\Customers – the customers service
defaultRoute (opens new window) string (opens new window) – The default route of this module.
description (opens new window) string (opens new window), null (opens new window) – The plugin’s description
developer (opens new window) string (opens new window), null (opens new window) – The plugin developer’s name
developerEmail (opens new window) string (opens new window), null (opens new window) – The plugin developer’s support email
developerUrl (opens new window) string (opens new window), null (opens new window) – The plugin developer’s website URL
discounts craft\commerce\services\Discounts – the discounts service
documentationUrl (opens new window) string (opens new window), null (opens new window) – The plugin’s documentation URL
donation craft\commerce\elements\Donation – the address service
downloadUrl (opens new window) string (opens new window), null (opens new window) – The plugin’s download URL
edition (opens new window) string (opens new window) – The active edition.
emails craft\commerce\services\Emails – the emails service
formulas craft\commerce\services\Formulas – The formulas service
gateways craft\commerce\services\Gateways – the gateways service
handle (opens new window) string (opens new window) – The plugin’s handle (alias of id (opens new window))
hasCpSection boolean (opens new window) – Whether the plugin has its own section in the control panel
hasCpSettings boolean (opens new window) – Whether the plugin has a settings page in the control panel
id (opens new window) string (opens new window) – An ID that uniquely identifies this module among other modules which have the same parent (opens new window).
isInstalled (opens new window) boolean (opens new window) – Whether the plugin is currently installed.
layout (opens new window) string (opens new window), boolean (opens new window), null (opens new window) – The layout that should be applied for views within this module.
layoutPath (opens new window) string (opens new window) – The root directory of layout files.
lineItemStatuses craft\commerce\services\LineItemStatuses – The lineItems service
lineItems craft\commerce\services\LineItems – the line items service
migrator (opens new window) craft\db\MigrationManager (opens new window) – The plugin’s migration manager
minVersionRequired string (opens new window) – The minimum required version the plugin has to be so it can be updated.
module (opens new window) yii\base\Module (opens new window), null (opens new window) – The parent module of this module.
modules (opens new window) array (opens new window) – The modules (indexed by their IDs).
name (opens new window) string (opens new window), null (opens new window) – The plugin’s display name
orderAdjustments craft\commerce\services\OrderAdjustments – the order adjustments service
orderHistories craft\commerce\services\OrderHistories – the order histories service
orderNotices craft\commerce\services\OrderStatuses – the order notices service
orderStatuses craft\commerce\services\OrderStatuses – the orderStatuses service
orders craft\commerce\services\Orders – the orders service
packageName (opens new window) string (opens new window), null (opens new window) – The plugin’s package name
params (opens new window) array (opens new window) – Custom module parameters (name => value).
paymentCurrencies craft\commerce\services\PaymentCurrencies – the paymentCurrencies service
paymentSources craft\commerce\services\PaymentSources – the payment sources service
payments craft\commerce\services\Payments – the payments service
pdf craft\commerce\services\Pdfs – the pdf service
pdfs craft\commerce\services\Pdfs – The PDFs service
plans craft\commerce\services\Plans – the plans service
productTypes craft\commerce\services\ProductTypes – the product types service
products craft\commerce\services\Products – the products service
purchasables craft\commerce\services\Purchasables – the purchasables service
sales craft\commerce\services\Sales – the sales service
schemaVersion string (opens new window), null (opens new window) – The plugin’s schema version number
settings craft\commerce\models\Settings
settingsResponse mixed – the settings page response
shippingCategories craft\commerce\services\ShippingCategories – the shipping categories service
shippingMethods craft\commerce\services\ShippingMethods – the shipping methods service
shippingRuleCategories craft\commerce\services\ShippingRuleCategories – the shipping rule categories service
shippingRules craft\commerce\services\ShippingRules – the shipping rules service
shippingZones craft\commerce\services\ShippingZones – the shipping zones service
sourceLanguage (opens new window) string (opens new window) – The language that the plugin’s messages were written in
states craft\commerce\services\States – the states service
subscriptions craft\commerce\services\Subscriptions – the subscriptions service
t9nCategory (opens new window) string (opens new window), null (opens new window) – The translation category that this plugin’s translation messages should use.
taxCategories craft\commerce\services\TaxCategories – the taxCategories service
taxRates craft\commerce\services\TaxRates – the taxRates service
taxZones craft\commerce\services\TaxZones – the taxZones service
taxes craft\commerce\services\Taxes – The taxes service
transactions craft\commerce\services\Transactions – the transactions service
uniqueId (opens new window) string (opens new window) – The unique ID of the module.
variants craft\commerce\services\Variants – the variants service
version (opens new window) string (opens new window) – The version of this module.
viewPath (opens new window) string (opens new window) – The root directory of view files.
webhooks craft\commerce\services\Webhooks – The variants service

# cpNavItem

Type
array (opens new window)
Default value
null

the control panel navigation menu

View source (opens new window)

# hasCpSection

Type
boolean (opens new window)
Default value
true

Whether the plugin has its own section in the control panel

View source (opens new window)

# hasCpSettings

Type
boolean (opens new window)
Default value
true

Whether the plugin has a settings page in the control panel

View source (opens new window)

# minVersionRequired

Type
string (opens new window)
Default value
'2.2.18'

The minimum required version the plugin has to be so it can be updated.

View source (opens new window)

# schemaVersion

Type
string (opens new window), null (opens new window)
Default value
'3.4.13'

The plugin’s schema version number

View source (opens new window)

# settings

Type
craft\commerce\models\Settings
Default value
null

View source (opens new window)

# settingsResponse

Type
mixed
Default value
null

the settings page response

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() (opens new window) Constructor.
__get() (opens new window) Getter magic method.
__isset() (opens new window) Checks if a property value is null.
__set() (opens new window) Sets the value of a component property.
__unset() (opens new window) Sets a component property to be null.
afterAction() (opens new window) This method is invoked right after an action within this module is executed.
afterSaveSettings() (opens new window) Performs actions after the plugin’s settings are saved.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
beforeAction() (opens new window) This method is invoked right before an action within this module is executed.
beforeInstall() Performs actions before the plugin is installed.
beforeSaveSettings() (opens new window) Performs actions before the plugin’s settings are saved.
behaviors() (opens new window) Returns a list of behaviors that this component should behave as.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
clear() (opens new window) Removes the component from the locator.
createController() (opens new window) Creates a controller instance based on the given route.
createControllerByID() (opens new window) Creates a controller based on the given controller ID.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
editions()
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component.
get() (opens new window) Returns the component instance with the specified ID.
getAddresses() Returns the address service
getBasePath() (opens new window) Returns the root directory of the module.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getCarts() Returns the cart service
getComponents() (opens new window) Returns the list of the component definitions or the loaded component instances.
getControllerPath() (opens new window) Returns the directory that contains the controller classes according to controllerNamespace (opens new window).
getCountries() Returns the countries service
getCpNavItem() Returns the control panel nav item definition for this plugin, if it has a section in the control panel.
getCurrencies() Returns the currencies service
getCustomers() Returns the customers service
getDiscounts() Returns the discounts service
getDonation() Returns the donation purchasable
getEmails() Returns the emails service
getFormulas() Returns the formulas service
getGateways() Returns the gateways service
getHandle() (opens new window) Returns the plugin’s handle (really just an alias of yii\base\Module::$id (opens new window)).
getInstance() (opens new window) Returns the currently requested instance of this module class.
getLayoutPath() (opens new window) Returns the directory that contains layout view files for this module.
getLineItemStatuses() Returns the lineItems statuses service
getLineItems() Returns the lineItems service
getMigrator() (opens new window) Returns the plugin’s migration manager
getModule() (opens new window) Retrieves the child module of the specified ID.
getModules() (opens new window) Returns the sub-modules in this module.
getOrderAdjustments() Returns the orderAdjustments service
getOrderHistories() Returns the orderHistories service
getOrderNotices() Returns the OrderNotices service
getOrderStatuses() Returns the OrderStatuses service
getOrders() Returns the orders service
getPaymentCurrencies() Returns the paymentCurrencies service
getPaymentSources() Returns the payment sources service
getPayments() Returns the payments service
getPdf()
getPdfs() Returns the PDFs service
getPlans() Returns the payment sources service
getProductTypes() Returns the productTypes service
getProducts() Returns the products service
getPurchasables() Returns the purchasables service
getSales() Returns the sales service
getSettings()
getSettingsResponse() Returns the settings page response.
getShippingCategories() Returns the shippingCategories service
getShippingMethods() Returns the shippingMethods service
getShippingRuleCategories() Returns the shippingRules service
getShippingRules() Returns the shippingRules service
getShippingZones() Returns the shippingZones service
getStates() Returns the states service
getSubscriptions() Returns the subscriptions service
getTaxCategories() Returns the taxCategories service
getTaxRates() Returns the taxRates service
getTaxZones() Returns the taxZones service
getTaxes() Returns the taxes service
getTransactions() Returns the transactions service
getUniqueId() (opens new window) Returns an ID that uniquely identifies this module among all modules within the current application.
getVariants() Returns the variants service
getVersion() (opens new window) Returns current module version.
getViewPath() (opens new window) Returns the directory that contains the view files for this module.
getWebhooks() Returns the webhooks service
has() (opens new window) Returns a value indicating whether the locator has the specified component definition or has instantiated the component.
hasEventHandlers() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasModule() (opens new window) Checks whether the child module of the specified ID exists.
hasProperty() (opens new window) Returns a value indicating whether a property is defined for this component.
init() Initializes the module.
install() (opens new window) Installs the plugin.
is() (opens new window) Compares the active edition with the given edition.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
runAction() (opens new window) Runs a controller action specified by a route.
set() (opens new window) Registers a component definition with this locator.
setAliases() (opens new window) Defines path aliases.
setBasePath() (opens new window) Sets the root directory of the module.
setComponents() (opens new window) Registers a set of component definitions in this locator.
setControllerPath() (opens new window) Sets the directory that contains the controller classes.
setInstance() (opens new window) Sets the currently requested instance of this module class.
setLayoutPath() (opens new window) Sets the directory that contains the layout files.
setModule() (opens new window) Adds a sub-module to this module.
setModules() (opens new window) Registers sub-modules in the current module.
setSettings() (opens new window) Sets the plugin settings
setVersion() (opens new window) Sets current module version.
setViewPath() (opens new window) Sets the directory that contains the view files.
t()
trigger() (opens new window) Triggers an event.
uninstall() (opens new window) Uninstalls the plugin.

# beforeInstall()

Performs actions before the plugin is installed.

View source (opens new window)

Returns

boolean (opens new window) – Whether the plugin should be installed

# editions()

View source (opens new window)

# getCpNavItem()

Returns the control panel nav item definition for this plugin, if it has a section in the control panel.

The returned array should contain the following keys:

  • label – The human-facing nav item label
  • url – The URL the nav item should link to
  • id – The HTML id attribute the nav item should have (optional)
  • icon – The path to an SVG file that should be used as the nav item icon (optional)
  • fontIcon – A character/ligature from Craft’s font icon set (optional)
  • badgeCount – A number that should be displayed beside the nav item when unselected
  • subnav – A sub-array of subnav items

The subnav array should be associative, with identifiable keys set to sub-arrays with the following keys:

  • label – The human-facing subnav item label
  • url – The URL the subnav item should link to

For example:

return [
    'label' => 'Commerce',
    'url' => 'commerce',
    'subnav' => [
        'orders' => ['label' => 'Orders', 'url' => 'commerce/orders',
        'discounts' => ['label' => 'Discounts', 'url' => 'commerce/discounts',
    ],
];

Control panel templates can specify which subnav item is selected by defining a selectedSubnavItem variable.

{% set selectedSubnavItem = 'orders' %}

View source (opens new window)

Returns

array (opens new window), null (opens new window)

# getSettings()

View source (opens new window)

Returns

craft\commerce\models\Settings

# getSettingsResponse()

Returns the settings page response.

View source (opens new window)

Returns

mixed – The result that should be returned from craft\controllers\PluginsController::actionEditPluginSettings() (opens new window)

# init()

Initializes the module.

This method is called after the module is created and initialized with property values given in configuration. The default implementation will initialize controllerNamespace (opens new window) if it is not set.

If you override this method, please make sure you call the parent implementation.

View source (opens new window)

# t()

DEPRECATED

Deprecated in 3.2.4

Since
2.2.0

See also \Craft::t() View source (opens new window)

Arguments

Returns

string (opens new window)

# Protected Methods

Method Description
afterInstall() (opens new window) Performs actions after the plugin is installed.
afterUninstall() (opens new window) Performs actions after the plugin is uninstalled.
beforeUninstall() (opens new window) Performs actions before the plugin is uninstalled.
cpNavIconPath() (opens new window) Returns the path to the SVG icon that should be used in the plugin’s nav item in the control panel.
createInstallMigration() (opens new window) Instantiates and returns the plugin’s installation migration, if it has one.
createSettingsModel() Creates and returns the model used to store the plugin’s settings.
defaultVersion() (opens new window) Returns default module version.
settingsHtml() (opens new window) Returns the rendered settings HTML, which will be inserted into the content block on the settings page.

# createSettingsModel()

Creates and returns the model used to store the plugin’s settings.

View source (opens new window)

Returns

craft\base\Model (opens new window), null (opens new window)

# Constants

Constant Description
EDITION_LITE
EDITION_PRO