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.
Public Properties ​
Property | Description |
---|---|
allEnabledPlans | array, craft\commerce\base\Plan[] |
allPlans | array, craft\commerce\base\Plan[] |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
allEnabledPlans
​
- Type
- array, craft\commerce\base\Plan[]
- Default value
null
allPlans
​
- Type
- array, craft\commerce\base\Plan[]
- Default value
null
Public Methods ​
Method | Description |
---|---|
__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.
Arguments ​
$id
(integer) – The id
Throws ​
getAllEnabledPlans()
​
Returns all enabled subscription plans
Returns ​
getAllGatewayPlans()
​
DEPRECATED
Deprecated in 4.0. Use getPlansByGatewayId() instead.
Return all subscription plans for a gateway.
Arguments ​
$gatewayId
Returns ​
getAllPlans()
​
Returns all subscription plans
Returns ​
getPlanByHandle()
​
Returns a subscription plan by its handle.
Arguments ​
$handle
(string) – The plan handle
getPlanById()
​
Returns a subscription plan by its id.
Arguments ​
$planId
(integer) – The plan id.
getPlanByReference()
​
Returns a subscription plan by its reference.
Arguments ​
$reference
(string) – The plan reference
getPlanByUid()
​
Returns a subscription plan by its uid.
Arguments ​
$planUid
(string) – The plan uid.
getPlansByGatewayId()
​
Return all subscription plans for a gateway.
Arguments ​
$gatewayId
Returns ​
getPlansByInformationEntryId()
​
Returns plans which use the provided Entry for its "information"
Arguments ​
$entryId
(integer) – The Entry ID to search by
Returns ​
reorderPlans()
​
Reorders subscription plans by ids.
Arguments ​
$ids
(array) – Array of plans.
Returns ​
boolean – Always true.
Throws ​
savePlan()
​
Save a subscription plan
Arguments ​
$plan
(craft\commerce\base\Plan) – The payment source being saved.$runValidation
(boolean) – Should we validate this plan before saving.
Returns ​
boolean – Whether the plan was saved successfully
Throws ​
- yii\base\InvalidConfigException
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
});