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/grain.iiko/lib/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/grain.iiko/lib/deliveryhandler.php
<?php

namespace Grain\Iiko;

use \Bitrix\Currency\CurrencyManager;
use \Bitrix\Main\Loader;
use \Bitrix\Main\Localization\Loc;
use \Bitrix\Main\Web\Json;
use \Bitrix\Sale\Delivery\CalculationResult;
use \Bitrix\Main\Config\Option;
use \Bitrix\Main\Error;
use \Grain\Iiko\Order;
use \Grain\Iiko\Rest;
use \Grain\Iiko\ServiceListTable;
use \Grain\Iiko\Compatiblility;

class DeliveryHandler extends \Bitrix\Sale\Delivery\Services\Base
{
	public static function onSaleDeliveryHandlersClassNamesBuildList(\Bitrix\Main\Event $event) 
	{
		$result = new \Bitrix\Main\EventResult(
			\Bitrix\Main\EventResult::SUCCESS, 
			array(
				'\Grain\Iiko\DeliveryHandler' => '/bitrix/modules/grain.iiko/lib/deliveryhandler.php'
			)
		);
		return $result;
	}
	
	protected static $isCalculatePriceImmediately = true;
	protected static $whetherAdminExtraServicesShow = true;

	/**
	 * @param array $initParams
	 * @throws \Bitrix\Main\ArgumentTypeException
	 */
	public function __construct(array $initParams)
	{
		parent::__construct($initParams);
	}

	/**
	 * @return string Class title.
	 */
	public static function getClassTitle()
	{
		return Loc::getMessage('GRAIN_IIKO_DELIVERYHANDLER_TITLE');
	}

	/**
	 * @return string Class, service description.
	 */
	public static function getClassDescription()
	{
		return Loc::getMessage('GRAIN_IIKO_DELIVERYHANDLER_DESCRIPTION');
	}

	/**
	 * @param \Bitrix\Sale\Shipment|null $shipment
	 * @return CalculationResult
	 * @throws \Bitrix\Main\ArgumentException
	 */
	protected function calculateConcrete(\Bitrix\Sale\Shipment $shipment = null)
	{
		$calculationResult = new CalculationResult;

		$order = $shipment->getCollection()->getOrder();

		$propertyCollection = $order->getPropertyCollection();
        $propertyValueByCode = array();
        foreach($propertyCollection as $propertyValue)
            $propertyValueByCode[$propertyValue->getField('CODE')] = $propertyValue->getField('VALUE');	

		if(!$restaurant=Restaurants::getRestaurantByOrder($order))
		{
			$calculationResult->addError(new Error(Loc::getMessage('GRAIN_IIKO_DELIVERYHANDLER_ERROR_NO_RESTAURANT'),'NO_RESTAURANT'));
			return $calculationResult;
		}

		if(!$propertyValueByCode[Option::get('grain.iiko','order_prop_street')] || !$propertyValueByCode[Option::get('grain.iiko','order_prop_home')])
		{
			$calculationResult->addError(new Error(Loc::getMessage('GRAIN_IIKO_DELIVERYHANDLER_ERROR_NO_ADDRESS'),'NO_ADDRESS'));
			return $calculationResult;
		}
		
		$account = Rest::getAccount($restaurant['ID']);
		if($account['API_VERSION']==0)
			return Compatibility/DeliveryHandler::calculateConcrete($shipment,$restaurant,$order,$this->config,$calculationResult);

		$calculateTime = isset($this->config['MAIN']['TIME']) && strlen($this->config['MAIN']['TIME'])>0?date('Y-m-d',strtotime('tomorrow')).' '.$this->config['MAIN']['TIME'].':00.000':null;
			
		$params = Order::buildOrderParamsArray($restaurant,$order);

		$params["queryType"] = "deliveryCalculate";
		
		$event = new \Bitrix\Main\Event("grain.iiko", "OnBuildOrderParamsArray", array(
			'RESTAURANT' => $restaurant,
			'ORDER' => $order,
			'PARAMS' => $params,
			'CALCULATE_DELIVERY' => true,
		));
		$event->send();
		foreach ($event->getResults() as $eventResult)
		{
			if($eventResult->getType() == \Bitrix\Main\EventResult::ERROR)
				continue;
			if($eventResult->getParameters())
				$params = $eventResult->getParameters();
		}
		
		$body = array(
			'organizationIds' => array($restaurant['XML_ID']),
			//'orderLocation' => array('latitude'=>0,'longitude'=>0),
			'deliveryAddress' => array(
				'city' => $params['city'],
				'streetName' => $params['street'],
				'house' => $params['house'],
				'building' => $params['building'],
			),
			'orderItems' => array(),
			'isCourierDelivery' => true,
			//'deliveryDate' => $calculateTime,
			'deliverySum' => 0,
			'discountSum' => 0,
		);
		
		foreach($params['items'] as $item)
		{
			$newItem = array(
				'id' => $item['id'],
				'product' => 'Product',
				'amount' => $item['amount'],
				//'price' => $item['price'],
			);
			$body['deliverySum'] += $item['price']*$item['amount'];
			if(is_array($item['productSize']))
				$newItem['productSizeId'] = $item['productSize']['sizeId'];			
			if(is_array($item['modifiers']) && count($item['modifiers'])>0)
			{
				$newItem['modifiers'] = array();
				foreach($item['modifiers'] as $modifier)
				{
					$newModifier = array(
						'id' => $modifier['id'],
						'product' => 'Modifier',
						//'price' => $modifier['price'],
						'amount' => $modifier['amount'],
					);
					if($modifier['groupId'])
						$newModifier['productGroupId'] = $modifier['groupId'];
					$newItem['modifiers'][] = $newModifier;
				}
			}
			$body['orderItems'][] = $newItem;
		}

		$result = Rest::getDeliveryRestrictionsAllowed($body,$restaurant['ID']);

		if($this->config['MAIN']['LOG']=='Y')
		{
			\CEventLog::Add(array(
				"SEVERITY" => "CUSTOM",
				"AUDIT_TYPE_ID" => "GRAIN_IIKO_DELIVERY_CALCULATE",
				"MODULE_ID" => "grain.iiko",
				"ITEM_ID" => time(),
				"DESCRIPTION" => "\$result = ".print_r($result,true)."\n\$body = ".print_r($body,true),
			));
		}
		
		if(isset($result['error']))
		{
			$calculationResult->addError(new Error($result['error'],'API'));			
			return $calculationResult;
		}

		$tmpData = $result['result'];
		$tmpData['setTerminalGroup'] = $this->config['MAIN']['SET_TERMINAL_GROUP']=='Y';

		if($result['result']['isAllowed'])
		{			
			if(isset($result['result']['allowedItems']) && is_array($result['result']['allowedItems']))
			{
				$allowedItemSelected = false;
				$deliveryPriceSelected = false;

				foreach($result['result']['allowedItems'] as $allowedItem)
				{
					if($allowedItem['organizationId']!=$restaurant['XML_ID'] && Option::get('grain.iiko','all_terminal_groups_'.$restaurant['ID'])!='Y')
						continue;
					$deliveryPrice = 0.0;
					$service = null;
					if($allowedItem['deliveryServiceProductId'])
					{
						$resultService = ServiceListTable::getList(array(
							'filter' => array(
								'ORGANIZATION_ID' => $restaurant['XML_ID'],
								'SERVICE_ID' => $allowedItem['deliveryServiceProductId'],
								'!DELETED' => 'Y',
							),
							'limit' => 1,
						));
						if($service=$resultService->fetch())
							$deliveryPrice = floatval($service['PRICE']);
					}
					if($deliveryPriceSelected===false || $deliveryPrice<$deliveryPriceSelected)
					{
						$deliveryPriceSelected = $deliveryPrice;
						$allowedItemSelected = $allowedItem;
						if($service)
							$tmpData['service'] = $service;
						elseif(isset($tmpData['service']))
							unset($tmpData['service']);
					}
				}
				if($allowedItemSelected)
				{
					$tmpData['allowedItemSelected'] = $allowedItemSelected;
					$calculationResult->setDeliveryPrice(
						\roundEx(
							$deliveryPriceSelected,
							SALE_VALUE_PRECISION
						)
					);
					if($allowedItemSelected['deliveryDurationInMinutes'])
					{
						$calculationResult->setPeriodDescription(Loc::getMessage('GRAIN_IIKO_DELIVERYHANDLER_PERIOD',array('#MIN#'=>$allowedItemSelected['deliveryDurationInMinutes'])));
					}
				}
				else
				{
					$calculationResult->setDeliveryPrice(0.0);
				}
			}
			else
			{
				$calculationResult->setDeliveryPrice(0.0);
			}
		}
		else
		{
			$calculationResult->addError(new Error(Loc::getMessage('GRAIN_IIKO_DELIVERYHANDLER_ERROR_NO_DELIVERY'),'NO_DELIVERY'));
		}

		$calculationResult->setTmpData(Json::encode($tmpData));

		return $calculationResult;
	}

	/**
	 * @return array
	 * @throws \Exception
	 */

	protected function getConfigStructure()
	{
		$result = array(
			"MAIN" => array(
				"TITLE" => Loc::getMessage("GRAIN_IIKO_DELIVERYHANDLER_SETTINGS_TAB_MAIN"),
				"DESCRIPTION" => Loc::getMessage("GRAIN_IIKO_DELIVERYHANDLER_SETTINGS_TAB_MAIN"),
				"ITEMS" => array(
					"NAME" => array(
						"TYPE" => "STRING",
						"NAME" => Loc::getMessage("GRAIN_IIKO_DELIVERYHANDLER_SETTINGS_NAME"),
						"DEFAULT" => "Calculate customer",
					),
					"PHONE" => array(
						"TYPE" => "STRING",
						"NAME" => Loc::getMessage("GRAIN_IIKO_DELIVERYHANDLER_SETTINGS_PHONE"),
						"DEFAULT" => "+7 (999) 999-99-99"
					),
					"TIME" => array(
						"TYPE" => "STRING",
						"NAME" => Loc::getMessage("GRAIN_IIKO_DELIVERYHANDLER_SETTINGS_TIME"),
						"DEFAULT" => "12:00"
					),
					"SET_TERMINAL_GROUP" => array(
						'TYPE' => 'Y/N',
						"NAME" => Loc::getMessage("GRAIN_IIKO_DELIVERYHANDLER_SETTINGS_SET_TERMINAL_GROUP"),
						"DEFAULT" => "N"
					),
					"LOG" => array(
						'TYPE' => 'Y/N',
						"NAME" => Loc::getMessage("GRAIN_IIKO_DELIVERYHANDLER_SETTINGS_LOG"),
						"DEFAULT" => "N"
					),					
				)
			)
		);

		return $result;
	}

	public function isCalculatePriceImmediately()
	{
		return self::$isCalculatePriceImmediately;
	}

	public static function whetherAdminExtraServicesShow()
	{
		return self::$whetherAdminExtraServicesShow;
	}

	public function isCompatible(\Bitrix\Sale\Shipment $shipment)
	{
		return true;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit