Y
Y
Yuriy2018-08-15 10:28:10
1C-Bitrix
Yuriy, 2018-08-15 10:28:10

Bitrix selection from infoblock, how to filter by multi-property?

PROPERTY_HIT - list type property, contains New, Promotion, Hit, etc.
I filter the elements by the value "New" so that these elements are not in the selection

$arFilter = Array(
    "IBLOCK_ID"=>$IBLOCK_ID,  
    "ACTIVE"=>"Y",
    ">=DATE_CREATE"=>date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT")), mktime(0,0,0,$date)),
    "!PROPERTY_HIT_VALUE"=>array("Новинка"),
  );
  
$productQuery = CIBlockElement::GetList(Array(), $arFilter,false,false, Array("ID","IBLOCK_ID","DATE_CREATE","NAME","PROPERTY_HIT"));

I still get this element, because He also has "Action" in the property.
array(14) {
  ["ID"]=>
  string(5) "34255"
  ["~ID"]=>
  string(5) "34255"
  ["IBLOCK_ID"]=>
  string(2) "53"
  ["~IBLOCK_ID"]=>
  string(2) "53"
  ["DATE_CREATE"]=>
  string(19) "14.08.2018 14:45:58"
  ["~DATE_CREATE"]=>
  string(19) "14.08.2018 14:45:58"
  ["NAME"]=>
  string(4) "test"
  ["~NAME"]=>
  string(4) "test"
  ["PROPERTY_HIT_VALUE"]=>
  string(10) "Акция"
  ["~PROPERTY_HIT_VALUE"]=>
  string(10) "Акция"
  ["PROPERTY_HIT_ENUM_ID"]=>
  string(2) "91"
  ["~PROPERTY_HIT_ENUM_ID"]=>
  string(2) "91"
  ["PROPERTY_HIT_VALUE_ID"]=>
  string(6) "224294"
  ["~PROPERTY_HIT_VALUE_ID"]=>
  string(6) "224294"
}

if you remove PROPERTY_HIT_VALUE from the filter at all, then the output will have 2 identical elements, the difference will be only in PROPERTY_HIT_VALUE.
how to filter elements so that they do not fall under the selection !PROPERTY_HIT_VALUE = New

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2018-08-15
@yous

There are several ways to do this. As the user Maxim
suggested, you can translate the method of storing properties into a separate table. This will increase the speed of the search and fix this misunderstanding left over from the infoblocks of version 1. If you don’t want to do anything, but want everything to work, then you can use SubQuery in CIblockElement

\Bitrix\Main\Loader::IncludeModule('iblock');

$arFilter = Array(
  "IBLOCK_ID" => 2,  
  "ACTIVE"    => "Y",
  "!ID"       => \CIBlockElement::SubQuery("PROPERTY_HIT", array(
    "IBLOCK_ID"          => 2,
    "PROPERTY_HIT_VALUE" => "Новинка",
  ))
);
  
$productQuery = \CIBlockElement::GetList(
  [],
  $arFilter,
  false,
  false,
  [
    "ID",
    "IBLOCK_ID",
    "NAME",
    "PROPERTY_HIT"
  ]
);

while( $arElement = $productQuery->fetch() )
{
  echo "<pre>";
  var_dump($arElement);
  echo "</pre>";
}

M
Maxim, 2018-08-15
@Tomio

Try moving the storage of properties to separate tables (in the infoblock settings) and repeat the selection under the same conditions.
Do not forget to make a backup before that .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question