Skip to content

Instantly share code, notes, and snippets.

@EscApp2
Created March 18, 2024 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EscApp2/2409b47ecc03f7edc28a2ba31e0e5c35 to your computer and use it in GitHub Desktop.
Save EscApp2/2409b47ecc03f7edc28a2ba31e0e5c35 to your computer and use it in GitHub Desktop.
Custom Payment Restrict
<?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