403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/catalog/lib/v2/Facade/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/catalog/lib/v2/Facade/Repository.php
<?php

namespace Bitrix\Catalog\v2\Facade;

use Bitrix\Catalog\v2\IoC\ServiceContainer;
use Bitrix\Catalog\v2\Product\BaseProduct;
use Bitrix\Catalog\v2\Sku\BaseSku;

/**
 * Class Repository
 *
 * @package Bitrix\Catalog\v2\Facade
 *
 * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice.
 * @internal
 */
final class Repository
{
	private ?string $detailUrlTemplate = null;

	private bool $allowedDetailUrl = false;

	public function loadProduct(int $productId): ?BaseProduct
	{
		$iblockId = (int)\CIBlockElement::GetIBlockByID($productId);
		if (!$iblockId)
		{
			return null;
		}

		try
		{
			return $this->loadFromProductRepository($iblockId, $productId);
		}
		catch (\Bitrix\Main\SystemException $e)
		{}

		return null;
	}

	public function loadVariation(int $skuId): ?BaseSku
	{
		$iblockId = (int)\CIBlockElement::GetIBlockByID($skuId);
		if (!$iblockId)
		{
			return null;
		}

		$iblockInfo = ServiceContainer::getIblockInfo($iblockId);
		if (!$iblockInfo)
		{
			return null;
		}

		try
		{
			if ($iblockInfo->getProductIblockId() === $iblockId)
			{
				$product = $this->loadFromProductRepository($iblockId, $skuId);
				if ($product)
				{
					return $product->getSkuCollection()->getFirst();
				}
			}
			else
			{
				return $this->loadFromSkuRepository($iblockId, $skuId);
			}
		}
		catch (\Bitrix\Main\SystemException $e)
		{}

		return null;
	}

	public function setAutoloadDetailUrl(bool $state): self
	{
		$this->allowedDetailUrl = $state;

		return $this;
	}

	public function checkAutoloadDetailUrl(): bool
	{
		return $this->allowedDetailUrl;
	}

	public function setDetailUrlTemplate(?string $template): self
	{
		$this->detailUrlTemplate = $template;

		$this->setAutoloadDetailUrl($template !== null);

		return $this;
	}

	public function getDetailUrlTemplate(): ?string
	{
		return $this->detailUrlTemplate;
	}

	private function loadFromProductRepository(int $iblockId, int $productId): ?BaseProduct
	{
		static $repository = null;

		if ($repository === null)
		{
			$repository = ServiceContainer::getProductRepository($iblockId);
			if (!$repository)
			{
				return null;
			}
		}

		$repository->setAutoloadDetailUrl($this->checkAutoloadDetailUrl());
		$urlTemplate = $this->getDetailUrlTemplate();
		if ($urlTemplate)
		{
			$repository->setDetailUrlTemplate($urlTemplate);
		}

		return $repository->getEntityById($productId);
	}

	private function loadFromSkuRepository(int $iblockId, int $skuId): ?BaseSku
	{
		static $repository = null;

		if ($repository === null)
		{
			$repository = ServiceContainer::getSkuRepository($iblockId);
			if (!$repository)
			{
				return null;
			}
		}

		$repository->setAutoloadDetailUrl($this->checkAutoloadDetailUrl());
		$urlTemplate = $this->getDetailUrlTemplate();
		if ($urlTemplate)
		{
			$repository->setDetailUrlTemplate($urlTemplate);
		}

		return $repository->getEntityById($skuId);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit