Skip to content

Plans ​

Type
Class
Namespace
craft\commerce\services
Inherits
craft\commerce\services\Plans » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
2.0

Plans service.

View source

Public Properties ​

PropertyDescription
allEnabledPlansarray, craft\commerce\base\Plan[]
allPlansarray, craft\commerce\base\Plan[]
behaviorsyii\base\Behavior – List of behaviors attached to this component.

allEnabledPlans ​

Type
array, craft\commerce\base\Plan[]
Default value
null

View source

allPlans ​

Type
array, craft\commerce\base\Plan[]
Default value
null

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
archivePlanById()Archive a subscription plan by its id.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() 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()Returns the named behavior object.
getBehaviors()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.
getPlansByGatewayId()Return all subscription plans for a gateway.
getPlansByInformationEntryId()Returns plans which use the provided Entry for its "information"
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined for this component.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
reorderPlans()Reorders subscription plans by ids.
savePlan()Save a subscription plan
trigger()Triggers an event.

archivePlanById() ​

Archive a subscription plan by its id.

View source

Arguments ​

Throws ​

getAllEnabledPlans() ​

Returns all enabled subscription plans

View source

Returns ​

craft\commerce\base\Plan[]

getAllGatewayPlans() ​

DEPRECATED

Deprecated in 4.0. Use getPlansByGatewayId() instead.

Return all subscription plans for a gateway.

View source

Arguments ​

  • $gatewayId

Returns ​

craft\commerce\base\Plan[]

getAllPlans() ​

Returns all subscription plans

View source

Returns ​

craft\commerce\base\Plan[]

getPlanByHandle() ​

Returns a subscription plan by its handle.

View source

Arguments ​

  • $handle (string) – The plan handle

getPlanById() ​

Returns a subscription plan by its id.

View source

Arguments ​

  • $planId (integer) – The plan id.

getPlanByReference() ​

Returns a subscription plan by its reference.

View source

Arguments ​

  • $reference (string) – The plan reference

getPlanByUid() ​

Returns a subscription plan by its uid.

View source

Arguments ​

  • $planUid (string) – The plan uid.

getPlansByGatewayId() ​

Return all subscription plans for a gateway.

View source

Arguments ​

  • $gatewayId

Returns ​

craft\commerce\base\Plan[]

getPlansByInformationEntryId() ​

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

View source

Arguments ​

  • $entryId (integer) – The Entry ID to search by

Returns ​

craft\commerce\base\Plan[]

reorderPlans() ​

Reorders subscription plans by ids.

View source

Arguments ​

  • $ids (array) – Array of plans.

Returns ​

boolean – Always true.

Throws ​

savePlan() ​

Save a subscription plan

View source

Arguments ​

Returns ​

boolean – 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.

php
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.

php
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.

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