-
-
Save JamesBondsky/6e948d3cbbc5d2163f7bd76b2dbff512 to your computer and use it in GitHub Desktop.
ограничения оплат и платежных систем pay system paysystem restriction delivery
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
//help | |
//https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=43&LESSON_ID=7352&LESSON_PATH=3913.3516.4776.7351.7352 | |
//https://zen.yandex.ru/media/id/5d6a4518dfa9ce00ad86fcb7/bitriks-polzovatelskie-ogranicheniia-dostavki-i-platejnoi-sistemy-5d8e873bbd639600b14c987c | |
//example | |
//https://dev.1c-bitrix.ru/community/forums/forum6/topic132246/ | |
//https://gist.github.com/dmitryburov/878edc4aec1477d54f92913cd5e25cbf |
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
<? | |
\Bitrix\Main\EventManager::getInstance()->addEventHandler( | |
'sale', | |
'onSalePaySystemRestrictionsClassNamesBuildList', | |
'onSalePaySystemRestrictionsClassNamesBuildListHandler' | |
); | |
//AddEventHandler("sale", "onSalePaySystemRestrictionsClassNamesBuildList", "onSalePaySystemRestrictionsClassNamesBuildListHandler"); | |
//AddEventHandler("sale", "onSaleDeliveryRestrictionsClassNamesBuildList", "onSaleDeliveryRestrictionsClassNamesBuildListHandler"); | |
//платежные системы | |
function onSalePaySystemRestrictionsClassNamesBuildListHandler() | |
{ | |
//relative path important | |
$file = '/local/php_interface/salerestrictions.php'; | |
return new \Bitrix\Main\EventResult( | |
\Bitrix\Main\EventResult::SUCCESS, | |
array( | |
'\salerestrictions' => $file, | |
) | |
); | |
} | |
// службы доставки | |
function onSaleDeliveryRestrictionsClassNamesBuildListHandler(){ | |
//relative path important | |
$file = '/local/php_interface/salerestrictions.php'; | |
return new \Bitrix\Main\EventResult( | |
\Bitrix\Main\EventResult::SUCCESS, | |
array( | |
'\salerestrictions' => $file, | |
) | |
); | |
} |
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
<? | |
use Bitrix\Sale\Internals\CollectableEntity; | |
use Bitrix\Sale\Internals\PersonTypeTable; | |
use Bitrix\Sale\ShipmentCollection; | |
use Bitrix\Main\Localization\Loc; | |
use Bitrix\Sale\Order; | |
Loc::loadMessages(__FILE__); | |
class salerestrictions extends Bitrix\Sale\Services\Base\Restriction | |
{ | |
/** | |
* @param $usergroupId Данные из self::extractParams() | |
* @param array $params | |
* @param int $deliveryId | |
* @return bool | |
*/ | |
public static function check($usergroupId, array $params, $deliveryId = 0) | |
{ | |
if (is_array($params) && isset($params['USER_GROUP_ID'])) | |
{ | |
return sizeof(array_intersect($usergroupId, $params['USER_GROUP_ID']))>0; | |
} | |
return true; | |
} | |
/** | |
* @param CollectableEntity $entity | |
* @return int | |
*/ | |
public static function extractParams(CollectableEntity $entity) | |
{ | |
/** @var ShipmentCollection $collection */ | |
$collection = $entity->getCollection(); | |
/** @var Order $order */ | |
$order = $collection->getOrder(); | |
//pre($order); | |
if($GLOBALS['USER']->isAuthorized()) | |
$usergroupId = $GLOBALS['USER']->GetUserGroupArray(); | |
else | |
$usergroupId = array(2); | |
return $usergroupId; | |
} | |
/** | |
* @return mixed | |
*/ | |
public static function getClassTitle() | |
{ | |
return 'по группам пользователей'; | |
} | |
/** | |
* @return mixed | |
*/ | |
public static function getClassDescription() | |
{ | |
return 'Ограничение по группам пользователей'; | |
} | |
/** | |
* @param $deliveryId | |
* @return array | |
* @throws \Bitrix\Main\ArgumentException | |
*/ | |
public static function getParamsStructure($deliveryId = 0) | |
{ | |
$personTypeList = array(); | |
$dbRes = \Bitrix\Main\GroupTable::getList(); | |
while ($personType = $dbRes->fetch()) | |
$personTypeList[$personType["ID"]] = $personType["NAME"]." (".$personType["ID"].")"; | |
return array( | |
"USER_GROUP_ID" => array( | |
"TYPE" => "ENUM", | |
'MULTIPLE' => 'Y', | |
"LABEL" => Loc::getMessage("SALE_DLVR_RSTR_BY_PERSON_TYPE_NAME"), | |
"OPTIONS" => $personTypeList | |
) | |
); | |
} | |
/** | |
* @param $mode | |
* @return int | |
*/ | |
public static function getSeverity($mode) | |
{ | |
return \Bitrix\Sale\Delivery\Restrictions\Manager::SEVERITY_STRICT; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment