setupDefaultRestrictions
public static function \Bitrix\Sale\Services\Base\RestrictionManager::setupDefaultRestrictions( RestrictableService $service );
This method applies all default limitations for a service to be applied when adding this service. It means that if we add a payment system that operates only in USD, then when calling the method setupDefaultRestrictions, a restriction by "USD" currency is added to this payment system. Static method.
Note: currently, this method operates only with a single type of services – payment systems.
Parameters
Parameter | Description | Version |
---|---|---|
$service | Service, to be limited (for example, payment system). It must implement the interface \Bitrix\Sale\Services\Base\RestrictableService . |
Restriction manager RestrictionManager
and the service $service
, that is passed into the method of this manager must have a single type (in our case, a payment system manager is passed to the payment system restriction manager).
The method setupDefaultRestrictions is called for payment system after adding such system to the database. The method is called in all locations where payment system is added (in public and admin site sections).
Examples
public static function setupDefaultRestrictions(RestrictableService $service): Result { $result = new Result(); // Next, gets collections of restrictions which were initially written for the service. Collection of restrictions is the class Bitrix\Sale\Services\Base\RestrictionInfoCollection $startupRestrictions = $service->getStartupRestrictions(); // Then the third-party developers can subscribe to the event of applying standard restrictions, traced by SERVICE_ID which server it is, as well as remove/add to collection of restrictions STARTUP_RESTRICTIONS_COLLECTION the limits to be finally applied to the service. Currently, this is applicable to the payment systems only (new Event( moduleId: 'sale', type: static::ON_STARTUP_SERVICE_RESTRICTIONS_EVENT_NAME, [ 'STARTUP_RESTRICTIONS_COLLECTION' => $startupRestrictions, 'SERVICE_ID' => $service->getServiceId(), ] ))->send(); self::clearAlreadyUsedByServiceRestrictions($service->getserviceId(), $startupRestrictions); /** @var RestrictionInfo $restrictionInfo */ // Below is the final list of restrictions. Each restriction from the collection is applied to the payment scheme foreach ($startupRestrictions as $restrictionInfo) { $applyResult = static::applyRestriction($service->getServiceId(), $restrictionInfo); $result->addErrors($applyResult->getErrors()); } // Restrictions introduced by developers must be fetched as class Bitrix\Sale\Services\Base\RestrictionInfo. In the same manner, they are stored in the collection. return $result; }