require_once (__DIR__.'/crest.php');
ini_set('display_errors', 1); // Выводить ошибки в браузер
ini_set('display_startup_errors', 1); // Выводить ошибки при старте PHP
error_reporting(E_ALL); // Включить все уровни ошибок
global $MESS;
$lang = $_REQUEST["LANG"];
$langFile = __DIR__ . '/lang/' . $lang . '.php';
$defaultLangFile = __DIR__ . '/lang/en.php';
if (file_exists($langFile)) {
require_once($langFile);
} else {
require_once($defaultLangFile);
}
?>
Index
try
{
$method = "app.option.get";
$result_app_option_get = CRest::call($method, []);
if ( !empty($result_app_option_get["error"]) )
{
$errMess = $method." - [".$result_app_option_get["error"]."]".$result_app_option_get["error_description"];
throw new \Exception($errMess);
}
$appOptions = $result_app_option_get["result"];
if(empty($appOptions["properties_viewed"]))
{
$appOptions["properties_viewed"] = [];
}
$result_catalog_catalog_list = CRest::call(
'catalog.catalog.list',
[
'select' => [],
'filter' => ['skuPropertyId' => 0],
'order' => [
'id' => 'desc',
]
]
);
if ( !empty($result_catalog_catalog_list["error"]) )
{
$errMess = "[".$result_catalog_catalog_list["error"]."]".$result_catalog_catalog_list["error_description"];
throw new \Exception($errMess);
}
$catalogIblockId = $result_catalog_catalog_list["result"]["catalogs"][0]["iblockId"];
$result_catalog_productProperty_list = CRest::call(
'catalog.productProperty.list',
[
"filter" => [
"iblockId" => $catalogIblockId,
"propertyType" => ["S", "L", "N"]
]
]
);
$result_catalog_section_list = CRest::call(
"catalog.section.list",
[
'select' => ["id", "name", "sort"],
'filter' => [
"iblockId" => $catalogIblockId,
],
'order' => [
'name' => 'ASC'
]
]
);
$arCatalogSections = $result_catalog_section_list["result"]["sections"];
$arSectionsById = array_column($arCatalogSections, null, "id");
$result_catalog_catalog_get = CRest::call(
'catalog.catalog.get',
[
'id' => $catalogIblockId,
]
);
$catalogVatId = $result_catalog_catalog_get["result"]["catalog"]["vatId"];
//catalog.vat.list
$resultCatalogVatList = CRest::call(
'catalog.vat.list',
[
'select' => [
'id',
'name',
'rate'
],
'filter' => [
'active' => 'Y'
],
'order' => [
'id' => 'ASC'
]
]
);
?>
$selectedId = isset($appOptions["catalog_section_template_id"])
? IntVal($appOptions["catalog_section_template_id"])
: null;
$valueName = "";
if (!empty($selectedId) && !empty($arSectionsById[$selectedId]["name"])) {
$valueName = $arSectionsById[$selectedId]["name"];
}
?>
$functionsById = [];
$arFunctions = isset($appOptions["functions"])
? $appOptions["functions"]
: [];
foreach ($arFunctions as $item) {
$functionsById[$item['propId']] = $item['value'];
}
$arPropDesc = [
[
"name" => $MESS["PLSMNT_TH_PRODUCT"],
"id" => "FIELD_NAME",
"is_field" => true,
"listType" => null
],
[
"name" => $MESS["PLSMNT_TH_PRICE"],
"id" => "FIELD_PRICE",
"is_field" => true,
"listType" => null
],
[
"name" => $MESS["PLSMNT_TH_COUNT"],
"id"=>"FIELD_KOLVO",
"is_field" => true,
"listType" => null
],
[
"name"=>$MESS["PLSMNT_TH_SUMA"],
"id"=>"FIELD_SUMA",
"is_field" => true,
"listType" => null
]
];
$arPropDesc = array_merge($arPropDesc, $result_catalog_productProperty_list["result"]["productProperties"]);
$arSort = is_array($appOptions["sort"]) ? $appOptions["sort"] : [];
foreach ( $arPropDesc as &$field )
{
$sort = 0;
if ( array_key_exists($field["id"], $arSort))
{
$sort = $arSort[$field["id"]];
}
$field["sort"] = $sort;
}
unset($field);
usort($arPropDesc, function($a, $b) {
// Если оба 0 — равны
if ($a['sort'] == 0 && $b['sort'] == 0) {
return 0;
}
// Если в $a sort=0 → $a в конец
if ($a['sort'] == 0) {
return 1;
}
// Если в $b sort=0 → $b в конец
if ($b['sort'] == 0) {
return -1;
}
// Иначе обычное сравнение
return $a['sort'] <=> $b['sort'];
});
?>
}
catch(\Exception $e)
{
echo "
".$e->getMessage()."";
}
?>