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

# allEnabledPlans

Type
array (opens new window), craft\commerce\base\Plan[]
Default value
null

View source (opens new window)

# allPlans

Type
array (opens new window), craft\commerce\base\Plan[]
Default value
null

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 a component property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets the value of a component property.
__unset() (opens new window) Sets a component property to be 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 for this component.
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

Returns

boolean (opens new window)

Throws

# getAllEnabledPlans()

Returns all enabled subscription plans

View source (opens new window)

Returns

craft\commerce\base\Plan[]

# getAllGatewayPlans()

Return all subscription plans for a gateway.

View source (opens new window)

Arguments

Returns

craft\commerce\base\Plan[]

# getAllPlans()

Returns all subscription plans

View source (opens new window)

Returns

craft\commerce\base\Plan[]

# getPlanByHandle()

Returns a subscription plan by its handle.

View source (opens new window)

Arguments

Returns

craft\commerce\base\Plan, null (opens new window)

# getPlanById()

Returns a subscription plan by its id.

View source (opens new window)

Arguments

Returns

craft\commerce\base\Plan, null (opens new window)

# getPlanByReference()

Returns a subscription plan by its reference.

View source (opens new window)

Arguments

Returns

craft\commerce\base\Plan, null (opens new window)

# getPlanByUid()

Returns a subscription plan by its uid.

View source (opens new window)

Arguments

Returns

craft\commerce\base\Plan, null (opens new window)

# getPlansByInformationEntryId()

Returns plans which use the provided Entry for its "information"

View source (opens new window)

Arguments

Returns

craft\commerce\base\Plan[]

# reorderPlans()

Reorders subscription plans by ids.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Always true.

# savePlan()

Save a subscription plan

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the plan was saved successfully

Throws

# Events

# EVENT_AFTER_SAVE_PLAN

Type
craft\commerce\events\PlanEvent

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

Type
craft\commerce\events\PlanEvent

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

Type
craft\commerce\events\PlanEvent

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
});