Answer the question
In order to leave comments, you need to log in
How to add a picture to MORE_PHOTO?
The situation is as follows:
There is an assortment of goods from 904 elements, I was told that it is necessary to attach one photo to each.
As you understand, doing it with your hands is very painful.
I don't understand what script to write to add another photo to this property.
Thank you all in advance
Answer the question
In order to leave comments, you need to log in
In general, here is the code for adding a picture to MORE_PHOTO without overwriting the old ones, I tested it on bitrixlabs, it is working.
\Bitrix\Main\Loader::includeModule('iblock');
$iBlockId = 28;
$file = CFile::MakeFileArray($_SERVER['DOCUMENT_ROOT'] . "/backs/doorman.jpg");
$result = CIblockElement::GetList([], ['IBLOCK_ID' => $iBlockId, 'INCLUDE_SUBSECTIONS' => 'Y'], false, false, ['ID']);
while ($element = $result->Fetch()) {
$values = ['n0' => ['VALUE' => $file, 'DESCRIPTION' => '']];
$result2 = CIBlockElement::GetProperty($iBlockId, $element['ID'], [], ['CODE' => 'MORE_PHOTO']);
while ($photo = $result2->Fetch()) {
$values[$photo['PROPERTY_VALUE_ID']] = ['VALUE' => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
'description' => ''
], 'DESCRIPTION' => ''];
}
CIBlockElement::SetPropertyValuesEx($element['ID'], $iBlockId, ['MORE_PHOTO' => $values]);
}
$elementId=1; //ID элемента в который нужно добавить
$tmpFilePath=$_SERVER['DOCUMENT_ROOT']."/upload/picatest.jpg";
$arFile=array("VALUE" => \CFile::MakeFileArray($tmpFilePath),"DESCRIPTION"=>"");
\CIBlockElement::SetPropertyValueCode($elementId, 'MORE_PHOTO', $arFile);
$elementId=1; //ID элемента в который нужно добавить
$tmpFilePath=$_SERVER['DOCUMENT_ROOT']."/upload/picatest1.jpg";
$arFile[]=array("VALUE" => \CFile::MakeFileArray($tmpFilePath),"DESCRIPTION"=>"");
$tmpFilePath=$_SERVER['DOCUMENT_ROOT']."/upload/picatest2.jpg";
$arFile[]=array("VALUE" => \CFile::MakeFileArray($tmpFilePath),"DESCRIPTION"=>"");
$tmpFilePath=$_SERVER['DOCUMENT_ROOT']."/upload/picatest3.jpg";
$arFile[]=array("VALUE" => \CFile::MakeFileArray($tmpFilePath),"DESCRIPTION"=>"");
\CIBlockElement::SetPropertyValueCode($elementId, 'MORE_PHOTO', $arFile);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question