Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
shopbuilder.php
1<?php
2namespace Bitrix\Catalog\Url;
3
10
11class ShopBuilder extends AdminPage\CatalogBuilder
12{
13 public const TYPE_ID = 'SHOP';
14
15 public const OPEN_SETTINGS_PARAM = 'open_settings_page';
16
17 public const PAGE_CSV_IMPORT = 'csvImport';
18
19 protected const TYPE_WEIGHT = 300;
20
21 protected const PATH_PREFIX = '/shop/settings/';
22
23 protected const PATH_DETAIL_CARD_PREFIX = '/shop/catalog/';
24
25 public function __construct()
26 {
27 parent::__construct();
28 }
29
35 public function use(): bool
36 {
37 if (defined('CATALOG_PRODUCT') && defined('SELF_FOLDER_URL'))
38 {
39 return true;
40 }
41 if (!$this->request->isAdminSection())
42 {
43 if ($this->checkCurrentPage([
44 self::PATH_PREFIX,
45 self::PATH_DETAIL_CARD_PREFIX
46 ]))
47 {
48 return true;
49 }
50 }
51
52 return false;
53 }
54
63 public function getContextMenuItems(string $pageType, array $items = [], array $options = []): ?array
64 {
65 if ($pageType !== self::PAGE_ELEMENT_LIST && $pageType !== self::PAGE_SECTION_LIST)
66 {
67 return null;
68 }
69
70 if (!Loader::includeModule('crm'))
71 {
72 return null;
73 }
74
75 $result = [];
76
77 if (AccessController::getCurrent()->check(ActionDictionary::ACTION_CATALOG_SETTINGS_ACCESS))
78 {
79 if (!\CCrmSaleHelper::isWithOrdersMode())
80 {
81 Extension::load(['crm.config.catalog']);
82
83 $result[] = [
84 'TEXT' => Loc::getMessage('CATALOG_SHOP_BUILDER_CONTEXT_MENU_ITEM_INVENTORY_MANAGEMENT_SETTINGS'),
85 'TITLE' => Loc::getMessage('CATALOG_SHOP_BUILDER_CONTEXT_MENU_ITEM_INVENTORY_MANAGEMENT_SETTINGS'),
86 'ONCLICK' => 'BX.Crm.Config.Catalog.Slider.open(\'shop\')',
87 ];
88 }
89 }
90
91 if (Catalog\Config\Feature::isAccessControllerCheckingEnabled())
92 {
93 Extension::load('sidepanel');
94
95 $result[] = [
96 'TEXT' => Loc::getMessage('CATALOG_SHOP_BUILDER_CONTEXT_MENU_ITEM_ACCESS_RIGHTS'),
97 'TITLE' => Loc::getMessage('CATALOG_SHOP_BUILDER_CONTEXT_MENU_ITEM_ACCESS_RIGHTS'),
98 'ONCLICK' => "BX.SidePanel.Instance.open('" . \CUtil::JSEscape('/shop/settings/permissions/') . "')"
99 ];
100 }
101 else
102 {
103 $helpLink = Catalog\Config\Feature::getAccessControllerHelpLink();
104 if (!empty($helpLink))
105 {
106 Catalog\Config\Feature::initUiHelpScope();
107 $result[] = [
108 'TEXT' => Loc::getMessage('CATALOG_SHOP_BUILDER_CONTEXT_MENU_ITEM_ACCESS_RIGHTS'),
109 'TITLE' => Loc::getMessage('CATALOG_SHOP_BUILDER_CONTEXT_MENU_ITEM_ACCESS_RIGHTS'),
110 $helpLink['TYPE'] => $helpLink['LINK'],
111 ];
112 }
113 unset($helpLink);
114 }
115
116 $result[] = [
117 'TEXT' => Loc::getMessage('CATALOG_SHOP_BUILDER_CONTEXT_MENU_ITEM_SEO'),
118 'TITLE' => Loc::getMessage('CATALOG_SHOP_BUILDER_CONTEXT_MENU_ITEM_SEO'),
119 'ONCLICK' => "BX.SidePanel.Instance.open('"
120 . \CUtil::JSEscape($this->getCatalogSeoUrl())
121 . "', {cacheable: false, allowChangeHistory: false, width: 1000})"
122 ,
123 ];
124
125 if (!empty($items))
126 {
127 $result = array_merge($result, $items);
128 }
129
130 return (!empty($result) ? $result: null);
131 }
132
138 protected function initConfig(): void
139 {
140 parent::initConfig();
141 $this->config['UI_CATALOG'] = Catalog\Config\State::isProductCardSliderEnabled();
142 }
143
149 protected function isUiCatalog(): bool
150 {
151 return (isset($this->config['UI_CATALOG']) && $this->config['UI_CATALOG']);
152 }
153
154 public function getDetailPageSlider(): string
155 {
156 $path = $this->getSliderPath();
157 if (!$this->checkSliderPath($path))
158 {
159 return '';
160 }
161 $path = \CUtil::JSEscape($path);
162
163 $listUrl = \CUtil::JSEscape($this->getElementListUrl(0));
164
165 return<<<HTML
166 <script>
167 window.history.replaceState({}, '', '$path');
168 BX.Event.ready(function(){
169 BX.SidePanel.Instance.open(
170 '$path',
171 {
172 events: {
173 onCloseComplete: function(event) {
174 window.location = '$listUrl';
175 }
176 }
177 }
178 );
179 });
180 </script>
181 HTML
182 ;
183 }
184
190 protected function initUrlTemplates(): void
191 {
192 $this->urlTemplates[self::PAGE_SECTION_LIST] =
193 '/shop/catalog/#IBLOCK_ID#/section/#PARENT_ID#/'
194 . '?#ADDITIONAL_PARAMETERS#'
195 ;
196 $this->urlTemplates[self::PAGE_ELEMENT_LIST] =
197 '/shop/catalog/#IBLOCK_ID#/'
198 ;
199
200 $this->urlTemplates[self::PAGE_SECTION_DETAIL] =
201 '#PATH_PREFIX#'
202 . 'cat_section_edit/'
203 . '?#BASE_PARAMS#'
204 . '&ID=#ENTITY_ID#'
205 . '&publicSidePanel=Y'
206 . '#ADDITIONAL_PARAMETERS#'
207 ;
208 $this->urlTemplates[self::PAGE_SECTION_COPY] =
209 $this->urlTemplates[self::PAGE_SECTION_DETAIL]
210 . $this->getCopyAction()
211 ;
212 $this->urlTemplates[self::PAGE_SECTION_SAVE] =
213 '#PATH_PREFIX#'
214 . 'cat_section_edit.php'
215 . '?#BASE_PARAMS#'
216 . '#ADDITIONAL_PARAMETERS#'
217 ;
218 $this->urlTemplates[self::PAGE_SECTION_SEARCH] =
219 '/bitrix/tools/iblock/section_search.php'
220 . '?#LANGUAGE#'
221 . '#ADDITIONAL_PARAMETERS#'
222 ;
223
224 if ($this->isUiCatalog())
225 {
226 $this->urlTemplates[self::PAGE_ELEMENT_DETAIL] =
227 self::PATH_DETAIL_CARD_PREFIX
228 . '#IBLOCK_ID#/product/#ENTITY_ID#/'
229 . '?#ADDITIONAL_PARAMETERS#'
230 ;
231 $this->urlTemplates[self::PAGE_ELEMENT_COPY] =
232 self::PATH_DETAIL_CARD_PREFIX
233 . '#IBLOCK_ID#/product/0/copy/#ENTITY_ID#/'
234 ;
235 $this->urlTemplates[self::PAGE_ELEMENT_SAVE] = $this->urlTemplates[self::PAGE_ELEMENT_DETAIL];
236 $this->urlTemplates[self::PAGE_OFFER_DETAIL] =
237 '/shop/catalog/'
238 . '#PRODUCT_IBLOCK_ID#/product/#PRODUCT_ID#/'
239 . 'variation/#ENTITY_ID#/'
240 ;
241 }
242 else
243 {
244 $this->urlTemplates[self::PAGE_ELEMENT_DETAIL] =
245 '#PATH_PREFIX#'
246 . 'cat_product_edit/'
247 . '?#BASE_PARAMS#'
248 . '&ID=#ENTITY_ID#'
249 . '&publicSidePanel=Y'
250 . '#ADDITIONAL_PARAMETERS#'
251 ;
252 $this->urlTemplates[self::PAGE_ELEMENT_COPY] =
253 $this->urlTemplates[self::PAGE_ELEMENT_DETAIL]
254 . $this->getCopyAction()
255 ;
256 $this->urlTemplates[self::PAGE_ELEMENT_SAVE] =
257 '#PATH_PREFIX#'
258 . 'cat_product_edit.php'
259 . '?#BASE_PARAMS#'
260 . '#ADDITIONAL_PARAMETERS#'
261 ;
262 $this->urlTemplates[self::PAGE_OFFER_DETAIL] = $this->urlTemplates[self::PAGE_ELEMENT_DETAIL];
263 }
264 $this->urlTemplates[self::PAGE_ELEMENT_SEARCH] =
265 '/bitrix/tools/iblock/element_search.php'
266 . '?#LANGUAGE#'
267 . '#ADDITIONAL_PARAMETERS#'
268 ;
269 $this->urlTemplates[self::PAGE_CATALOG_SEO] = self::PATH_DETAIL_CARD_PREFIX . '#IBLOCK_ID#/seo/';
270 $this->urlTemplates[self::PAGE_ELEMENT_SEO] = self::PATH_DETAIL_CARD_PREFIX . '#IBLOCK_ID#/seo/product/#PRODUCT_ID#/';
271 $this->urlTemplates[self::PAGE_SECTION_SEO] = self::PATH_DETAIL_CARD_PREFIX . '#IBLOCK_ID#/seo/section/#SECTION_ID#/';
272 }
273
279 protected function getSliderPathTemplates(): array
280 {
281 return [
282 '/^\/shop\/catalog\/[0-9]+\/product\/[0-9]+\/$/',
283 '/^\/shop\/catalog\/[0-9]+\/product\/[0-9]+\/variation\/[0-9]+\/$/',
284 ];
285 }
286
287 public function openSettingsPage(): void
288 {
289 if
290 (
291 $this->request->get('open_settings_page')
292 && (int)$this->request->get('open_settings_page') === 1
293 )
294 {
295 echo $this->getSettingsSlider();
296 }
297 }
298
299 protected function getSettingsSlider(): string
300 {
301 \Bitrix\Main\UI\Extension::load(['crm.config.catalog']);
302
303 return '<script>'
304 . 'BX.ready(function() {' . "\n"
305 . ' BX.Crm.Config.Catalog.Slider.open(\'shop\');' . "\n"
306 . '});' . "\n"
307 . '</script>'
308 ;
309 }
310
311 public function subscribeOnAfterSettingsSave(): void
312 {
313 $saveEventName = static::getOnSaveEventName();
314
315 if ($saveEventName !== '')
316 {
317 $saveEventName = \CUtil::JSEscape($saveEventName);
318
319 echo '<script>'
320 . 'BX.addCustomEvent(\'' . $saveEventName . '\', function() {' . "\n"
321 . ' var href = window.top.location.href;' . "\n"
322 . ' window.top.location.replace(href.replace(/' . \CUtil::JSEscape(static::OPEN_SETTINGS_PARAM) . '.*&?/, \'\'));' . "\n"
323 . '});' . "\n"
324 . '</script>'
325 ;
326 }
327 }
328
329 protected static function getOnSaveEventName(): string
330 {
331 return 'onCatalogSettingsSave';
332 }
333}
getContextMenuItems(string $pageType, array $items=[], array $options=[])
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29