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/ilovecveti.ru/bitrix/modules/grain.iiko/lib/rest/compatibility/ |
Upload File : |
<?php namespace Grain\Iiko\Rest\Compatibility; class v0tov1 { public static function dishes($result,$organizationId) { if(array_key_exists('error', $result) || !is_array($result['result'])) return $result; if(is_array($result['result']['products'])) { foreach($result['result']['products'] as &$product) { // images if(is_array($product['images'])) { $product['imageLinks'] = array(); foreach($product['images'] as $image) { $product['imageLinks'][] = $image['imageUrl']; } unset($product['images']); } // /images // types switch($product['type']) { case 'modifier': $product['type'] = 'Modifier'; break; case 'dish': $product['type'] = 'Dish'; break; } // /types // prices if(array_key_exists('price', $product)) { $product['sizePrices'] = array( 0 => array ( 'sizeId' => NULL, 'price' => array ( 'currentPrice' => $product['price'], 'isIncludedInMenu' => true, 'nextPrice' => NULL, 'nextIncludedInMenu' => false, 'nextDatePrice' => NULL, ), ), ); unset($product['price']); } // /prices // modifiers if(is_array($product['groupModifiers'])) { foreach($product['groupModifiers'] as &$group) { if(array_key_exists('modifierId', $group)) { $group['id'] = $group['modifierId']; unset($group['modifierId']); } if(is_array($group['childModifiers'])) { foreach($group['childModifiers'] as &$mod) { if(array_key_exists('modifierId', $mod)) { $mod['id'] = $mod['modifierId']; unset($mod['modifierId']); } } unset($mod); } } unset($group); } if(is_array($product['modifiers'])) { foreach($product['modifiers'] as &$mod) { if(array_key_exists('modifierId', $mod)) { $mod['id'] = $mod['modifierId']; unset($mod['modifierId']); } } unset($mod); } // /modifiers // other $product['carbohydratesAmount'] = $product['carbohydrateAmount']; if(isset($product['carbohydrateAmount'])) unset($product['carbohydrateAmount']); $product['carbohydratesFullAmount'] = $product['carbohydrateFullAmount']; if(isset($product['carbohydrateFullAmount'])) unset($product['carbohydrateFullAmount']); // /other } unset($product); } if(is_array($result['result']['groups'])) { foreach($result['result']['groups'] as &$group) { if(is_array($group['images'])) { $group['imageLinks'] = array(); foreach($group['images'] as $image) { $group['imageLinks'][] = $image['imageUrl']; } unset($group['images']); } } unset($group); } return $result; } public static function cities($result,$organizationId) { if(array_key_exists('error', $result) || !is_array($result['result'])) return $result; $tmp = $result['result']; $result['result'] = array('cities'=>array(array('organizationId'=>$organizationId,'items'=>array()))); foreach($tmp as $tmpCity) { $city = $tmpCity['city']; if(array_key_exists('deleted', $city)) { $city['isDeleted'] = $city['deleted']; unset($city['deleted']); } $city['streets'] = array(); foreach($tmpCity['streets'] as $street) { if(array_key_exists('deleted', $street)) { $street['isDeleted'] = $street['deleted']; unset($street['deleted']); } if(array_key_exists('cityId', $street)) unset($street['cityId']); $city['streets'][] = $street; } $result['result']['cities'][0]['items'][] = $city; } return $result; } public static function terminalGroups($result,$organizationId) { if(array_key_exists('error', $result) || !is_array($result['result'])) return $result; $tmp = $result['result']; $result['result'] = array('terminalGroups'=>array(array('organizationId'=>$organizationId,'items'=>array()))); foreach($tmp['deliveryTerminals'] as $terminal) { $terminal['id'] = $terminal['deliveryTerminalId']; unset($terminal['deliveryTerminalId']); $result['result']['terminalGroups'][0]['items'][] = $terminal; } return $result; } public static function discounts($result,$organizationId) { if(array_key_exists('error', $result) || !is_array($result['result'])) return $result; if(is_array($result['result']['discounts'])) { foreach($result['result']['discounts'] as &$discount) { $mode = ''; foreach(explode("_",$discount['mode']) as $part) { $mode .= ucfirst(strtolower($part)); } $discount['mode'] = $mode; } unset($discount); } $result['result']['discounts'] = array( array( 'organizationId' => $organizationId, 'items' => $result['result']['discounts'], ) ); return $result; } public static function paymentTypes($result,$organizationId) { if(array_key_exists('error', $result) || !is_array($result['result'])) return $result; if(is_array($result['result']['paymentTypes'])) { foreach($result['result']['paymentTypes'] as &$paymentType) { if(array_key_exists('deleted', $paymentType)) { $paymentType['isDeleted'] = $paymentType['deleted']; unset($paymentType['deleted']); } } unset($paymentType); } return $result; } public static function loyalty($result,$organizationId) { if(array_key_exists('error', $result) || !is_array($result['result'])) return $result; if(is_array($result['result']['availablePayments'])) { foreach($result['result']['availablePayments'] as &$availablePayment) if(array_key_exists('walletInfos', $availablePayment)) unset($availablePayment['walletInfos']); unset($availablePayment); } if(is_array($result['result']['loyatyResult']['programResults'])) { $result['result']['loyaltyProgramResults'] = $result['result']['loyatyResult']['programResults']; unset($result['result']['loyatyResult']); foreach($result['result']['loyaltyProgramResults'] as &$loyaltyProgramResult) { if(array_key_exists('programId', $loyaltyProgramResult)) { $loyaltyProgramResult['marketingCampaignId'] = $loyaltyProgramResult['programId']; unset($loyaltyProgramResult['programId']); } if(is_array($loyaltyProgramResult['discounts'])) { foreach($loyaltyProgramResult['discounts'] as &$discount) { if(array_key_exists('productCode', $discount)) unset($discount['productCode']); if(array_key_exists('productName', $discount)) unset($discount['productName']); } unset($discount); } if(is_array($loyaltyProgramResult['combos'])) { $loyaltyProgramResult['availableComboSpecifications'] = $loyaltyProgramResult['combos']; unset($loyaltyProgramResult['combos']); } } unset($loyaltyProgramResult); } $result['result']['apiVersion'] = 0; return $result; } public static function walletBalances($result) { if(array_key_exists('error', $result) || !is_array($result['result'])) return $result; foreach($result['result']['walletBalances'] as &$wallet) { switch($wallet['wallet']['type']) { case 'IikoCard': $type = 2; break; default: $type = 1; break; } $wallet = array( 'id' => $wallet['wallet']['id'], 'name' => $wallet['wallet']['name'], 'type' => $type, 'balance' => $wallet['balance'], ); } unset($wallet); return $result; } }