23 private const ONLY_CODES = [
29 private const FOOTER_LINKS_MAP = [
30 'store-chats-dark/about' =>
'#landing1',
31 'store-chats-dark/contacts' =>
'#landing2',
32 'store-chats-dark/cutaway' =>
'#landing3',
33 'store-chats-dark/payinfo' =>
'#landing8',
34 'store-chats-dark/webform' =>
'#landing9',
36 private const FOOTER_BLOCK_CODE =
'55.1.list_of_links';
43 private static function createFolder(
int $siteId): ?
int
45 $catalogFolderId =
null;
47 $folders = Site::getFolders(
$siteId);
48 $translitCode = \CUtil::translit(
49 Loc::getMessage(
'LANDING_DEMO_STORE_CHATS_CATALOG-NAME'),
52 'replace_space' =>
'',
56 foreach ($folders as $folder)
59 $folder[
'CODE'] ===
'catalog'
60 || $folder[
'CODE'] ===
'katalog'
61 || $folder[
'CODE'] === $translitCode
64 $catalogFolderId = $folder[
'ID'];
68 if (!$catalogFolderId)
71 'TITLE' => Loc::getMessage(
'LANDING_SITE_UPDATE_CHAT_SALE_FOLDER_NAME'),
74 if (!
$res->isSuccess())
78 $catalogFolderId =
$res->getId();
81 return $catalogFolderId;
91 private static function createPageIfNotExists(
int $siteId,
int $catalogFolderId,
string $code): ?
int
101 '=TPL_CODE' =>
$code,
102 'CHECK_PERMISSIONS' =>
'N',
105 if ($row =
$res->fetch())
113 'FOLDER_ID' => $catalogFolderId,
114 'SITE_TYPE' =>
'STORE',
120 && Landing::createInstance(
$pageId)->publication()
129 private static function setTemplateToLanding(
int $landingId,
string $templateName,
array $templateReferences):
bool
131 $resTemplate = Template::getList([
136 'XML_ID' => $templateName,
145 if ($resUpdate->isSuccess())
156 private static function setIndexToFolder(
int $folderId,
int $indexId):
void
158 $landing = Landing::createInstance($indexId);
161 Folder::update($folderId, [
162 'INDEX_ID' => $indexId,
176 if (!
$site || !in_array(
$site[
'TPL_CODE'], self::ONLY_CODES,
true))
181 $catalogFolderId = self::createFolder(
$siteId);
182 if (!$catalogFolderId)
188 !(
$orderId = self::createPageIfNotExists(
$siteId, $catalogFolderId,
'store-chats-dark/catalog_order'))
189 || !($detailId = self::createPageIfNotExists(
$siteId, $catalogFolderId,
'store-chats-dark/catalog_detail'))
190 || !($catalogId = self::createPageIfNotExists(
$siteId, $catalogFolderId,
'store-chats-dark/catalog'))
191 || !($headerId = self::createPageIfNotExists(
$siteId, $catalogFolderId,
'store-chats-dark/catalog_header'))
192 || !($footerId = self::createPageIfNotExists(
$siteId, $catalogFolderId,
'store-chats-dark/catalog_footer'))
199 self::setIndexToFolder($catalogFolderId, $catalogId);
200 self::setTemplateToLanding($catalogId,
'header_footer', [1 => $headerId, 2 => $footerId]);
201 self::setTemplateToLanding($detailId,
'header_footer', [1 => $headerId, 2 => $footerId]);
202 self::setTemplateToLanding(
$orderId,
'header_footer', [1 => $headerId, 2 => $footerId]);
204 self::replaceFooterLinks($footerId,
$siteId);
209 private static function replaceFooterLinks(
int $footerId,
int $siteId): void
211 $replaceCodes = array_keys(self::FOOTER_LINKS_MAP);
215 'select' => [
'ID',
'TPL_CODE'],
216 'filter' => [
'SITE_ID' =>
$siteId],
218 while ($landing = $landings->fetch())
220 $tpl = $landing[
'TPL_CODE'];
221 if (in_array($tpl, $replaceCodes,
true))
223 $replaces[
'"' . self::FOOTER_LINKS_MAP[$tpl] .
'"'] =
'"#landing' . $landing[
'ID'] .
'"';
227 if (!empty($replaces))
229 $blocks = BlockTable::getList([
230 'select' => [
'ID',
'CONTENT'],
233 'CODE' => self::FOOTER_BLOCK_CODE,
236 while ($block = $blocks->fetch())
238 $newContent = str_replace(
239 array_keys($replaces),
240 array_values($replaces),
243 BlockTable::update($block[
'ID'], [
244 'CONTENT' => $newContent
static set($id, $type, $lid=false)
static update($primary, array $data)
static getList(array $parameters=array())