Answer the question
In order to leave comments, you need to log in
Why do duplicate catalog items occur when sorting images based on width and height?
Please explain why there is a duplication of the elements of the catalog list, with such a list output in an attempt to sort products by image format - first vertical, then square, horizontal, others not included in the condition, without photos?
Code example
if (!isset($_GET['byName']) && !isset($_GET['byPrice']))
{
$arVert = array();
$arSquare = array();
$arHor = array();
$arQwadrat = array();
$arWithPhoto = array();
$arNoPhoto = array();
foreach ($arResult['elements'] as $key => $value)
$arFile = array();
if (isset($value["DEPTH_LEVEL"])) {
if (count($value['UF_CROPED']) > 0) {
$arFile = CFile::GetFileArray($value['UF_CROPED'][0]);
$arWithPhoto[$key] = $value;
} else {
$arNoPhoto[$key] = $value;
}
} else {
if (!empty($value["DETAIL_PICTURE"])) {
$arWithPhoto[$key] = $value;
$arFile = CFile::GetFileArray($value["DETAIL_PICTURE"]);
} else {
$arNoPhoto[$key] = $value;
}
}
if (!empty($arFile['WIDTH']) && !empty($arFile['HEIGHT']))
{
$k = floatval(intval($arFile['WIDTH']) / intval($arFile['HEIGHT']));
if ($k > 1.2)
{
$arHor[$key] = $value;
}
elseif ($k < 0.8) {
$arVert[$key] = $value;
}
else
{
$arSquare[$key] = $value;
}
}
}
$arResult['elements'] = array_merge($arVert, $arSquare, $arHor, $arWithPhoto, $arNoPhoto);
}
Answer the question
In order to leave comments, you need to log in
Why do you need the $arWithPhoto array ? It duplicates what goes into $arHor , $arVert and $arSquare .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question