• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/v2/Integration/Seo/Facebook/FacebookFacade.php
  • Класс: BitrixCatalogv2IntegrationSeoFacebookFacebookFacade
  • Вызов: FacebookFacade::exportProductsByIds
public function exportProductsByIds(array $ids): Result
{
	$result = $this->checkRequirements();
	if (!$result->isSuccess())
	{
		return $result;
	}

	$skus = $this->getProductEntitiesByIds($ids);

	$result = $this->validateProducts($skus);
	if (!$result->isSuccess())
	{
		return $result;
	}

	$preparedSku = $this->prepareProducts($skus);
	$response =
		$this
			->getCatalog()
			->batchCatalogProducts($preparedSku);

	$result = new Result();
	if ($response->isSuccess())
	{
		$responseData = $response->getData();
		$queueId = $responseData['queue_ids'][0] ?? null;
		$validationStatus = $responseData['validation_status'] ?? null;
		$productKeys = array_keys($preparedSku);

		if ($validationStatus)
		{
			$errorProducts = $this->parseValidationStatus($validationStatus);
			$result->setData(['ERROR_PRODUCTS' => $errorProducts]);
			$errorProductKeys = array_keys($errorProducts);
			$productKeys = array_diff($productKeys, $errorProductKeys);
			$this->exportedProductRepository->save($errorProducts);
		}

		if ($queueId)
		{
			BitrixCatalogv2IntegrationSeoEntityExportedProductQueueTable::add([
				'QUEUE_ID' => $queueId,
				'PRODUCT_IDS' => BitrixMainWebJson::encode($productKeys),
			]);
			$result->setData(['QUEUE_ID' => $queueId]);
		}
	}
	else
	{
		$result->addErrors($response->getErrors());
	}

	return $result;
}