Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
config.php
1
<?php
2
namespace
Bitrix\Catalog\Controller
;
3
4
use
Bitrix\Catalog\Access\AccessController
;
5
use
Bitrix\Catalog\Access\ActionDictionary
;
6
use
Bitrix\Catalog\Component\PresetHandler
;
7
use
Bitrix\Catalog\Component\UseStore
;
8
use
Bitrix\Catalog\Product\Store\CostPriceCalculator
;
9
use
Bitrix\Main\Engine\Action
;
10
use
Bitrix\Main\Error
;
11
use
Bitrix\Main\Localization\Loc
;
12
use
Bitrix\Main\NotImplementedException
;
13
use
Bitrix\Main\Result
;
14
use
Bitrix\Main\SystemException
;
15
16
final
class
Config
extends
\Bitrix\Main\Engine\Controller
17
{
18
public
const
QUANTITY_INCONSISTENCY_EXISTS
=
'QUANTITY_INCONSISTENCY_EXISTS'
;
19
public
const
CONDUCTED_DOCUMENTS_EXIST
=
'CONDUCTED_DOCUMENTS_EXIST'
;
20
27
protected
function
processBeforeAction
(
Action
$action): ?bool
28
{
29
$r = $this->
checkPermission
($action->
getName
(), $action->
getArguments
());
30
if
($r->isSuccess())
31
{
32
//do nothing
33
}
34
else
35
{
36
$this->
addErrors
($r->getErrors());
37
return
null
;
38
}
39
40
return
parent::processBeforeAction($action);
41
}
42
46
protected
function
checkPermission
($name, $arguments = [])
47
{
48
$name = strtolower($name);
49
50
if
(
51
$name === strtolower(
'onceInventoryManagementY'
)
52
|| $name === strtolower(
'onceInventoryManagementN'
)
53
|| $name === strtolower(
'inventoryManagementN'
)
54
|| $name === strtolower(
'inventoryManagementY'
)
55
|| $name === strtolower(
'inventoryManagementYAndResetQuantity'
)
56
|| $name === strtolower(
'inventoryManagementYAndResetQuantityWithDocuments'
)
57
|| $name === strtolower(
'unRegisterOnProlog'
)
58
)
59
{
60
$r = $this->
checkModifyPermissionEntity
($name, $arguments);
61
}
62
else
if
(
63
$name === strtolower(
'isUsedInventoryManagement'
)
64
|| $name === strtolower(
'conductedDocumentsExist'
)
65
|| $name === strtolower(
'checkEnablingConditions'
)
66
)
67
{
68
$r = $this->
checkReadPermissionEntity
($name, $arguments);
69
}
70
else
71
{
72
$r = $this->
checkPermissionEntity
($name, $arguments);
73
}
74
75
return
$r;
76
}
77
83
protected
function
checkReadPermissionEntity
($name, $arguments = [])
84
{
85
$r =
new
Result
();
86
if
(!AccessController::getCurrent()->check(ActionDictionary::ACTION_CATALOG_READ))
87
{
88
$r->addError(
new
Error
(
'Access denied!'
, 200040300010));
89
}
90
return
$r;
91
}
92
93
protected
function
checkModifyPermissionEntity
($name, $arguments = []):
Result
94
{
95
$r =
new
Result
();
96
if
(!AccessController::getCurrent()->check(ActionDictionary::ACTION_STORE_VIEW))
97
{
98
$r->addError(
new
Error
(
'Access denied!'
, 200040300011));
99
}
100
return
$r;
101
}
102
108
protected
function
checkPermissionEntity
($name, $arguments = [])
109
{
110
throw
new
NotImplementedException
(
'Check permission entity. The method '
.$name.
' is not implemented.'
);
111
}
112
113
public
function
onceInventoryManagementYAction
(): bool
114
{
115
return
UseStore::enableOnec();
116
}
117
118
public
function
onceInventoryManagementNAction
(): bool
119
{
120
return
UseStore::disableOnec();
121
}
122
123
public
function
isUsedInventoryManagementAction
(): bool
124
{
125
return
UseStore::isUsed();
126
}
127
128
public
function
inventoryManagementNAction
(): void
129
{
130
if
(!UseStore::disable())
131
{
132
$this->addInventoryManagementDisableError();
133
}
134
}
135
136
public
function
inventoryManagementYAndResetQuantityWithDocumentsAction
(
string
$costPriceCalculationMethod): void
137
{
138
if
(
139
UseStore::isPlanRestricted()
140
|| !UseStore::enable()
141
)
142
{
143
$this->addInventoryManagementEnableError();
144
145
return
;
146
}
147
148
CostPriceCalculator::setMethod($costPriceCalculationMethod);
149
150
UseStore::resetDocuments();
151
}
152
153
public
function
inventoryManagementYAndResetQuantityAction
(): void
154
{
155
if
(
156
UseStore::isPlanRestricted()
157
|| !UseStore::enable()
158
)
159
{
160
$this->addInventoryManagementEnableError();
161
}
162
}
163
164
public
function
inventoryManagementYAction
(
string
$costPriceCalculationMethod): void
165
{
166
if
(
167
UseStore::isPlanRestricted()
168
|| !UseStore::enableWithoutResetting()
169
)
170
{
171
$this->addInventoryManagementEnableError();
172
}
173
174
CostPriceCalculator::setMethod($costPriceCalculationMethod);
175
}
176
177
public
function
unRegisterOnPrologAction
(): bool
178
{
179
return
PresetHandler::unRegister();
180
}
181
182
public
function
conductedDocumentsExistAction
(): bool
183
{
184
return
UseStore::conductedDocumentsExist();
185
}
186
187
public
function
checkEnablingConditionsAction
(): array
188
{
189
$result = [];
190
191
if
(UseStore::doNonEmptyProductsExist())
192
{
193
$result[] = self::QUANTITY_INCONSISTENCY_EXISTS;
194
}
195
196
if
(UseStore::conductedDocumentsExist())
197
{
198
$result[] = self::CONDUCTED_DOCUMENTS_EXIST;
199
}
200
201
return
$result;
202
}
203
204
private
function
addInventoryManagementEnableError(): void
205
{
206
$this->addError(
207
new
Error
(
208
Loc::getMessage
(
'CATALOG_CONTROLLER_CONFIG_INVENTORY_MANAGEMENT_ENABLE_DEFAULT_ERROR'
)
209
)
210
);
211
}
212
213
private
function
addInventoryManagementDisableError(): void
214
{
215
$this->addError(
216
new
Error
(
217
Loc::getMessage
(
'CATALOG_CONTROLLER_CONFIG_INVENTORY_MANAGEMENT_DISABLE_DEFAULT_ERROR'
)
218
)
219
);
220
}
221
}
Bitrix\Catalog\Access\AccessController
Definition
AccessController.php:28
Bitrix\Catalog\Access\ActionDictionary
Definition
ActionDictionary.php:17
Bitrix\Catalog\Component\PresetHandler
Definition
presethandler.php:6
Bitrix\Catalog\Component\UseStore
Definition
usestore.php:22
Bitrix\Catalog\Controller\Config\conductedDocumentsExistAction
conductedDocumentsExistAction()
Definition
config.php:182
Bitrix\Catalog\Controller\Config\onceInventoryManagementYAction
onceInventoryManagementYAction()
Definition
config.php:113
Bitrix\Catalog\Controller\Config\inventoryManagementYAction
inventoryManagementYAction(string $costPriceCalculationMethod)
Definition
config.php:164
Bitrix\Catalog\Controller\Config\inventoryManagementYAndResetQuantityAction
inventoryManagementYAndResetQuantityAction()
Definition
config.php:153
Bitrix\Catalog\Controller\Config\CONDUCTED_DOCUMENTS_EXIST
const CONDUCTED_DOCUMENTS_EXIST
Definition
config.php:19
Bitrix\Catalog\Controller\Config\inventoryManagementYAndResetQuantityWithDocumentsAction
inventoryManagementYAndResetQuantityWithDocumentsAction(string $costPriceCalculationMethod)
Definition
config.php:136
Bitrix\Catalog\Controller\Config\inventoryManagementNAction
inventoryManagementNAction()
Definition
config.php:128
Bitrix\Catalog\Controller\Config\processBeforeAction
processBeforeAction(Action $action)
Definition
config.php:27
Bitrix\Catalog\Controller\Config\checkModifyPermissionEntity
checkModifyPermissionEntity($name, $arguments=[])
Definition
config.php:93
Bitrix\Catalog\Controller\Config\checkEnablingConditionsAction
checkEnablingConditionsAction()
Definition
config.php:187
Bitrix\Catalog\Controller\Config\isUsedInventoryManagementAction
isUsedInventoryManagementAction()
Definition
config.php:123
Bitrix\Catalog\Controller\Config\unRegisterOnPrologAction
unRegisterOnPrologAction()
Definition
config.php:177
Bitrix\Catalog\Controller\Config\checkPermission
checkPermission($name, $arguments=[])
Definition
config.php:46
Bitrix\Catalog\Controller\Config\QUANTITY_INCONSISTENCY_EXISTS
const QUANTITY_INCONSISTENCY_EXISTS
Definition
config.php:18
Bitrix\Catalog\Controller\Config\checkReadPermissionEntity
checkReadPermissionEntity($name, $arguments=[])
Definition
config.php:83
Bitrix\Catalog\Controller\Config\checkPermissionEntity
checkPermissionEntity($name, $arguments=[])
Definition
config.php:108
Bitrix\Catalog\Controller\Config\onceInventoryManagementNAction
onceInventoryManagementNAction()
Definition
config.php:118
Bitrix\Catalog\Product\Store\CostPriceCalculator
Definition
costpricecalculator.php:19
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Engine\Action
Definition
action.php:17
Bitrix\Main\Engine\Action\getArguments
getArguments()
Definition
action.php:62
Bitrix\Main\Engine\Action\getName
getName()
Definition
action.php:146
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Engine\Controller\addErrors
addErrors(array $errors)
Definition
controller.php:1064
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\NotImplementedException
Definition
exception.php:147
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Catalog\Controller
Bitrix\Main\Config
Definition
configuration.php:2
modules
catalog
lib
controller
config.php
Создано системой
1.10.0