Created
March 18, 2024 13:02
-
-
Save EscApp2/2409b47ecc03f7edc28a2ba31e0e5c35 to your computer and use it in GitHub Desktop.
Custom Payment Restrict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Bitrix\Sale\Services\Base; | |
use Bitrix\Sale\Internals\Entity; | |
use Bitrix\Sale\Payment; | |
class CustomPaymentRestrict extends Base\Restriction | |
{ | |
const NAME = 'Только для админов'; | |
public static function getClassTitle() | |
{ | |
return self::NAME; | |
} | |
public static function getClassDescription() | |
{ | |
return self::NAME; | |
} | |
protected static function extractParams(Entity $entity) | |
{ | |
$isAvail = false; | |
global $USER; | |
if ($entity instanceof Payment) { | |
/** @var PaymentCollection $collection */ | |
$collection = $entity->getCollection(); | |
/** @var Order $order */ | |
$order = $collection->getOrder(); | |
/** @var \Bitrix\Sale\Basket $basket */ | |
$basket = $order->getBasket(); | |
/** @var \Bitrix\Sale\BasketItem $basketItems */ | |
$basketItems = $basket->getOrderableItems(); | |
if($USER->isAdmin()){ | |
$isAvail = true; | |
} | |
} | |
return [ | |
'AVAIL_FOR_ALL' => $isAvail, | |
]; | |
} | |
public static function getParamsStructure($entityId = 0) | |
{ | |
return [ | |
'ITEM_COUNT' => [ | |
'TYPE' => 'NUMBER', | |
'DEFAULT' => "0", | |
'MIN' => 0, | |
'LABEL' => 'Параметр, от которого ничего не зависит', | |
] | |
]; | |
} | |
public static function check($params, array $restrictionParams, $serviceId = 0) | |
{ | |
$result = true; | |
if ($params['AVAIL_FOR_ALL'] === false) { | |
return false; | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment