Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
storeselector.php
1<?php
2
4
13
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}
static getList(array $parameters=array())