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/compatibility/ |
Upload File : |
<?php namespace Grain\Iiko\Compatiblility; use \Bitrix\Main\Localization\Loc; use \Bitrix\Sale\Delivery\CalculationResult; use \Bitrix\Main\Config\Option; use \Bitrix\Main\Error; use \Grain\Iiko\Order; use \Grain\Iiko\Rest; class DeliveryHandler { public static function calculateConcrete($shipment,$restaurant,$order,$config,$calculationResult) { $calculatePhone = $config['MAIN']['PHONE']; $calculateName = $config['MAIN']['NAME']; $calculateTime = date('Y-m-d',strtotime('tomorrow')).' '.$config['MAIN']['TIME'].':00'; $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 = Rest::buildIikoOrderBody($params,$restaurant['ID']); $event = new \Bitrix\Main\Event("grain.iiko", "OnBuildIikoOrderBody", array( 'RESTAURANT' => $restaurant, 'ORDER' => $order, 'PARAMS' => $params, 'BODY' => $body, 'CALCULATE_DELIVERY' => true, )); $event->send(); foreach ($event->getResults() as $eventResult) { if($eventResult->getType() == \Bitrix\Main\EventResult::ERROR) continue; if($eventResult->getParameters()) $body = $eventResult->getParameters(); } if($calculateTime) $body['order']['date'] = $calculateTime; if($calculatePhone) $body['order']['phone'] = $body['customer']['phone'] = $calculatePhone; if($calculateName) $body['customer']['name'] = $calculateName; $result = Rest::orderCheckCreate($body,$restaurant['ID']); if($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), )); } $errorMessage = Option::get('grain.iiko','post_orders_check_error_message_'.$order->getSiteId()); $problemMessage = Option::get('grain.iiko','post_orders_check_error_message_'.$order->getSiteId()); $problemGeoMessage = Option::get('grain.iiko','post_orders_check_problem_message_geo_'.$order->getSiteId()); if(isset($result['error'])) { $message = !!$errorMessage?str_replace('#ERROR#',$result['error'],$errorMessage):$result['error']; $calculationResult->addError(new Error($message)); return $calculationResult; } elseif(isset($result['result']['problem'])) { if( strpos($result['result']['problem'], Loc::getMessage('GRAIN_IIKO_ORDER_GEO_NEEDLE1'))!==false || strpos($result['result']['problem'], Loc::getMessage('GRAIN_IIKO_ORDER_GEO_NEEDLE2'))!==false ) $message = !!$problemGeoMessage?str_replace('#ERROR#',$result['result']['problem'],$problemGeoMessage):$result['result']['problem']; else $message = !!$problemMessage?str_replace('#ERROR#',$result['result']['problem'],$problemMessage):$result['result']['problem']; $calculationResult->addError(new Error($message)); return $calculationResult; } if(array_key_exists('deliveryServiceProductInfo',$result['result'])) { if(is_array($result['result']['deliveryServiceProductInfo'])) { $calculationResult->setDeliveryPrice( \roundEx( $result['result']['deliveryServiceProductInfo']['productSum'], SALE_VALUE_PRECISION ) ); } else { $calculationResult->setDeliveryPrice(0.0); } if($result['result']['deliveryDurationInMinutes']) { $calculationResult->setPeriodDescription(Loc::getMessage('GRAIN_IIKO_DELIVERYHANDLER_PERIOD',array('#MIN#'=>$result['result']['deliveryDurationInMinutes']))); } } else { $calculationResult->addError(new Error(Loc::getMessage('GRAIN_IIKO_DELIVERYHANDLER_ERROR_CANT_CALCULATE'))); } return $calculationResult; } }