• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Service/Timeline/Item/DealProductList/ExpandableListFactory.php
  • Класс: Bitrix\Crm\Service\Timeline\Item\DealProductList\ExpandableListFactory
  • Вызов: ExpandableListFactory::makeByProductsData
static function makeByProductsData(array $productsData, int $dealId): ExpandableList
{
	$list = new ExpandableList();

	$products = array_map(
		static function (array $productData)
		{
			return Converter::convertFromArray($productData);
		},
		$productsData
	);
	$dealSkuIds = self::getDealSkuIds($dealId);
	foreach ($products as $product)
	{
		$isInDeal = in_array($product->getOfferId(), $dealSkuIds, true);

		$listItem =
			(new ExpandableListItem($product->getOfferId()))
				->setTitle($product->getName())
				->setTitleAction(self::getOpenProductDetailAction($product->getAdminLink()))
				->setImage($product->getImageSource())
				->setIsSelected($isInDeal)
		;

		$bottomBlock = new LineOfTextBlocks();
		if ($product->getVariationInfo())
		{
			$bottomBlock->addContentBlock(
				'variationInfo',
				(new Text())
					->setColor(Text::COLOR_BASE_50)
					->setValue($product->getVariationInfo())
					->setFontSize(Text::FONT_SIZE_SM)
			);
		}

		if (
			$product->getPrice()
			&& $product->getCurrency()
		)
		{
			$bottomBlock->addContentBlock(
				'price',
				(new Money())
					->setOpportunity($product->getPrice())
					->setCurrencyId($product->getCurrency())
					->setFontSize(Text::FONT_SIZE_SM)
			);
		}

		if (!$bottomBlock->isEmpty())
		{
			$listItem->setBottomBlock($bottomBlock);
		}

		$buttonText = null;
		$buttonAction = null;
		if ($isInDeal)
		{
			$buttonText = Loc::getMessage('CRM_TIMELINE_CONTENT_BLOCK_PRODUCT_LIST_ALREADY_IN_DEAL');
			$buttonAction = null;
		}
		elseif (self::hasCatalogRead())
		{
			$buttonText = Loc::getMessage('CRM_TIMELINE_CONTENT_BLOCK_PRODUCT_LIST_TO_DEAL');
			$buttonAction = (new Action\JsEvent('ProductList:AddToDeal'))
				->addActionParamInt('dealId', $dealId)
				->addActionParamInt('productId', $product->getOfferId())
				->addActionParamArray('options', [
					'price' => $product->getPrice(),
				])
				->setAnimation(Action\Animation::showLoaderForItem())
			;
		}

		if ($buttonText)
		{
			$listItem->setButton(
				(new ExpandableListItemButton())
					->setText($buttonText)
					->setAction($buttonAction)
			);
		}

		$list->addListItem($listItem);
	}

	return $list;
}