89 lines
3.6 KiB
PHP
89 lines
3.6 KiB
PHP
<?php
|
|
|
|
use Bitrix\Main\Loader;
|
|
use Bitrix\Main\SystemException;
|
|
use Bitrix\Main\Web\Json;
|
|
|
|
define('STATISTIC_SKIP_ACTIVITY_CHECK', 'true');
|
|
|
|
require $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php';
|
|
include_once 'const.php';
|
|
|
|
try {
|
|
if (!Loader::includeModule('iblock') || !Loader::includeModule('aspro.allcorp3')) {
|
|
throw new SystemException('Error include module');
|
|
}
|
|
|
|
if (!include_once ($_SERVER['DOCUMENT_ROOT'].SITE_TEMPLATE_PATH.'/vendor/php/solution.php')) {
|
|
throw new SystemException('Error include solution constants');
|
|
}
|
|
|
|
$application = Bitrix\Main\Application::getInstance();
|
|
$request = $application->getContext()->getRequest();
|
|
$request->addFilter(new Bitrix\Main\Web\PostDecodeFilter());
|
|
$session = $application->getSession();
|
|
|
|
$action = $request->get('action');
|
|
$type = $request->get('type');
|
|
if (check_bitrix_sessid() && $action) {
|
|
$arItems = [];
|
|
switch ($action) {
|
|
case 'compare':
|
|
$iblockID = trim(htmlspecialcharsbx($request->get('IBLOCK_ID')));
|
|
$isSKU = $iblockID == TSolution::getFrontParametrValue('CATALOG_SKU_IBLOCK_ID');
|
|
if ($isSKU) {
|
|
$iblockID = TSolution::getFrontParametrValue('CATALOG_IBLOCK_ID');
|
|
}
|
|
|
|
if ($type === 'multiple') {
|
|
$arItems = (array)$request->get('items');
|
|
if ($iblockID && $arItems) {
|
|
foreach ($arItems as $arItem) {
|
|
$itemID = trim(htmlspecialcharsbx($arItem['ID']));
|
|
|
|
$catalogCompareList = $session->get('CATALOG_COMPARE_LIST');
|
|
$catalogCompareList[$iblockID]['ITEMS'][$itemID] = CIBlockElement::GetByID($itemID)->Fetch();
|
|
|
|
$session->set('CATALOG_COMPARE_LIST', $catalogCompareList);
|
|
}
|
|
|
|
$arItems = array_keys($_SESSION['CATALOG_COMPARE_LIST'][$iblockID]['ITEMS']);
|
|
} else {
|
|
throw new SystemException('Not enought parameters');
|
|
}
|
|
} else {
|
|
$itemID = trim(htmlspecialcharsbx($request->get('ID')));
|
|
if ($iblockID && $itemID) {
|
|
if (
|
|
$session->has('CATALOG_COMPARE_LIST')
|
|
&& !empty($session->get('CATALOG_COMPARE_LIST'))
|
|
&& !empty($session['CATALOG_COMPARE_LIST'][$iblockID])
|
|
&& array_key_exists($itemID, $session['CATALOG_COMPARE_LIST'][$iblockID]['ITEMS'])
|
|
) {
|
|
unset($session['CATALOG_COMPARE_LIST'][$iblockID]['ITEMS'][$itemID]);
|
|
} else {
|
|
$catalogCompareList = $session->get('CATALOG_COMPARE_LIST');
|
|
$catalogCompareList[$iblockID]['ITEMS'][$itemID] = CIBlockElement::GetByID($itemID)->Fetch();
|
|
|
|
$session->set('CATALOG_COMPARE_LIST', $catalogCompareList);
|
|
}
|
|
|
|
$arItems = array_keys($session['CATALOG_COMPARE_LIST'][$iblockID]['ITEMS']);
|
|
} else {
|
|
throw new SystemException('Not enought parameters');
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!isset($arItems)) {
|
|
throw new SystemException('Not enought parameters');
|
|
}
|
|
} catch (SystemException $error) {
|
|
exit(Json::encode(['error' => $error->getMessage()]));
|
|
}
|
|
|
|
exit(Json::encode(['status' => 'OK', 'items' => $arItems]));
|