1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
landing.php
См. документацию.
1<?php
2
4
8
9Loc::loadMessages(__FILE__);
10
18{
19 public const TRADING_PLATFORM_CODE = 'landing';
20 public const CODE_DELIMITER = '_';
21
22 public const LANDING_STORE_CLOTHES = 'clothes';
23 public const LANDING_STORE_INSTAGRAM = 'instagram';
24 public const LANDING_STORE_CHATS = 'chats';
25 public const LANDING_STORE_MINI_ONE_ELEMENT = 'mini-one-element';
26 public const LANDING_STORE_MINI_CATALOG = 'mini-catalog';
27 public const LANDING_STORE_STORE_V3 = 'store_v3';
28
29 protected static $stores = [
30 self::LANDING_STORE_CLOTHES,
31 self::LANDING_STORE_INSTAGRAM,
32 self::LANDING_STORE_CHATS,
33 self::LANDING_STORE_MINI_ONE_ELEMENT,
34 self::LANDING_STORE_MINI_CATALOG,
35 self::LANDING_STORE_STORE_V3,
36 ];
37
38 protected $site = [];
39
43 public function install()
44 {
45 $data = $this->getInfo();
46
47 $result = Sale\TradingPlatformTable::add([
48 "CODE" => $this->getCode(),
49 "ACTIVE" => "Y",
50 "NAME" => Loc::getMessage('SALE_LANDING_NAME', ['#NAME#' => $data['TITLE']]),
51 "DESCRIPTION" => '',
52 "CLASS" => '\\'.static::class,
53 "XML_ID" => static::generateXmlId(),
54 ]);
55
56 if ($result->isSuccess())
57 {
58 $this->isInstalled = true;
59 $this->id = $result->getId();
60 }
61
62 return $result->isSuccess();
63 }
64
68 protected static function generateXmlId()
69 {
70 return uniqid('bx_');
71 }
72
76 protected function getSiteId()
77 {
78 return (int)mb_substr($this->getCode(), mb_strrpos($this->getCode(), '_') + 1);
79 }
80
84 public static function setShipmentTableOnAfterUpdateEvent()
85 {
86 return;
87 }
88
92 protected static function unSetShipmentTableOnAfterUpdateEvent()
93 {
94 return;
95 }
96
100 protected function setCatalogSectionsTabEvent()
101 {
102 return;
103 }
104
108 protected function unSetCatalogSectionsTabEvent()
109 {
110 return;
111 }
112
116 public static function onLandingSiteAdd(Main\Event $event)
117 {
118 $fields = $event->getParameter('fields');
119 if ($fields['TYPE'] !== 'STORE')
120 {
121 return;
122 }
123
124 $primary = $event->getParameter('primary');
125 $landing = Landing::getInstanceByCode(static::getCodeBySiteId($primary['ID']));
126 if (!$landing->isInstalled())
127 {
128 $landing->install();
129 }
130 }
131
132 public static function onLandingSiteUpdate(Main\Event $event)
133 {
134 $fields = $event->getParameter('fields');
135 if (empty($fields['TYPE']) || $fields['TYPE'] !== 'STORE')
136 {
137 return;
138 }
139
140 $primary = $event->getParameter('primary');
141 $landing = Landing::getInstanceByCode(static::getCodeBySiteId($primary['ID']));
142 if ($landing->isInstalled())
143 {
144 Sale\TradingPlatformTable::update(
145 $landing->getId(),
146 [
147 'NAME' => Loc::getMessage('SALE_LANDING_NAME', ['#NAME#' => $fields['TITLE']]),
148 ]
149 );
150 }
151 }
152
156 public static function onLandingSiteDelete(Main\Event $event)
157 {
158 $primary = $event->getParameter('primary');
159
160 $landing = Landing::getInstanceByCode(static::getCodeBySiteId($primary['ID']));
161 if ($landing->isInstalled())
162 {
164
166 $tradeBindingCollection = $registry->get(Sale\Registry::ENTITY_TRADE_BINDING_COLLECTION);
167
168 $dbRes = $tradeBindingCollection::getList([
169 'select' => ['ID'],
170 'filter' => [
171 '=TRADING_PLATFORM_ID' => $landing->getId()
172 ]
173 ]);
174
175 if ($dbRes->fetch())
176 {
177 $landing->unsetActive();
178 }
179 else
180 {
181 $landing->uninstall();
182 }
183 }
184 }
185
190 {
191 $id = $event->getParameter('id');
192 $delete = $event->getParameter('delete');
193
194 $res = \Bitrix\Landing\Site::getList([
195 'select' => [
196 'ID'
197 ],
198 'filter' => [
199 '=ID' => $id,
200 'CHECK_PERMISSIONS' => 'N',
201 '=TYPE' => 'STORE'
202 ]
203 ]);
204
205 if (!$res->fetch())
206 {
207 return;
208 }
209
210 $landing = Landing::getInstanceByCode(static::getCodeBySiteId($id));
211 if (!$landing || !$landing->isInstalled())
212 {
213 return;
214 }
215
216 if ($delete)
217 {
218 $landing->unsetActive();
219 }
220 else
221 {
222 $landing->setActive();
223 }
224 }
225
230 public static function getCodeBySiteId($id)
231 {
232 return static::TRADING_PLATFORM_CODE.static::CODE_DELIMITER.$id;
233 }
234
238 public function getInfo()
239 {
240 if (!Main\Loader::includeModule('landing'))
241 {
242 return [];
243 }
244
245 if ($this->site)
246 {
247 return $this->site;
248 }
249
251 $dbRes = \Bitrix\Landing\Site::getList([
252 'filter' => [
253 '=ID' => $this->getSiteId(),
254 'CHECK_PERMISSIONS' => 'N',
255 '=DELETED' => ['Y', 'N'],
256 ]
257 ]);
258
259 if ($data = $dbRes->fetch())
260 {
261 $this->site = $data;
262 $this->site['PUBLIC_URL'] = \Bitrix\Landing\Site::getPublicUrl($this->getSiteId());
263 }
264
265 return $this->site;
266 }
267
268 public function getAnalyticCode()
269 {
270 $data = $this->getInfo();
271 if (!isset($data['XML_ID']) || !$data['XML_ID'])
272 {
273 return parent::getAnalyticCode();
274 }
275
276 foreach (static::$stores as $store)
277 {
278 if (mb_strpos($data['XML_ID'], $store) !== false)
279 {
280 return $store;
281 }
282 }
283
284 return $data['XML_ID'];
285 }
286
293 public function getExternalLink($type, Sale\Order $order)
294 {
295 if ($type === static::LINK_TYPE_PUBLIC_DETAIL_ORDER)
296 {
297 return $this->getLandingSysPageUrl(
298 'personal',
299 [
300 'SECTION' => 'orders',
301 'ID' => $order->getId()
302 ]
303 );
304 }
305
306 if ($type === static::LINK_TYPE_PUBLIC_FEEDBACK)
307 {
308 return $this->getLandingSysPageUrl('feedback');
309 }
310
311 throw new Main\ArgumentException("Unsupported link type: {$type}");
312 }
313
319 private function getLandingSysPageUrl(string $type, array $additional = []): string
320 {
321 if (!Main\Loader::includeModule('landing'))
322 {
323 return '';
324 }
325
326 return \Bitrix\Landing\Syspage::getSpecialPage($this->getSiteId(), $type, $additional);
327 }
328
332 public function getRealName()
333 {
334 return (string)($this->getInfo()['TITLE'] ?? '');
335 }
336
341 public function isOfType(string $type): bool
342 {
343 $info = $this->getInfo();
344 if (!isset($info['XML_ID']))
345 {
346 return false;
347 }
348
349 return mb_strpos($info['XML_ID'], $type) !== false;
350 }
351}
$type
Определения options.php:106
const ENTITY_TRADE_BINDING_COLLECTION
Определения registry.php:55
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
static onLandingSiteUpdate(Main\Event $event)
Определения landing.php:132
static unSetShipmentTableOnAfterUpdateEvent()
Определения landing.php:92
getExternalLink($type, Sale\Order $order)
Определения landing.php:293
static onLandingBeforeSiteRecycle(Main\Event $event)
Определения landing.php:189
static getCodeBySiteId($id)
Определения landing.php:230
isOfType(string $type)
Определения landing.php:341
const LANDING_STORE_MINI_ONE_ELEMENT
Определения landing.php:25
static onLandingSiteAdd(Main\Event $event)
Определения landing.php:116
static setShipmentTableOnAfterUpdateEvent()
Определения landing.php:84
static getInstanceByCode($code)
Определения platform.php:79
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
Определения buffer.php:3
$order
Определения payment.php:8
$event
Определения prolog_after.php:141
$dbRes
Определения yandex_detail.php:168
$site
Определения yandex_run.php:614