Plans
- Type
- Class
- Namespace
- craft\commerce\services
- Inherits
- craft\commerce\services\Plans » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 2.0
Plans service.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
allEnabledPlans | craft\commerce\base\Plan[] |
allPlans | craft\commerce\base\Plan[] |
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component |
# allEnabledPlans
- Type
- craft\commerce\base\Plan[]
- Access
- Read-only
View source (opens new window)
# allPlans
- Type
- craft\commerce\base\Plan[]
- Access
- Read-only
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) | Returns the value of an object property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets value of an object property. |
__unset() (opens new window) | Sets an object property to null. |
archivePlanById() | Archive a subscription plan by its id. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
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. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
getAllEnabledPlans() | Returns all enabled subscription plans |
getAllGatewayPlans() | Return all subscription plans for a gateway. |
getAllPlans() | Returns all subscription plans |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | Returns all behaviors attached to this component. |
getPlanByHandle() | Returns a subscription plan by its handle. |
getPlanById() | Returns a subscription plan by its id. |
getPlanByReference() | Returns a subscription plan by its reference. |
getPlanByUid() | Returns a subscription plan by its uid. |
getPlansByInformationEntryId() | Returns plans which use the provided Entry for its "information" |
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. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined. |
init() (opens new window) | Initializes the object. |
off() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | Attaches an event handler to an event. |
reorderPlans() | Reorders subscription plans by ids. |
savePlan() | Save a subscription plan |
trigger() (opens new window) | Triggers an event. |
# archivePlanById()
Archive a subscription plan by its id.
View source (opens new window)
Arguments
$id
(integer (opens new window)) – The id
Returns
Throws
# getAllEnabledPlans()
Returns all enabled subscription plans
View source (opens new window)
Returns
# getAllGatewayPlans()
Return all subscription plans for a gateway.
View source (opens new window)
Arguments
$gatewayId
(integer (opens new window))
Returns
# getAllPlans()
Returns all subscription plans
View source (opens new window)
Returns
# getPlanByHandle()
Returns a subscription plan by its handle.
View source (opens new window)
Arguments
$handle
(string (opens new window)) – The plan handle
Returns
craft\commerce\base\Plan, null (opens new window)
Throws
- yii\base\InvalidConfigException (opens new window)
if the plan configuration is not correct
# getPlanById()
Returns a subscription plan by its id.
View source (opens new window)
Arguments
$planId
(integer (opens new window)) – The plan id.
Returns
craft\commerce\base\Plan, null (opens new window)
Throws
- yii\base\InvalidConfigException (opens new window)
if the plan configuration is not correct
# getPlanByReference()
Returns a subscription plan by its reference.
View source (opens new window)
Arguments
$reference
(string (opens new window)) – The plan reference
Returns
craft\commerce\base\Plan, null (opens new window)
Throws
- yii\base\InvalidConfigException (opens new window)
if the plan configuration is not correct
# getPlanByUid()
Returns a subscription plan by its uid.
View source (opens new window)
Arguments
$planUid
(string (opens new window)) – The plan uid.
Returns
craft\commerce\base\Plan, null (opens new window)
Throws
- yii\base\InvalidConfigException (opens new window)
if the plan configuration is not correct
# getPlansByInformationEntryId()
Returns plans which use the provided Entry for its "information"
View source (opens new window)
Arguments
$entryId
(integer (opens new window)) – The Entry ID to search by
Returns
# reorderPlans()
Reorders subscription plans by ids.
View source (opens new window)
Arguments
$ids
(array (opens new window)) – Array of plans.
Returns
boolean (opens new window) – Always true.
# savePlan()
Save a subscription plan
View source (opens new window)
Arguments
$plan
(craft\commerce\base\Plan) – The payment source being saved.$runValidation
(boolean (opens new window)) – Should we validate this plan before saving.
Returns
boolean (opens new window) – Whether the plan was saved successfully
Throws
- yii\base\InvalidConfigException (opens new window)
if subscription plan not found by id.
# Events
# EVENT_AFTER_SAVE_PLAN
The event that is triggered after a plan is saved.
Plugins can get notified after a subscription plan is being saved.
use craft\commerce\events\PlanEvent;
use craft\commerce\services\Plans;
use yii\base\Event;
Event::on(Plans::class, Plans::EVENT_AFTER_SAVE_PLAN, function(PlanEvent $e) {
// Do something
});
# EVENT_ARCHIVE_PLAN
The event that is triggered when a plan is archived.
Plugins can get notified whenever a subscription plan is being archived. This is useful as sometimes this can be triggered by an action on the gateway.
use craft\commerce\events\PlanEvent;
use craft\commerce\services\Plans;
use yii\base\Event;
Event::on(Plans::class, Plans::EVENT_ARCHIVE_PLAN, function(PlanEvent $e) {
// Do something as the plan is being retired.
});
# EVENT_BEFORE_SAVE_PLAN
The event that is triggered before a plan is saved.
Plugins can get notified before a subscription plan is being saved.
use craft\commerce\events\PlanEvent;
use craft\commerce\services\Plans;
use yii\base\Event;
Event::on(Plans::class, Plans::EVENT_BEFORE_SAVE_PLAN, function(PlanEvent $e) {
// Do something
});
← Pdf ProductTypes →