Views: 13041
Last Modified: 24.11.2023

Task 1: Delete one of the values of a multiple property of the infoblock element.

Solution:

$el = new CIBlockElement;
$PROP = array();
$PROP[property_id][id] = "4";  
$PROP[property_id][id] = "5";
$PROP[property_id][id] = "6";

$arLoadProductArray = Array(
  "IBLOCK_ID" => $B_ID,
  "PROPERTY_VALUES" => $PROP,
  "NAME" => "Element",
  );

$PRODUCT_ID = $E_ID;
$res = $el->Update($PRODUCT_ID, $arLoadProductArray);

In this case, in order to delete the value, it is sufficient to exclude the pair: key and value of the property to be deleted from the array $PROP. This solution is appropriate when the property value id must be left unchanged.

$PROP[property_id ][id ]

Alternatively, the method SetPropertyValues may be used as a solution:

CIBlockElement::SetPropertyValues($ELEMENT_ID, $IBLOCK_ID, $PROPERTY_VALUE, $PROPERTY_CODE);

False shall be submitted to the fourth parameter of the function, and the "property code"=>"value" array – to the third parameter.

In this case, all of the values will be deleted except for those indicated in the array submitted to the third parameter.


Task 2: Adding a specific value for a multiple property of the file type:

Solution:

//68 – property id;
//FILES – symbol code of a multiple property of the file type;

$ELEMENT_ID = 392;
$arFile = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/images/help.gif");
$arFile["MODULE_ID"] = "iblock";

$PROPERTY_VALUE["68"][n0] = $arFile;  
CIBlockElement::SetPropertyValueCode($ELEMENT_ID, "FILES", Array("VALUE"=>$arFile) ) );

Task 3: Adding several values for a multiple property of the file type:

Solution:

$arFile = array(
0 => array("VALUE" => CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/images/01.gif"),"DESCRIPTION"=>""),
1 => array("VALUE" => CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/images/help.gif"),"DESCRIPTION"=>"")
);
CIBlockElement::SetPropertyValuesEx($ELEMENT_ID, $IBLOCK_ID, array($PROPERTY_CODE => $arFile));

Task 4: Deleting a specific value of a multiple property of the file type:

Solution:

//68 – property id;
//FILES – symbol code of a multiple property of the file type;
//2033 – property value id;

$ELEMENT_ID = 392;
$arFile["MODULE_ID"] = "iblock";
$arFile["del"] = "Y";

$PROPERTY_VALUE["68"]["2033"] = $arFile; 
CIBlockElement::SetPropertyValueCode($ELEMENT_ID, "FILES", Array ("2033" => Array("VALUE"=>$arFile) ) );

Task 5: Updating a specific value of a multiple property of the file type файл:

Solution:

//68 – property id;
//FILES – symbol code of a multiple property of the file type;
//2033 – property value id;

$ELEMENT_ID = 392;
$arFile = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/images/help.gif");
$arFile["MODULE_ID"] = "iblock";
$arFile["del"] = "Y";

$PROPERTY_VALUE["68"]["2033"] = $arFile;  
CIBlockElement::SetPropertyValueCode($ELEMENT_ID, "FILES", Array ("2033" => Array("VALUE"=>$arFile) ) );

Task 6: Setting a multiple property of the string type with a value description field:

Solution using SetPropertyValueCode:

$arValues = array(
  0 => array("VALUE"=>"value","DESCRIPTION"=>"value description"),
  1 => array("VALUE"=>"value2","DESCRIPTION"=>"value description2") 
);  
CIBlockElement::SetPropertyValueCode($IBLOCK_ID, $PROP_CODE, $arValues);  

Solution using SetPropertyValuesEx:

$PROPERTY_VALUE = array(
  0 => array("VALUE"=>"value","DESCRIPTION"=>"value description"),
  1 => array("VALUE"=>"value2","DESCRIPTION"=>"value description2") 
);
CIBlockElement::SetPropertyValuesEx($ELEMENT_ID, $IBLOCK_ID, array($PROPERTY_CODE => $PROPERTY_VALUE));

Task 7: Updating a multiple property of the text type without changing the DESCRIPTION:

Solution:

CIBlockElement::SetPropertyValues($nProductID, $nIblockID, array(
             array(
                 "VALUE" => array(
                     "TEXT"=>time(),
                     "TYPE"=>"HTML"
                  ),
                 "DESCRIPTION"=>"111"),
             array(
                 "VALUE" => array(
                     "TEXT"=>time(),
                     "TYPE"=>"HTML"
                  ),
                 "DESCRIPTION"=>"222"),
            ), $prop['ID']);


Courses developed by Bitrix24