Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
paymentavailablespaysystems.php
1
<?php
2
3
namespace
Bitrix\Sale\PaySystem
;
4
5
use
Bitrix\Main\Error
;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Main\Result
;
8
use
Bitrix\Sale\Internals\PaymentPaySystemAvailableTable
;
9
use
Bitrix\Sale\Internals\PaymentTable
;
10
use
Bitrix\Sale\Internals\PaySystemActionTable
;
11
12
Loc::loadMessages
(__FILE__);
13
19
class
PaymentAvailablesPaySystems
20
{
27
public
static
function
clearBindings
(
int
$paymentId)
28
{
29
return
self::setBindings
($paymentId, []);
30
}
31
41
public
static
function
setBindings
(
int
$paymentId, array $paySystemIds)
42
{
43
$result =
new
Result
();
44
45
// check existing payment
46
$existPayment = PaymentTable::getCount([
47
'=ID'
=> $paymentId,
48
]) > 0;
49
if
(!$existPayment)
50
{
51
$result->addError(
52
new
Error
(
Loc::getMessage
(
'SALE_PS_PAYMENT_AVAILABLES_PAYSYSTEMS_NOT_FOUND_PAYMENT'
))
53
);
54
return
$result;
55
}
56
57
// grouping existing items by added & deleted
58
$existPaySystemIds = [];
59
$existRows =
PaymentPaySystemAvailableTable::getList
([
60
'select'
=> [
61
'ID'
,
62
'PAY_SYSTEM_ID'
,
63
],
64
'filter'
=> [
65
'=PAYMENT_ID'
=> $paymentId,
66
],
67
]);
68
69
$deletedIds = [];
70
$paySystemIds = array_map(
'intval'
, $paySystemIds);
71
foreach
($existRows as $row)
72
{
73
$rowPaySystemId = (int)$row[
'PAY_SYSTEM_ID'
];
74
if
(in_array($rowPaySystemId, $paySystemIds,
true
))
75
{
76
$existPaySystemIds[] = $rowPaySystemId;
77
}
78
else
79
{
80
$deletedIds[] = (int)$row[
'ID'
];
81
}
82
}
83
$addedPaySystemIds = array_diff($paySystemIds, $existPaySystemIds);
84
85
// delete old pay systems
86
foreach
($deletedIds as $deleteId)
87
{
88
$deleteResult =
PaymentPaySystemAvailableTable::delete
($deleteId);
89
foreach
($deleteResult->getErrors() as $err)
90
{
91
$result->addError($err);
92
}
93
}
94
95
// add new exist pay systems
96
$paySystems = PaySystemActionTable::getList([
97
'select'
=> [
98
'ID'
,
99
],
100
'filter'
=> [
101
'=ID'
=> $addedPaySystemIds,
102
],
103
]);
104
foreach
($paySystems as $item)
105
{
106
$addResult =
PaymentPaySystemAvailableTable::add
([
107
'PAYMENT_ID'
=> $paymentId,
108
'PAY_SYSTEM_ID'
=> (
int
)$item[
'ID'
],
109
]);
110
foreach
($addResult->getErrors() as $err)
111
{
112
$result->addError($err);
113
}
114
}
115
116
return
$result;
117
}
118
125
public
static
function
getAvailablePaySystemIdsByPaymentId
(
int
$paymentId)
126
{
127
$ret = [];
128
129
$rows =
PaymentPaySystemAvailableTable::getList
([
130
'select'
=> [
131
'PAY_SYSTEM_ID'
,
132
],
133
'filter'
=> [
134
'=PAYMENT_ID'
=> $paymentId,
135
],
136
]);
137
foreach
($rows as $row)
138
{
139
$ret[] = (int)$row[
'PAY_SYSTEM_ID'
];
140
}
141
142
return
$ret;
143
}
144
}
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Definition
datamanager.php:1632
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Definition
datamanager.php:874
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Sale\Internals\PaySystemActionTable
Definition
paysystemaction.php:40
Bitrix\Sale\Internals\PaymentPaySystemAvailableTable
Definition
paymentpaysystemavailabletable.php:35
Bitrix\Sale\Internals\PaymentTable
Definition
payment.php:32
Bitrix\Sale\PaySystem\PaymentAvailablesPaySystems
Definition
paymentavailablespaysystems.php:20
Bitrix\Sale\PaySystem\PaymentAvailablesPaySystems\clearBindings
static clearBindings(int $paymentId)
Definition
paymentavailablespaysystems.php:27
Bitrix\Sale\PaySystem\PaymentAvailablesPaySystems\getAvailablePaySystemIdsByPaymentId
static getAvailablePaySystemIdsByPaymentId(int $paymentId)
Definition
paymentavailablespaysystems.php:125
Bitrix\Sale\PaySystem\PaymentAvailablesPaySystems\setBindings
static setBindings(int $paymentId, array $paySystemIds)
Definition
paymentavailablespaysystems.php:41
Bitrix\Sale\PaySystem
Definition
applepay.php:3
modules
sale
lib
paysystem
paymentavailablespaysystems.php
Создано системой
1.10.0