Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
770 B
5
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 = 74;

/** @var \Bitrix\Catalog\v2\Barcode\BarcodeFactory $barcodeFactory */
$barcodeFactory = \Bitrix\Catalog\v2\IoC\ServiceContainer::getContainer()->make(
	\Bitrix\Catalog\v2\IoC\Dependency::BARCODE_FACTORY
);

$barcode = $barcodeFactory->createEntity();
$barcode
	->setBarcode('000001')
	//->setProductId(74)
	//->setStoreId(1)
;

$sku =
	\Bitrix\Catalog\v2\IoC\ServiceContainer::getRepositoryFacade()
		->loadVariation($skuId)
;
$barcodeCollection = $sku->getBarcodeCollection();
$barcodeCollection->add($barcode);

var_dump($sku->save());