1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
pricetypegroup.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Catalog\Controller;
4
5
use Bitrix\Catalog\GroupAccessTable;
6
use Bitrix\Main\Error;
7
use Bitrix\Main\GroupTable;
8
use Bitrix\Main\Result;
9
10
class
PriceTypeGroup
extends
Controller
11
{
12
use
ListAction
;
// default listAction realization
13
use PriceTypeRights;
14
15
// region Actions
16
20
public
function
getFieldsAction
():
array
21
{
22
return
[$this->
getServiceItemName
() => $this->
getViewFields
()];
23
}
24
29
public
function
addAction
(
array
$fields
): ?
array
30
{
31
$checkFieldsResult = $this->checkFields(
$fields
);
32
if
(!$checkFieldsResult->isSuccess())
33
{
34
$this->addErrors($checkFieldsResult->getErrors());
35
36
return
null
;
37
}
38
39
$addResult =
GroupAccessTable::add
(
$fields
);
40
if
(!$addResult)
41
{
42
$this->addErrors($addResult->getErrors());
43
44
return
null
;
45
}
46
47
return
[$this->
getServiceItemName
() => $this->
get
($addResult->getId())];
48
}
49
54
59
public
function
deleteAction
(
int
$id): ?bool
60
{
61
$existsResult = $this->
exists
($id);
62
if
(!$existsResult->isSuccess())
63
{
64
$this->addErrors($existsResult->getErrors());
65
66
return
null
;
67
}
68
69
$deleteResult =
GroupAccessTable::delete
($id);
70
if
(!$deleteResult)
71
{
72
$this->addErrors($deleteResult->getErrors());
73
74
return
null
;
75
}
76
77
return
true
;
78
}
79
// endregion
80
85
private
function
checkFields(
array
$fields
):
Result
86
{
87
$result
=
new
Result
();
88
89
$priceTypeId =
$fields
[
'CATALOG_GROUP_ID'
];
90
$priceType =
\Bitrix\Catalog\GroupTable::getById
($priceTypeId)->fetch();
91
if
(!$priceType)
92
{
93
$result
->addError(
new
Error
(
'The specified price type does not exist'
));
94
}
95
96
$groupId =
$fields
[
'GROUP_ID'
];
97
$group =
GroupTable::getById
($groupId)->fetch();
98
if
(!$group)
99
{
100
$result
->addError(
new
Error
(
'The specified group does not exist'
));
101
}
102
103
$accessTypeValues = [
GroupAccessTable::ACCESS_BUY
,
GroupAccessTable::ACCESS_VIEW
];
104
$access
=
$fields
[
'ACCESS'
];
105
if
(!in_array(
$access
, $accessTypeValues,
true
))
106
{
107
$result
->addError(
108
new
Error(
109
'Invalid access type provided. The available values are: '
110
. implode(
', '
, $accessTypeValues)
111
)
112
);
113
}
114
115
$exists = (bool)
GroupAccessTable::getRow
([
116
'select'
=> [
'ID'
],
117
'filter'
=> [
118
'=CATALOG_GROUP_ID'
=>
$fields
[
'CATALOG_GROUP_ID'
],
119
'=GROUP_ID'
=>
$fields
[
'GROUP_ID'
],
120
'=ACCESS'
=>
$fields
[
'ACCESS'
],
121
]
122
]);
123
124
if
($exists)
125
{
126
$result
->addError(
new
Error(
'The specified access type for this group already exists'
));
127
}
128
129
return
$result
;
130
}
131
135
protected
function
getEntityTable
()
136
{
137
return
GroupAccessTable::class;
138
}
139
}
Bitrix\Catalog\Controller\Controller\getServiceItemName
getServiceItemName()
Определения
controller.php:139
Bitrix\Catalog\Controller\Controller\getViewFields
getViewFields()
Определения
controller.php:107
Bitrix\Catalog\Controller\PriceTypeGroup
Определения
pricetypegroup.php:11
Bitrix\Catalog\Controller\PriceTypeGroup\addAction
addAction(array $fields)
Определения
pricetypegroup.php:29
Bitrix\Catalog\Controller\PriceTypeGroup\getEntityTable
getEntityTable()
Определения
pricetypegroup.php:135
Bitrix\Catalog\Controller\PriceTypeGroup\getFieldsAction
getFieldsAction()
Определения
pricetypegroup.php:20
Bitrix\Catalog\Controller\PriceTypeGroup\deleteAction
deleteAction(int $id)
Определения
pricetypegroup.php:59
Bitrix\Catalog\GroupAccessTable\ACCESS_BUY
const ACCESS_BUY
Определения
groupaccess.php:38
Bitrix\Catalog\GroupAccessTable\ACCESS_VIEW
const ACCESS_VIEW
Определения
groupaccess.php:39
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\ORM\Data\DataManager\getRow
static getRow(array $parameters)
Определения
datamanager.php:398
Bitrix\Main\ORM\Data\DataManager\getById
static getById($id)
Определения
datamanager.php:364
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Определения
datamanager.php:1644
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Определения
datamanager.php:877
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$access
if(!is_array($deviceNotifyCodes)) $access
Определения
options.php:174
Bitrix\Catalog\Controller
Bitrix\Catalog\Controller\exists
exists($id)
Определения
checkexists.php:30
Bitrix\Catalog\Controller\ListAction
trait ListAction
Определения
listaction.php:9
Bitrix\Sale\Discount\Result
Определения
compatibleformat.php:2
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
catalog
lib
controller
pricetypegroup.php
Создано системой
1.14.0