From f29c0f62a404b20f275c59c378041f081a27c53a Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Mon, 9 Sep 2013 16:49:08 +0400 Subject: [PATCH] fio parsing fix --- .../classes/general/ICrmOrderActions.php | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/intaro.intarocrm/classes/general/ICrmOrderActions.php b/intaro.intarocrm/classes/general/ICrmOrderActions.php index c0c970ce..7d3011b4 100755 --- a/intaro.intarocrm/classes/general/ICrmOrderActions.php +++ b/intaro.intarocrm/classes/general/ICrmOrderActions.php @@ -538,6 +538,7 @@ class ICrmOrderActions $resOrder = array(); $resOrderDeliveryAddress = array(); + $contactNameArr = array(); $rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID'])); while ($ar = $rsOrderProps->Fetch()) { @@ -553,7 +554,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; @@ -592,10 +593,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'], @@ -612,7 +610,16 @@ 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]; + } if(isset($arParams['optionsSites']) && is_array($arParams['optionsSites']) && in_array($arFields['LID'], $arParams['optionsSites'])) @@ -672,4 +679,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; + } } \ No newline at end of file