• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/ads/pixel/conversioneventtriggers/dealtrigger.php
  • Класс: Bitrix\Crm\Ads\Pixel\ConversionEventTriggers\DealTrigger
  • Вызов: DealTrigger::getConversionEventBuilder
protected function getConversionEventBuilder(): CrmConversionEventBuilderInterface
{
	return new class($this->deal) extends AbstractFacebookBuilder implements CrmConversionEventBuilderInterface {
		/**@var array|null $deal */
		protected $deal;

		/**
		 * FacebookCrmDealEventBuilder constructor.
		 *
		 * @param array|null $deal
		 */
		public function __construct(?array $deal)
		{
			$this->deal = $deal;
		}

		protected function resolveEventName(): string
		{
			['CATEGORY_ID' => $categoryId, 'STAGE_ID' => $stage] = $this->deal;
			$categoryId = $categoryId ?? 0;
			$stageName = Factory::createTarget(CCrmOwnerType::Deal)->getStatusInfos($categoryId)[$stage]['NAME'];
			if ($categoryId > 0)
			{
				return $this->getEntityName() . '. ' . DealCategory::getName($categoryId) . '. ' . $stageName;
			}

			return $this->getEntityName() . '. ' . $stageName;
		}

		protected function getEntityName(): string
		{
			if (array_key_exists($key = CCrmOwnerType::Deal, $typeDescriptions = CCrmOwnerType::GetAllDescriptions()))
			{
				return $typeDescriptions[$key];
			}

			return '';
		}

		/**
		 * @param $entity
		 *
		 * @return array|null
		 */
		public function getEventParams($entity): ?array
		{
			return [
				'event_name' => $this->resolveEventName(),
				'action_source' => Facebook\Event::ACTION_SOURCE_SYSTEM_GENERATED,
				'user_data' => $entity,
				'custom_data' => [
					'value' => (float)($this->deal['OPPORTUNITY'] ?? 0),
					'currency' => $this->deal['CURRENCY_ID'],
				],
			];
		}

		/**
		 * @return array
		 */
		public function getUserData(): array
		{
			return $this->getDealUserData($this->deal);
		}
	};
}