A
A
alexwprof2019-08-21 14:05:26
1C-Bitrix
alexwprof, 2019-08-21 14:05:26

How to sort products by property value in Bitrix?

Products have a property of type list. There are three meanings. Popular, not popular, very popular. Now on the test page I'm trying to make a selection so that only those products that have the property set to "Popular" are displayed. How to do it. There is a code, tell me how to add it.

<?
if(CModule::IncludeModule("iblock")){

    $arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM");
    $arFilter = Array("IBLOCK_ID"=>2, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y",
    "PROPERTY_CATMAIN_PROD" => "Популярные");
    $res = CIBlockElement::GetList(
            Array(),
            $arFilter,
            false,
            Array("nPageSize"=>50),
            $arSelect
    );

    while($ob = $res->GetNextElement()){
        $arFields = $ob->GetFields();
        debug($arFields);
        $arProps = $ob->GetProperties();
        debug($arProps);
    }


}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexwprof, 2019-08-21
@alexwprof

if(CModule::IncludeModule("iblock")){
    $arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM");
    $arrFilterMain["PROPERTY_CATMAIN_PROD_VALUE"]= "Не популярные";
    $res = CIBlockElement::GetList(
            Array(),
            $arrFilterMain,
            false,
            Array("nPageSize"=>50),
            $arSelect
    );
    while($ob = $res->GetNextElement()){
        $arFields = $ob->GetFields();
        debug($arFields);
        $arProps = $ob->GetProperties();
        debug($arProps);
    }
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question