From 0812440edc6bdbfd33b7f7577ab4a1113dcebc38 Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 9 Sep 2013 16:26:01 +0400 Subject: [PATCH] fixed fio parsing --- .../classes/general/ICrmOrderActions.php | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index b4e6e634..36cd518f 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -252,6 +252,7 @@ class ICrmOrderActions $resOrder = array(); $resOrderDeliveryAddress = array(); + $contactNameArr = array(); $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); while ($ar = $rsOrderProps->Fetch()) { @@ -267,7 +268,7 @@ class ICrmOrderActions $resOrderDeliveryAddress['city'] = self::toJSON($resOrderDeliveryAddress['city']['CITY_NAME_LANG']); } break; - case 'FIO': $resOrder['contactName'] = explode(" ", self::toJSON($ar['VALUE'])); + case 'FIO': $contactNameArr = self::explodeFIO($ar['VALUE']); break; case 'PHONE': $resOrder['phone'] = $ar['VALUE']; break; @@ -306,10 +307,7 @@ class ICrmOrderActions $createdAt = new \DateTime($arFields['DATE_INSERT']); $createdAt = $createdAt->format('Y-m-d H:i:s'); - $resOrder = self::clearArr(array( - 'lastName' => $resOrder['contactName'][0], - 'firstName' => $resOrder['contactName'][1], - 'patronymic' => $resOrder['contactName'][2], + $resOrder = array( 'phone' => $resOrder['phone'], 'email' => $resOrder['email'], 'deliveryCost' => $arFields['PRICE_DELIVERY'], @@ -326,7 +324,18 @@ class ICrmOrderActions 'createdAt' => $createdAt, 'deliveryAddress' => $resOrderDeliveryAddress, 'items' => $items - )); + ); + + // parse fio + if(count($contactNameArr) == 1) { + $resOrder['firstName'] = $contactNameArr[0]; + } else { + $resOrder['lastName'] = $contactNameArr['contactName'][0], + $resOrder['firstName'] = $contactNameArr['contactName'][1], + $resOrder['patronymic'] = $contactNameArr['contactName'][2], + } + + $resOrder = self::clearArr($resOrder); if($send) return $api->createOrder($resOrder); @@ -382,4 +391,17 @@ class ICrmOrderActions return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); } + + public static function expodeFIO($str) { + if(!$str) + return array(); + + $array = expolde(" ", ICrmOrderActions::toJSON($str), 3); + + foreach($array as &$ar) + if(!$ar) + unset($ar); + + return $array; + } }