%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 3.141.7.144
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/seo/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/seo/lib/advsession.php
<?php
namespace Bitrix\Seo;

use Bitrix\Currency\CurrencyManager;
use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
use Bitrix\Sale\Internals\BasketTable;
use Bitrix\Catalog\ProductTable;
use Bitrix\Seo\Adv\LinkTable;
use Bitrix\Seo\Adv\OrderTable;
use Bitrix\Seo\Adv\YandexBannerTable;
use Bitrix\Seo\Engine\YandexDirect;

Loc::loadMessages(__FILE__);

/**
 * Class AdvSession
 *
 * Events handler for managing users came from yandex.direct ad
 *
 * @package Bitrix\Seo
 **/
class AdvSession
{
	const URL_PARAM_CAMPAIGN = 'bxydcampaign';
	const URL_PARAM_CAMPAIGN_VALUE = '{campaign_id}';
	const URL_PARAM_BANNER = 'bxydbanner';
	const URL_PARAM_BANNER_VALUE = '{banner_id}';

	protected static $orderHandlerCalled = array();

	public static function checkSession()
	{
		$request = Main\Context::getCurrent()->getRequest();
		if(
			isset($request[static::URL_PARAM_CAMPAIGN])
			&& isset($request[static::URL_PARAM_BANNER])
		)
		{
			$_SESSION['SEO_ADV'] = array(
				"ENGINE" => YandexDirect::ENGINE_ID,
				"CAMPAIGN_ID" => $request[static::URL_PARAM_CAMPAIGN],
				"BANNER_ID" => $request[static::URL_PARAM_BANNER],
			);
		}
	}

	public static function isSession()
	{
		return isset($_SESSION['SEO_ADV']);
	}

	public static function getSession()
	{
		return $_SESSION['SEO_ADV'];
	}

	public static function onOrderSave($orderId, $orderFields, $orderData, $isNew)
	{
		if($isNew)
		{
			static::checkSessionOrder($orderId);
		}
	}

	public static function onBasketOrder($orderId)
	{
		static::checkSessionOrder($orderId);
	}

	public static function onSalePayOrder($orderId, $val)
	{
		if($val == 'Y')
		{
			static::countSessionOrder($orderId);
		}
	}

	public static function onSaleDeductOrder($orderId, $val)
	{
		if($val == 'Y')
		{
			static::countSessionOrder($orderId);
		}
	}
	public static function onSaleDeliveryOrder($orderId, $val)
	{
		if($val == 'Y')
		{
			static::countSessionOrder($orderId);
		}
	}

	public static function onSaleStatusOrder($orderId, $status)
	{
		if($status == 'F')
		{
			static::countSessionOrder($orderId);
		}
	}

	protected static function checkSessionOrder($orderId)
	{
		if(
			isset($_SESSION['SEO_ADV'])
			&& is_array($_SESSION['SEO_ADV'])
			&& $_SESSION['SEO_ADV']['BANNER_ID'] > 0
			&& !in_array($orderId, static::$orderHandlerCalled)
			&& Main\Loader::includeModule('sale')
			&& Main\Loader::includeModule('catalog')
		)
		{
			static::$orderHandlerCalled[] = $orderId;

			$banner = null;
			switch($_SESSION['SEO_ADV']['ENGINE'])
			{
				case YandexDirect::ENGINE_ID:
					$dbRes = YandexBannerTable::getList(array(
						'filter' => array(
							'=XML_ID' => $_SESSION['SEO_ADV']['BANNER_ID'],
							'=ENGINE.CODE' => YandexDirect::ENGINE_ID,
						),
						'select' => array(
							'ID', 'CAMPAIGN_ID', 'ENGINE_ID',
						)
					));
					$banner = $dbRes->fetch();
					break;
			}

			if($banner)
			{
				$linkedProductsList = static::getBannerLinkedProducts($banner['ID']);

				if(count($linkedProductsList) > 0)
				{
					$basket = BasketTable::getList(array(
						'filter' => array(
							'=ORDER_ID' => $orderId,
						),
						'select' => array('PRODUCT_ID'),
					));

					$addEntry = false;
					while($item = $basket->fetch())
					{
						if(in_array($item['PRODUCT_ID'], $linkedProductsList))
						{
							$addEntry = true;
							break;
						}
						else
						{
							$productInfo = \CCatalogSKU::GetProductInfo($item['PRODUCT_ID']);

							if(is_array($productInfo) && in_array($productInfo['ID'], $linkedProductsList))
							{
								$addEntry = true;
								break;
							}
						}
					}

					if($addEntry)
					{
						$entryData = array(
							'ENGINE_ID' => $banner['ENGINE_ID'],
							'CAMPAIGN_ID' => $banner['CAMPAIGN_ID'],
							'BANNER_ID' => $banner['ID'],
							'ORDER_ID' => $orderId,
							'SUM' => 0,
							'PROCESSED' => OrderTable::NOT_PROCESSED,
						);

						OrderTable::add($entryData);
					}
				}
			}
		}
	}

	protected static function countSessionOrder($orderId)
	{
		if(
			Main\Loader::includeModule('sale')
			&& Main\Loader::includeModule('catalog')
			&& Main\Loader::includeModule('currency')
		)
		{
			$orderLinks = OrderTable::getList(array(
				'filter' => array(
					'=ORDER_ID' => $orderId,
					'=PROCESSED' => OrderTable::NOT_PROCESSED,
				),
				'select' => array('ID', 'BANNER_ID')
			));
			$orderLink = $orderLinks->fetch();
			if($orderLink)
			{
				$linkedProductsList = static::getBannerLinkedProducts($orderLink['BANNER_ID']);
				if(count($linkedProductsList) > 0)
				{
					$basket = BasketTable::getList(array(
						'filter' => array(
							'=ORDER_ID' => $orderId,
						),
						'select' => array('PRODUCT_ID', 'GROSS_PROFIT', 'SUMMARY_PRICE', 'SUMMARY_PURCHASING_PRICE', 'QUANTITY'),
					));

					$sum = 0;
					while($item = $basket->fetch())
					{
						if(in_array($item['PRODUCT_ID'], $linkedProductsList))
						{
							$sum += static::getProductProfit($item);
						}
						else
						{
							$productInfo = \CCatalogSKU::GetProductInfo($item['PRODUCT_ID']);

							if(is_array($productInfo) && in_array($productInfo['ID'], $linkedProductsList))
							{
								$sum += static::getProductProfit($item);
							}
						}
					}

					OrderTable::update($orderLink['ID'], array(
						'SUM' => $sum,
						'PROCESSED' => OrderTable::PROCESSED,
					));
				}
			}
		}
	}

	protected static function getBannerLinkedProducts($bannerId)
	{
		$linkedProductsList = array();
		$linkedProducts = LinkTable::getList(
			array(
				'filter' => array(
					'=LINK_TYPE' => LinkTable::TYPE_IBLOCK_ELEMENT,
					'=BANNER_ID' => $bannerId,
				),
				'select' => array(
					'LINK_ID'
				)
			)
		);

		while($link = $linkedProducts->fetch())
		{
			$linkedProductsList[] = $link['LINK_ID'];
		}

		return $linkedProductsList;
	}

	// TODO: remove all this math when /sale_refactoring_mince releases
	protected static function getProductProfit($productInfo)
	{
		if($productInfo['GROSS_PROFIT'] <> '')
		{
			$profit = doubleval($productInfo['GROSS_PROFIT']);
		}
		else
		{
			$purchasingCost = 0;
			if($productInfo['SUMMARY_PURCHASING_PRICE'] <> '')
			{
				$purchasingCost = doubleval($productInfo['SUMMARY_PURCHASING_PRICE']);
			}
			else
			{
				$dbRes = ProductTable::getList(array(
					'filter' => array(
						'=ID' => $productInfo['PRODUCT_ID'],
					),
					'select' => array(
						'ID', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY'
					)
				));
				$productInfoBase = $dbRes->fetch();
				if($productInfoBase)
				{
					$purchasingCost = $productInfoBase['PURCHASING_PRICE'] * $productInfo['QUANTITY'];

					$baseCurrency = CurrencyManager::getBaseCurrency();
					if($baseCurrency != $productInfoBase['PURCHASING_CURRENCY'])
					{
						$purchasingCost = \CCurrencyRates::convertCurrency(
							$purchasingCost,
							$productInfoBase['PURCHASING_CURRENCY'],
							$baseCurrency
						);
					}
				}
			}

			$profit = doubleval($productInfo['SUMMARY_PRICE'])-$purchasingCost;
		}
		return $profit;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit