Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
519 B
4
Indexable
Never
<?php

require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php');

\Bitrix\Main\Loader::includeModule('catalog');
\Bitrix\Main\Loader::includeModule('iblock');

$skuId = 29;
$fileName = 'penguins.jpg';

$sku =\Bitrix\Catalog\v2\IoC\ServiceContainer::getRepositoryFacade()->loadVariation($skuId);
if (!$sku)
{
	exit('SKU not found');
}

$sku->getImageCollection()->addValues([
	CFile::MakeFileArray($_SERVER['DOCUMENT_ROOT'] . '/' . $fileName)
]);
var_dump($sku->save());