Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
bypaysystem.php
1
<?php
2
namespace
Bitrix\Sale\Delivery\Restrictions
;
3
4
use
Bitrix\Main\Localization\Loc
;
5
use
Bitrix\Sale\Internals\CollectableEntity
;
6
use
Bitrix\Sale\Internals\DeliveryPaySystemTable
;
7
use
Bitrix\Sale\Internals\Entity
;
8
use
Bitrix\Sale\Internals\PaySystemInner
;
9
use
Bitrix\Sale\Order
;
10
use
Bitrix\Sale\PaySystem
;
11
12
Loc::loadMessages
(__FILE__);
13
18
class
ByPaySystem
extends
Base
19
{
20
public
static
$easeSort
= 200;
21
protected
static
$preparedData
= array();
22
23
public
static
function
getClassTitle
()
24
{
25
return
Loc::getMessage
(
"SALE_DLVR_RSTR_BY_PAYSYSTEM_NAME"
);
26
}
27
28
public
static
function
getClassDescription
()
29
{
30
return
Loc::getMessage
(
"SALE_DLVR_RSTR_BY_PAYSYSTEM_DESCRIPT"
);
31
}
32
33
public
static
function
check
($paySystemIds, array $restrictionParams, $deliveryId = 0)
34
{
35
if
(intval($deliveryId) <= 0)
36
return
true
;
37
38
if
(empty($paySystemIds))
39
return
true
;
40
41
$paySystems =
self::getPaySystemsByDeliveryId
($deliveryId);
42
43
if
(empty($paySystems))
44
return
true
;
45
46
$diff = array_diff($paySystemIds, $paySystems);
47
48
return
empty($diff);
49
}
50
51
protected
static
function
extractParams(
Entity
$entity)
52
{
53
$result = array();
54
55
if
($entity instanceof
CollectableEntity
)
56
{
58
$collection = $entity->getCollection();
59
61
$order = $collection->getOrder();
62
}
63
elseif ($entity instanceof
Order
)
64
{
66
$order = $entity;
67
}
68
69
if
(!$order)
70
return
$result;
71
73
foreach
($order->getPaymentCollection() as $payment)
74
{
75
$paySystemId = $payment->getPaymentSystemId();
76
if
($paySystemId)
77
$result[] = $paySystemId;
78
}
79
80
return
$result;
81
}
82
83
protected
static
function
getPaySystemsList
(): array
84
{
85
static
$result =
null
;
86
87
if
($result !==
null
)
88
{
89
return
$result;
90
}
91
92
$result = [];
93
94
$iterator = PaySystem\Manager::getList([
95
'select'
=> [
96
'ID'
,
97
'NAME'
,
98
'SORT'
,
99
],
100
'filter'
=> [
101
'=ACTIVE'
=>
'Y'
,
102
],
103
'order'
=> [
'SORT'
=>
'ASC'
,
'NAME'
=>
'ASC'
]
104
]);
105
while
($row = $iterator->fetch())
106
{
107
$result[$row[
'ID'
]] = htmlspecialcharsbx($row[
'NAME'
]);
108
}
109
110
return
$result;
111
}
112
113
public
static
function
getParamsStructure
($entityId = 0)
114
{
115
$result = array(
116
"PAY_SYSTEMS"
=> array(
117
"TYPE"
=>
"ENUM"
,
118
'MULTIPLE'
=>
'Y'
,
119
"LABEL"
=>
Loc::getMessage
(
"SALE_DLVR_RSTR_BY_PAYSYSTEM_PRM_PS"
),
120
"OPTIONS"
=> self::getPaySystemsList()
121
)
122
);
123
124
return
$result;
125
}
126
127
protected
static
function
getPaySystemsByDeliveryId
($deliveryId = 0)
128
{
129
if
($deliveryId == 0)
130
return
array();
131
132
$result =
DeliveryPaySystemTable::getLinks
($deliveryId,
DeliveryPaySystemTable::ENTITY_TYPE_DELIVERY
, self::$preparedData);
133
return
$result;
134
}
135
136
protected
static
function
prepareParamsForSaving
(array $params = array(), $deliveryId = 0)
137
{
138
if
(intval($deliveryId) <= 0)
139
return
$params;
140
141
if
(isset($params[
"PAY_SYSTEMS"
]) && is_array($params[
"PAY_SYSTEMS"
]))
142
{
143
DeliveryPaySystemTable::setLinks
(
144
$deliveryId,
145
DeliveryPaySystemTable::ENTITY_TYPE_DELIVERY
,
146
$params[
"PAY_SYSTEMS"
],
147
true
148
);
149
150
unset($params[
"PAY_SYSTEMS"
]);
151
}
152
153
return
$params;
154
}
155
156
public
static
function
save
(array $fields, $restrictionId = 0)
157
{
158
$params = $fields[
"PARAMS"
];
159
$fields[
"PARAMS"
] = array();
160
161
$result = parent::save($fields, $restrictionId);
162
163
self::prepareParamsForSaving
($params, $fields[
"SERVICE_ID"
]);
164
return
$result;
165
}
166
167
public
static
function
prepareParamsValues
(array $paramsValues, $deliveryId = 0)
168
{
169
$result = array();
170
171
if
(intval($deliveryId > 0))
172
$result =
DeliveryPaySystemTable::getLinks
($deliveryId,
DeliveryPaySystemTable::ENTITY_TYPE_DELIVERY
, array());
173
174
return
array(
"PAY_SYSTEMS"
=> $result);
175
}
176
177
public
static
function
delete
($restrictionId, $deliveryId = 0)
178
{
179
DeliveryPaySystemTable::setLinks
(
180
$deliveryId,
181
DeliveryPaySystemTable::ENTITY_TYPE_DELIVERY
,
182
array(),
183
true
184
);
185
186
return
parent::delete($restrictionId);
187
}
188
189
public
static
function
prepareData
(array $deliveryIds)
190
{
191
if
(empty($deliveryIds))
192
return
;
193
194
self::$preparedData = \Bitrix\Sale\Internals\DeliveryPaySystemTable::prepareData($deliveryIds,
DeliveryPaySystemTable::ENTITY_TYPE_DELIVERY
);
195
}
196
}
Bitrix\Catalog\Model\Entity
Definition
entity.php:12
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\Sale\Delivery\ExtraServices\Base
Definition
base.php:10
Bitrix\Sale\Delivery\Restrictions\ByPaySystem
Definition
bypaysystem.php:19
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\check
static check($paySystemIds, array $restrictionParams, $deliveryId=0)
Definition
bypaysystem.php:33
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\prepareData
static prepareData(array $deliveryIds)
Definition
bypaysystem.php:189
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\$easeSort
static $easeSort
Definition
bypaysystem.php:20
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\prepareParamsValues
static prepareParamsValues(array $paramsValues, $deliveryId=0)
Definition
bypaysystem.php:167
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\getClassTitle
static getClassTitle()
Definition
bypaysystem.php:23
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\$preparedData
static $preparedData
Definition
bypaysystem.php:21
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\getPaySystemsByDeliveryId
static getPaySystemsByDeliveryId($deliveryId=0)
Definition
bypaysystem.php:127
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\save
static save(array $fields, $restrictionId=0)
Definition
bypaysystem.php:156
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\getClassDescription
static getClassDescription()
Definition
bypaysystem.php:28
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\getPaySystemsList
static getPaySystemsList()
Definition
bypaysystem.php:83
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\getParamsStructure
static getParamsStructure($entityId=0)
Definition
bypaysystem.php:113
Bitrix\Sale\Delivery\Restrictions\ByPaySystem\prepareParamsForSaving
static prepareParamsForSaving(array $params=array(), $deliveryId=0)
Definition
bypaysystem.php:136
Bitrix\Sale\Helpers\Order
Definition
order.php:10
Bitrix\Sale\Internals\CollectableEntity
Definition
collectableentity.php:14
Bitrix\Sale\Internals\DeliveryPaySystemTable
Definition
delivery_paysystem.php:40
Bitrix\Sale\Internals\DeliveryPaySystemTable\setLinks
static setLinks($entityId, $entityType, array $linkedIds=array(), $actualizeRestrictions=true)
Definition
delivery_paysystem.php:114
Bitrix\Sale\Internals\DeliveryPaySystemTable\ENTITY_TYPE_DELIVERY
const ENTITY_TYPE_DELIVERY
Definition
delivery_paysystem.php:44
Bitrix\Sale\Internals\DeliveryPaySystemTable\getLinks
static getLinks($entityId, $entityType, array $preparedData=array(), $considerParent=true)
Definition
delivery_paysystem.php:525
Bitrix\Sale\Internals\PaySystemInner
Definition
paysysteminner.php:17
Bitrix\Sale\Delivery\Restrictions
Definition
base.php:2
Bitrix\Sale\PaySystem
Definition
applepay.php:3
modules
sale
lib
delivery
restrictions
bypaysystem.php
Создано системой
1.10.0