Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
storeselector.php
1
<?php
2
3
namespace
Bitrix\Catalog\Controller
;
4
5
use
Bitrix\Catalog\Access\AccessController
;
6
use
Bitrix\Catalog\Access\ActionDictionary
;
7
use
Bitrix\Catalog\StoreProductTable
;
8
use
Bitrix\Catalog\StoreTable
;
9
use
Bitrix\Main\Engine\Action
;
10
use
Bitrix\Main\Engine\ActionFilter
;
11
use
Bitrix\Main\Engine\JsonController
;
12
use
Bitrix\Main\Error
;
13
14
class
StoreSelector
extends
JsonController
15
{
16
private
AccessController
$accessController;
17
21
protected
function
init
()
22
{
23
parent::init();
24
25
$this->accessController = AccessController::getCurrent();
26
}
27
28
protected
function
getDefaultPreFilters
()
29
{
30
return
array_merge(
31
parent::getDefaultPreFilters(),
32
[
33
new
ActionFilter\
HttpMethod
([ActionFilter\
HttpMethod::METHOD_POST
]),
34
new
ActionFilter\
Scope
(ActionFilter\
Scope::AJAX
),
35
]
36
);
37
}
38
39
protected
function
processBeforeAction
(
Action
$action)
40
{
41
if
(
42
$this->accessController->check(ActionDictionary::ACTION_CATALOG_READ)
43
|| $this->accessController->check(ActionDictionary::ACTION_CATALOG_VIEW)
44
)
45
{
46
return
parent::processBeforeAction($action);
47
}
48
49
$this->
addError
(
new
Error
(
'Access denied'
));
50
51
return
false
;
52
}
53
59
public
function
getProductStoresAction
(
int
$productId): array
60
{
61
$iterator = \CIBlockElement::GetList(
62
[],
63
[
64
'ID'
=> $productId,
65
'ACTIVE'
=>
'Y'
,
66
'ACTIVE_DATE'
=>
'Y'
,
67
'CHECK_PERMISSIONS'
=>
'Y'
,
68
'MIN_PERMISSION'
=>
'R'
,
69
],
70
false
,
71
false
,
72
[
'ID'
,
'IBLOCK_ID'
,
'TYPE'
]
73
);
74
$element = $iterator->Fetch();
75
if
(!$element)
76
{
77
return
[];
78
}
79
80
$filter = [
81
'=PRODUCT_ID'
=> $productId,
82
];
83
84
$accessFilter = $this->accessController->getEntityFilter(
85
ActionDictionary::ACTION_STORE_VIEW,
86
StoreProductTable::class
87
);
88
if
($accessFilter)
89
{
90
$filter[] = $accessFilter;
91
}
92
93
$storeAmounts =
StoreProductTable::getList
([
94
'filter'
=> $filter,
95
'select'
=> [
96
'AMOUNT'
,
97
'QUANTITY_RESERVED'
,
98
'STORE_ID'
,
99
'STORE_TITLE'
=>
'STORE.TITLE'
100
]
101
]);
102
103
return
$storeAmounts->fetchAll();
104
}
105
106
public
function
createStoreAction
(
string
$name): ?array
107
{
108
if
(!$this->accessController->check(ActionDictionary::ACTION_STORE_MODIFY))
109
{
110
$this->
addError
(
new
Error
(
'Access denied'
));
111
return
null
;
112
}
113
114
$result = StoreTable::add([
115
'TITLE'
=> $name,
116
'ADDRESS'
=> $name,
117
]);
118
119
if
(!$result->isSuccess())
120
{
121
$this->
addErrors
($result->getErrors());
122
123
return
[];
124
}
125
126
return
[
127
'id'
=> $result->getId(),
128
];
129
}
130
}
Bitrix\Catalog\Access\AccessController
Definition
AccessController.php:28
Bitrix\Catalog\Access\ActionDictionary
Definition
ActionDictionary.php:17
Bitrix\Catalog\Controller\StoreSelector
Definition
storeselector.php:15
Bitrix\Catalog\Controller\StoreSelector\createStoreAction
createStoreAction(string $name)
Definition
storeselector.php:106
Bitrix\Catalog\Controller\StoreSelector\getDefaultPreFilters
getDefaultPreFilters()
Definition
storeselector.php:28
Bitrix\Catalog\Controller\StoreSelector\init
init()
Definition
storeselector.php:21
Bitrix\Catalog\Controller\StoreSelector\processBeforeAction
processBeforeAction(Action $action)
Definition
storeselector.php:39
Bitrix\Catalog\Controller\StoreSelector\getProductStoresAction
getProductStoresAction(int $productId)
Definition
storeselector.php:59
Bitrix\Catalog\StoreProductTable
Definition
storeproduct.php:39
Bitrix\Catalog\StoreTable
Definition
store.php:55
Bitrix\Main\Engine\ActionFilter\HttpMethod
Definition
httpmethod.php:13
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_POST
const METHOD_POST
Definition
httpmethod.php:15
Bitrix\Main\Engine\ActionFilter\Scope
Definition
scope.php:12
Bitrix\Main\Engine\ActionFilter\Scope\AJAX
const AJAX
Definition
scope.php:13
Bitrix\Main\Engine\Action
Definition
action.php:17
Bitrix\Main\Engine\Controller\addError
addError(Error $error)
Definition
controller.php:1051
Bitrix\Main\Engine\Controller\addErrors
addErrors(array $errors)
Definition
controller.php:1064
Bitrix\Main\Engine\JsonController
Definition
jsoncontroller.php:9
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Catalog\Controller
Bitrix\Main\Engine\ActionFilter
Definition
authentication.php:4
modules
catalog
lib
controller
storeselector.php
Создано системой
1.10.0