62 if (empty(
$fields[
'MODIFIED_BY']))
76 if ($updateResult->isSuccess())
78 if (!is_null($products))
80 $deleteProductsResult = self::deleteProductsByContractId($id);
81 if (!$deleteProductsResult->isSuccess())
83 $result->addErrors($deleteProductsResult->getErrors());
88 $addProductsResult = self::addProducts($id, $products);
89 if (!$addProductsResult->isSuccess())
91 $result->addErrors($addProductsResult->getErrors());
98 self::saveFiles($id,
$files);
103 $result->addErrors($updateResult->getErrors());
187 'filter' => [
'=ID' => $id],
204 '=CONTRACT_ID' => $id,
207 while ($agentProduct = $agentProductIterator->fetch())
211 $sectionIds[] = $agentProduct[
'PRODUCT_ID'];
216 $productsIds[] = $agentProduct[
'PRODUCT_ID'];
219 $agentProduct[
'PRODUCT_NAME'] =
'';
220 $products[] = $agentProduct;
232 'select' => [
'ID',
'NAME',
'PICTURE'],
233 'filter' => [
'=ID' => array_unique($sectionIds)],
235 while ($sectionData = $sectionIterator->fetch())
237 $sectionNames[$sectionData[
'ID']] = $sectionData[
'NAME'];
238 if (!empty($sectionData[
'PICTURE']))
240 $sectionImages[$sectionData[
'ID']] = self::getImageSource((
int)$sectionData[
'PICTURE']);
246 $iblockProductMorePhotoMap = [];
250 'select' => [
'ID',
'NAME',
'IBLOCK_ID',
'PREVIEW_PICTURE',
'DETAIL_PICTURE'],
251 'filter' => [
'=ID' => array_unique($productsIds)],
253 while ($elementData = $elementIterator->fetch())
255 $elementId = $elementData[
'ID'];
256 $productNames[$elementId] = $elementData[
'NAME'];
257 if (!empty($elementData[
'PREVIEW_PICTURE']))
259 $productImages[$elementId] = self::getImageSource((
int)$elementData[
'PREVIEW_PICTURE']);
262 if (empty($element[
'IMAGE']) && !empty($elementData[
'DETAIL_PICTURE']))
264 $productImages[$elementId] = self::getImageSource((
int)$elementData[
'DETAIL_PICTURE']);
267 if (empty($element[
'IMAGE']))
269 $iblockProductMorePhotoMap[$elementData[
'IBLOCK_ID']] ??= [];
270 $iblockProductMorePhotoMap[$elementData[
'IBLOCK_ID']][] = $elementId;
274 if (!empty($iblockProductMorePhotoMap))
278 'select' => [
'ID',
'IBLOCK_ID'],
280 '=IBLOCK_ID' => array_keys($iblockProductMorePhotoMap),
288 $morePhotoIds[$row[
'IBLOCK_ID']] = $row[
'ID'];
291 foreach ($morePhotoIds as
$iblockId => $propertyId)
293 $elementIds = $iblockProductMorePhotoMap[
$iblockId];
294 $elementPropertyValues = array_fill_keys($elementIds, []);
302 \CIBlockElement::GetPropertyValuesArray($elementPropertyValues,
$iblockId, $offersFilter, $propertyFilter);
303 foreach ($elementPropertyValues as $productId => $properties)
305 if (empty($properties))
310 $morePhotoProperty = reset($properties);
311 $value = $morePhotoProperty[
'VALUE'] ??
null;
317 $propertyValue = is_array($value) ? reset($value) : $value[
'VALUE'];
320 $productImages[$productId] = self::getImageSource((
int)
$propertyValue);
328 $products = array_map(
329 static function ($product) use ($sectionNames, $productNames, $productImages, $sectionImages)
333 $product[
'PRODUCT_NAME'] = $sectionNames[$product[
'PRODUCT_ID']];
334 $product[
'IMAGE'] = $sectionImages[$product[
'PRODUCT_ID']] ??
null;
339 $product[
'PRODUCT_NAME'] = $productNames[$product[
'PRODUCT_ID']];
340 $product[
'IMAGE'] = $productImages[$product[
'PRODUCT_ID']] ??
null;
349 $files = self::getFiles($id);
355 'PRODUCTS' => $products,