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
$allEnabledPlanscraft\commerce\base\Plan[]
$allPlanscraft\commerce\base\Plan[]
$behaviorsyii\base\Behavior – List of behaviors attached to this component

$allEnabledPlans

Signature

public craft\commerce\base\Plan[] getAllEnabledPlans ( )

$allPlans

Signature

public craft\commerce\base\Plan[] getAllPlans ( )

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 an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to 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.
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.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
savePlan()Save a subscription plan
trigger()Triggers an event.

archivePlanById()

Archive a subscription plan by its id.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean archivePlanById ( \craft\commerce\services\int $id )

getAllEnabledPlans()

Returns all enabled subscription plans

View source

Returns

craft\commerce\base\Plan[]

Signature

public craft\commerce\base\Plan[] getAllEnabledPlans ( )

getAllGatewayPlans()

Return all subscription plans for a gateway.

View source

Arguments

Returns

craft\commerce\base\Plan[]

Signature

public craft\commerce\base\Plan[] getAllGatewayPlans ( \craft\commerce\services\int $gatewayId )

getAllPlans()

Returns all subscription plans

View source

Returns

craft\commerce\base\Plan[]

Signature

public craft\commerce\base\Plan[] getAllPlans ( )

getPlanByHandle()

Returns a subscription plan by its handle.

View source

Arguments

  • $handle (string) – The plan handle

Returns

craft\commerce\base\Plan, null

Throws

Signature

public craft\commerce\base\Plan, null getPlanByHandle ( \craft\commerce\services\string $handle )

getPlanById()

Returns a subscription plan by its id.

View source

Arguments

Returns

craft\commerce\base\Plan, null

Throws

Signature

public craft\commerce\base\Plan, null getPlanById ( \craft\commerce\services\int $planId )

getPlanByReference()

Returns a subscription plan by its reference.

View source

Arguments

  • $reference (string) – The plan reference

Returns

craft\commerce\base\Plan, null

Throws

Signature

public craft\commerce\base\Plan, null getPlanByReference ( \craft\commerce\services\string $reference )

getPlanByUid()

Returns a subscription plan by its uid.

View source

Arguments

  • $planUid (string) – The plan uid.

Returns

craft\commerce\base\Plan, null

Throws

Signature

public craft\commerce\base\Plan, null getPlanByUid ( \craft\commerce\services\string $planUid )

savePlan()

Save a subscription plan

View source

Arguments

Returns

boolean – Whether the plan was saved successfully

Throws

Signature

public boolean savePlan ( craft\commerce\base\Plan $plan, \craft\commerce\services\bool $runValidation = true )

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