diff --git a/CHANGELOG.md b/CHANGELOG.md index 9296fbb1..113add5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2020-07-14 v.5.4.0 +* Добавлена поддержка функционала смены клиента + ## 2020-05-04 v.5.3.2 * Исправлена кодировка в настройках модуля diff --git a/intaro.retailcrm/classes/general/AbstractBuilder.php b/intaro.retailcrm/classes/general/AbstractBuilder.php new file mode 100644 index 00000000..7dc7a063 --- /dev/null +++ b/intaro.retailcrm/classes/general/AbstractBuilder.php @@ -0,0 +1,61 @@ +dataCrm[$key]) && !empty($this->dataCrm[$key]) ? $this->dataCrm[$key] : $default; + } + + /** + * @param array $array + * @param string $key + * @param mixed $default + * @return mixed|null + */ + public function getValueArray($array, $key, $default = NULL) + { + return isset($this->dataCrm[$array][$key]) && !empty($this->dataCrm[$array][$key]) ? $this->dataCrm[$array][$key] : $default; + } + + /** + * @param array $array + * @param array $symbols + * @return array + */ + public function arrayClear(array $array, array $symbols = array('', 0, null)) + { + return array_diff($array, $symbols); + } + + /** + * @param $data + * @return array + */ + public function objectToArray($data) + { + return $this->arrayClear(json_decode(json_encode($data), true)); + } + + /** + * + * @param string|array|\SplFixedArray $str in utf-8 + * + * @return array|bool|\SplFixedArray|string $str in SITE_CHARSET + * @global $APPLICATION + */ + public function fromJSON($str) + { + global $APPLICATION; + + return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); + } +} diff --git a/intaro.retailcrm/classes/general/AddressBuilder.php b/intaro.retailcrm/classes/general/AddressBuilder.php new file mode 100644 index 00000000..ebc1b269 --- /dev/null +++ b/intaro.retailcrm/classes/general/AddressBuilder.php @@ -0,0 +1,70 @@ +customerAddress = new CustomerAddress(); + } + + /** + * @param array $dataCrm + * @return $this|RetailcrmBuilderInterface + */ + public function setDataCrm($dataCrm) + { + $this->dataCrm = $dataCrm; + return $this; + } + + /** + * @param $data + * @return $this + */ + public function setCustomerAddress($data) + { + $this->customerAddress = $data; + return $this; + } + + /** + * @return CustomerAddress + */ + public function getCustomerAddress() + { + return $this->customerAddress; + } + + public function build() + { + $this->customerAddress->setText($this->getValue('text')) + ->setNotes($this->getValue('notes')) + ->setBuilding($this->getValue('building')) + ->setBlock($this->getValue('block')) + ->setCity($this->getValue('city')) + ->setFlat($this->getValue('flat')) + ->setHouse($this->getValue('house')) + ->setFloor($this->getValue('floor')) + ->setCountry($this->getValue('countryIso')) + ->setIndex($this->getValue('index')) + ->setIntercomCode($this->getValue('intercomCode')) + ->setMetro($this->getValue('metro')) + ->setRegion($this->getValue('region')) + ->setStreet($this->getValue('street')); + + return $this; + } +} diff --git a/intaro.retailcrm/classes/general/CorporateCustomerBuilder.php b/intaro.retailcrm/classes/general/CorporateCustomerBuilder.php new file mode 100644 index 00000000..3176a01d --- /dev/null +++ b/intaro.retailcrm/classes/general/CorporateCustomerBuilder.php @@ -0,0 +1,260 @@ +customer = new Customer(); + $this->customerBuilder = new CustomerBuilder(); + $this->customerAddress = new CustomerAddress(); + $this->buyerProfile = new BuyerProfile(); + $this->addressBuilder = new AddressBuilder(); + } + + /** + * @param Customer $customer + * @return $this + */ + public function setCustomer($customer) + { + $this->customer = $customer; + return $this; + } + + /** + * @return Customer + */ + public function getCustomer() + { + return $this->customer; + } + + /** + * @param CustomerBuilder $customerBuilder + * @return $this + */ + public function setCustomerBuilder($customerBuilder) + { + $this->$customerBuilder = $customerBuilder; + return $this; + } + + /** + * @return CustomerBuilder + */ + public function getCustomerBuilder() + { + return $this->customerBuilder; + } + + /** + * @param CustomerAddress $customerAddress + * @return $this + */ + public function setCustomerAddress($customerAddress) + { + $this->customerAddress = $customerAddress; + return $this; + } + + /** + * @return CustomerAddress + */ + public function getCustomerAddress() + { + return $this->customerAddress; + } + + /** + * @param array $dataCrm + * @return $this + */ + public function setDataCrm($dataCrm) + { + $this->dataCrm = $dataCrm; + return $this; + } + + /** + * @param int $registeredUserID + * @return $this + */ + public function setRegisteredUserID($registeredUserID) + { + $this->registeredUserID = $registeredUserID; + return $this; + } + + /** + * @return bool + */ + public function getRegisterNewUser() + { + return $this->registerNewUser; + } + + /** + * @return int + */ + public function getRegisteredUserID() + { + return $this->registeredUserID; + } + + /** + * @param int $data + * @return $this + */ + public function setOrderCustomerExtId($data) + { + $this->orderCustomerExtId = $data; + + return $this; + } + + /** + * @return int + */ + public function getOrderCustomerExtId() + { + return $this->orderCustomerExtId; + } + + /** + * @param array $data + * @return $this + */ + public function setCorporateContact($data) + { + $this->corporateContact = $data; + + return $this; + } + + /** + * @return array + */ + public function getCorporateContact() + { + return $this->corporateContact; + } + + /** + * @return BuyerProfile + */ + public function getBuyerProfile() + { + return $this->buyerProfile; + } + + /** + * @param array $contragentTypes + * @return $this + */ + public function setContragentTypes($contragentTypes) + { + $this->contragentTypes = $contragentTypes; + + return $this; + } + + public function build() + { + if (isset($this->dataCrm['contact'])) { + $this->customerBuilder->setDataCrm($this->dataCrm['contact'])->build(); + $this->corporateContact = $this->customerBuilder->getCustomer(); + $this->customer = $this->customerBuilder->getCustomer(); + } else { + $this->corporateContact = null; + $this->customer = null; + } + + if (isset($this->dataCrm['company']['address'])) { + $this->buildAddress(); + } + + if (isset($this->dataCrm['company'])) { + $this->buildBuyerProfile(); + } + } + + public function buildBuyerProfile() + { + if (RetailCrmOrder::isOrderCorporate($this->dataCrm) && !empty($this->dataCrm['company'])) { + $this->buyerProfile->setName($this->dataCrm['company']['name']) + ->setUserId($this->dataCrm['contact']['externalId']) + ->setPersonTypeId($this->contragentTypes['legal-entity']); + } + } + + public function buildAddress() + { + if (isset($this->dataCrm['company']['address'])) { + $this->addressBuilder->setDataCrm($this->dataCrm['company']['address'])->build(); + $this->customerAddress = $this->addressBuilder->getCustomerAddress(); + } else { + $this->customerAddress = null; + } + } + + /** + * @param string $login + * @return $this + */ + public function setLogin($login) + { + $this->customerBuilder->setLogin($login); + + return $this; + } + + /** + * @param string $email + * @return $this + */ + public function setEmail($email) + { + $this->customerBuilder->setEmail($email); + + return $this; + } +} diff --git a/intaro.retailcrm/classes/general/CustomerBuilder.php b/intaro.retailcrm/classes/general/CustomerBuilder.php new file mode 100644 index 00000000..1f3b5031 --- /dev/null +++ b/intaro.retailcrm/classes/general/CustomerBuilder.php @@ -0,0 +1,238 @@ +customer = new Customer(); + $this->customerAddress = new CustomerAddress(); + $this->addressBuilder = new AddressBuilder(); + } + + /** + * @param Customer $customer + * @return $this + */ + public function setCustomer($customer) + { + $this->customer = $customer; + return $this; + } + + /** + * @return Customer + */ + public function getCustomer() + { + return $this->customer; + } + + /** + * @param CustomerAddress $customerAddress + * @return $this + */ + public function setCustomerAddress($customerAddress) + { + $this->customerAddress = $customerAddress; + return $this; + } + + /** + * @return CustomerAddress + */ + public function getCustomerAddress() + { + return $this->customerAddress; + } + + /** + * @param array $dataCrm + * @return $this + */ + public function setDataCrm($dataCrm) + { + $this->dataCrm = $dataCrm; + return $this; + } + + /** + * @param array $user + * @return $this + */ + public function setUser($user) + { + $this->user = $user; + return $this; + } + + /** + * @param int $registeredUserID + * @return $this + */ + public function setRegisteredUserID($registeredUserID) + { + $this->registeredUserID = $registeredUserID; + return $this; + } + + /** + * @return int + */ + public function getRegisteredUserID() + { + return $this->registeredUserID; + } + + /** + * @return bool + */ + public function getRegisterNewUser() + { + return $this->registerNewUser; + } + + public function build() + { + if (!empty($this->dataCrm['firstName'])) { + $this->customer->setName($this->fromJSON($this->dataCrm['firstName'])); + } + + if (!empty($this->dataCrm['lastName'])) { + $this->customer->setLastName($this->fromJSON($this->dataCrm['lastName'])); + } + + if (!empty($this->dataCrm['patronymic'])) { + $this->customer->setSecondName($this->fromJSON($this->dataCrm['patronymic'])); + } + + if (isset($this->dataCrm['phones'])) { + foreach ($this->dataCrm['phones'] as $phone) { + if (isset($phone['old_number']) && in_array($phone['old_number'], $this->user)) { + $key = array_search($phone['old_number'], $this->user); + + if (isset($phone['number'])) { + $this->user[$key] = $phone['number']; + } else { + $this->user[$key] = ''; + } + } + + if (isset($phone['number'])) { + if ((!isset($this->user['PERSONAL_PHONE']) || strlen($this->user['PERSONAL_PHONE']) == 0) + && $this->user['PERSONAL_MOBILE'] != $phone['number'] + ) { + $this->customer->setPersonalPhone($phone['number']); + $this->user['PERSONAL_PHONE'] = $phone['number']; + continue; + } + if ((!isset($this->user['PERSONAL_MOBILE']) || strlen($this->user['PERSONAL_MOBILE']) == 0) + && $this->user['PERSONAL_PHONE'] != $phone['number'] + ) { + $this->customer->setPersonalMobile($phone['number']); + $this->user['PERSONAL_MOBILE'] = $phone['number']; + continue; + } + } + } + } + + if (!empty($this->dataCrm['address']['index'])) { + $this->customer->setPersonalZip($this->fromJSON($this->dataCrm['address']['index'])); + } + + if (!empty($this->dataCrm['address']['city'])) { + $this->customer->setPersonalCity($this->fromJSON($this->dataCrm['address']['city'])); + } + + if (!empty($this->dataCrm['birthday'])) { + $this->customer->setPersonalBirthday($this->fromJSON( + date("d.m.Y", strtotime($this->dataCrm['birthday'])) + )); + } + + if (!empty($this->dataCrm['email'])) { + $this->customer->setEmail($this->fromJSON($this->dataCrm['email'])); + } + + if (!empty($this->dataCrm['sex'])) { + $this->customer->setPersonalGender($this->fromJSON($this->dataCrm['sex'])); + } + + if (empty($this->dataCrm['externalId'])) { + $userPassword = uniqid("R"); + $this->customer->setPassword($userPassword) + ->setConfirmPassword($userPassword); + } + + if ((!isset($this->dataCrm['email']) || $this->dataCrm['email'] == '') + && (!isset($this->dataCrm['externalId'])) + ) { + $login = uniqid('user_' . time()) . '@example.com'; + $this->customer->setLogin($login) + ->setEmail($login); + } + + if (isset($this->dataCrm['address'])) { + $this->buildAddress(); + } + } + + public function buildAddress() + { + if (isset($this->dataCrm['address'])) { + $this->addressBuilder->setDataCrm($this->dataCrm['address'])->build(); + $this->customerAddress = $this->addressBuilder->getCustomerAddress(); + } else { + $this->customerAddress = null; + } + } + + /** + * @param string $login + * @return $this + */ + public function setLogin($login) + { + $this->customer->setLogin($login); + + return $this; + } + + /** + * @param string $email + * @return $this + */ + public function setEmail($email) + { + $this->customer->setEmail($email); + + return $this; + } +} diff --git a/intaro.retailcrm/classes/general/Model/BaseModel.php b/intaro.retailcrm/classes/general/Model/BaseModel.php new file mode 100644 index 00000000..da0a0ce4 --- /dev/null +++ b/intaro.retailcrm/classes/general/Model/BaseModel.php @@ -0,0 +1,38 @@ +arrayClear(call_user_func('get_object_vars', $this)); + } + + /** + * @param array $array + * @param array $symbols + * @return array + */ + public function arrayClear(array $array, array $symbols = array('', 0, null)) + { + return array_diff($array, $symbols); + } + + /** + * @param $array + * @return $this + */ + public function getArrayToObject($array) + { + foreach ($array as $key => $value) { + $this->$key = $value; + } + + return $this; + } +} diff --git a/intaro.retailcrm/classes/general/Model/BuyerProfile.php b/intaro.retailcrm/classes/general/Model/BuyerProfile.php new file mode 100644 index 00000000..9c01fb77 --- /dev/null +++ b/intaro.retailcrm/classes/general/Model/BuyerProfile.php @@ -0,0 +1,48 @@ +NAME = $NAME; + + return $this; + } + + /** + * @param int $USER_ID + * @return $this + */ + public function setUserId($USER_ID) + { + $this->USER_ID = $USER_ID; + + return $this; + } + + /** + * @param int $PERSON_TYPE_ID + * @return $this + */ + public function setPersonTypeId($PERSON_TYPE_ID) + { + $this->PERSON_TYPE_ID = $PERSON_TYPE_ID; + + return $this; + } +} diff --git a/intaro.retailcrm/classes/general/Model/Customer.php b/intaro.retailcrm/classes/general/Model/Customer.php new file mode 100644 index 00000000..d569f77e --- /dev/null +++ b/intaro.retailcrm/classes/general/Model/Customer.php @@ -0,0 +1,202 @@ +EMAIL = $EMAIL; + + return $this; + } + + /** + * @param string $LOGIN + * @return $this + */ + public function setLogin($LOGIN) + { + $this->LOGIN = $LOGIN; + + return $this; + } + + /** + * @param string $ACTIVE + * @return $this + */ + public function setActive($ACTIVE) + { + $this->ACTIVE = $ACTIVE; + + return $this; + } + + /** + * @param string $PASSWORD + * @return $this + */ + public function setPassword($PASSWORD) + { + $this->PASSWORD = $PASSWORD; + + return $this; + } + + /** + * @param string $CONFIRM_PASSWORD + * @return $this + */ + public function setConfirmPassword($CONFIRM_PASSWORD) + { + $this->CONFIRM_PASSWORD = $CONFIRM_PASSWORD; + + return $this; + } + + /** + * @param string $NAME + * @return $this + */ + public function setName($NAME) + { + $this->NAME = $NAME; + + return $this; + } + + /** + * @param string $LAST_NAME + * @return $this + */ + public function setLastName($LAST_NAME) + { + $this->LAST_NAME = $LAST_NAME; + + return $this; + } + + /** + * @param string $SECOND_NAME + * @return $this + */ + public function setSecondName($SECOND_NAME) + { + $this->SECOND_NAME = $SECOND_NAME; + + return $this; + } + + /** + * @param string $PERSONAL_MOBILE + * @return $this + */ + public function setPersonalMobile($PERSONAL_MOBILE) + { + $this->PERSONAL_MOBILE = $PERSONAL_MOBILE; + + return $this; + } + + /** + * @param string $PERSONAL_PHONE + * @return $this + */ + public function setPersonalPhone($PERSONAL_PHONE) + { + $this->PERSONAL_PHONE = $PERSONAL_PHONE; + + return $this; + } + + /** + * @param string $PERSONAL_ZIP + * @return $this + */ + public function setPersonalZip($PERSONAL_ZIP) + { + $this->PERSONAL_ZIP = $PERSONAL_ZIP; + + return $this; + } + + /** + * @param string $PERSONAL_CITY + * @return $this + */ + public function setPersonalCity($PERSONAL_CITY) + { + $this->PERSONAL_CITY = $PERSONAL_CITY; + + return $this; + } + + /** + * @param string $PERSONAL_BIRTHDAY + * @return $this + */ + public function setPersonalBirthday($PERSONAL_BIRTHDAY) + { + $this->PERSONAL_BIRTHDAY = $PERSONAL_BIRTHDAY; + + return $this; + } + + /** + * @param string $PERSONAL_GENDER + * @return $this + */ + public function setPersonalGender($PERSONAL_GENDER) + { + $this->PERSONAL_GENDER = $PERSONAL_GENDER; + + return $this; + } +} diff --git a/intaro.retailcrm/classes/general/Model/CustomerAddress.php b/intaro.retailcrm/classes/general/Model/CustomerAddress.php new file mode 100644 index 00000000..c229091d --- /dev/null +++ b/intaro.retailcrm/classes/general/Model/CustomerAddress.php @@ -0,0 +1,202 @@ +index = $index; + + return $this; + } + + /** + * @param string $country + * @return $this + */ + public function setCountry($country) + { + $this->country = $country; + + return $this; + } + + /** + * @param string $region + * @return $this + */ + public function setRegion($region) + { + $this->region = $region; + + return $this; + } + + /** + * @param string $city + * @return $this + */ + public function setCity($city) + { + $this->city = $city; + + return $this; + } + + /** + * @param string $street + * @return $this + */ + public function setStreet($street) + { + $this->street = $street; + + return $this; + } + + /** + * @param string $building + * @return $this + */ + public function setBuilding($building) + { + $this->building = $building; + + return $this; + } + + /** + * @param string $house + * @return $this + */ + public function setHouse($house) + { + $this->house = $house; + + return $this; + } + + /** + * @param string $block + * @return $this + */ + public function setBlock($block) + { + $this->block = $block; + + return $this; + } + + /** + * @param string $flat + * @return $this + */ + public function setFlat($flat) + { + $this->flat = $flat; + + return $this; + } + + /** + * @param string $floor + * @return $this + */ + public function setFloor($floor) + { + $this->floor = $floor; + + return $this; + } + + /** + * @param string $intercomCode + * @return $this + */ + public function setIntercomCode($intercomCode) + { + $this->intercomCode = $intercomCode; + + return $this; + } + + /** + * @param string $metro + * @return $this + */ + public function setMetro($metro) + { + $this->metro = $metro; + + return $this; + } + + /** + * @param string $notes + * @return $this + */ + public function setNotes($notes) + { + $this->notes = $notes; + + return $this; + } + + /** + * @param string $text + * @return $this + */ + public function setText($text) + { + $this->text = $text; + + return $this; + } +} diff --git a/intaro.retailcrm/classes/general/Model/CustomerContragent.php b/intaro.retailcrm/classes/general/Model/CustomerContragent.php new file mode 100644 index 00000000..ff213d09 --- /dev/null +++ b/intaro.retailcrm/classes/general/Model/CustomerContragent.php @@ -0,0 +1,132 @@ +contragentType = $contragentType; + + return $this; + } + + /** + * @param string $legalName + * @return $this + */ + public function setLegalName($legalName) + { + $this->legalName = $legalName; + + return $this; + } + + /** + * @param string $legalAddress + * @return $this + */ + public function setLegalAddress($legalAddress) + { + $this->legalAddress = $legalAddress; + + return $this; + } + + /** + * @param string $certificateNumber + * @return $this + */ + public function setCertificateNumber($certificateNumber) + { + $this->certificateNumber = $certificateNumber; + + return $this; + } + + /** + * @param string $certificateDate + * @return $this + */ + public function setCertificateDate($certificateDate) + { + $this->certificateDate = $certificateDate; + + return $this; + } + + /** + * @param string $bank + * @return $this + */ + public function setBank($bank) + { + $this->bank = $bank; + + return $this; + } + + /** + * @param string $bankAddress + * @return $this + */ + public function setBankAddress($bankAddress) + { + $this->bankAddress = $bankAddress; + + return $this; + } + + /** + * @param string $corrAccount + * @return $this + */ + public function setCorrAccount($corrAccount) + { + $this->corrAccount = $corrAccount; + + return $this; + } + + /** + * @param string $bankAccount + * @return $this + */ + public function setBankAccount($bankAccount) + { + $this->bankAccount = $bankAccount; + + return $this; + } +} diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index ace42c0c..450b8d7f 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -454,6 +454,8 @@ class RCrmActions case 'customersEdit': case 'customersСorporateGet': return self::proxy($api, $methodApi, $method, array($params, 'externalId', $site)); + case 'customersСorporateGetById': + return self::proxy($api, 'customersСorporateGet', $method, array($params, 'id', $site)); case 'customersGetById': return self::proxy($api, 'customersGet', $method, array($params, 'id', $site)); diff --git a/intaro.retailcrm/classes/general/RetailcrmBuilderInterface.php b/intaro.retailcrm/classes/general/RetailcrmBuilderInterface.php new file mode 100644 index 00000000..9757dbb6 --- /dev/null +++ b/intaro.retailcrm/classes/general/RetailcrmBuilderInterface.php @@ -0,0 +1,20 @@ +certificateDate bank bankAddress + INN + OKPO + KPP + OGRN + OGRNIP + certificateNumber + certificateDate + BIK corrAccount bankAccount diff --git a/intaro.retailcrm/classes/general/config/retailcrm.json b/intaro.retailcrm/classes/general/config/retailcrm.json index f9000881..ff2c144f 100644 --- a/intaro.retailcrm/classes/general/config/retailcrm.json +++ b/intaro.retailcrm/classes/general/config/retailcrm.json @@ -84,6 +84,10 @@ "type": "bool", "default": false }, + "subscribed": { + "type": "bool", + "default": false + }, "commentary": { "type": "string" }, diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php index 416bff1b..956cbf8b 100644 --- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php +++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php @@ -287,9 +287,9 @@ class RetailCrmEvent ); return false; - } else { - $userCrm = array('customer' => array('externalId' => $arOrder['USER_ID'])); } + + $userCrm = array('customer' => array('externalId' => $arOrder['USER_ID'])); } if (!isset($userCorp['customerCorporate'])) { @@ -352,23 +352,29 @@ class RetailCrmEvent ); if (!empty($companyResult)) { + $orderCompany = array( + 'id' => $companyResult['id'] + ); + $customerCorporateContact['companies'] = array( array( - 'company' => array( - 'id' => $companyResult['id'] - ) + 'company' => $orderCompany ) ); } - $contactResult = $api->customersCorporateContactsCreate( + $api->customersCorporateContactsCreate( $resultUserCorp['id'], $customerCorporateContact, 'id', $site ); - } else { + $arParams['orderCompany'] = array_merge( + $customerCorporateCompany, + array('id' => $companyResult['id']) + ); + } else { RetailCrmCorporateClient::addCustomersCorporateAddresses( $userCorp['customerCorporate']['id'], $nickName, diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index 83c74f2b..0e2a5683 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -18,7 +18,6 @@ class RetailCrmHistory public static $CRM_CONTRAGENT_TYPE = 'contragent_type'; public static $CRM_ORDER_FAILED_IDS = 'order_failed_ids'; public static $CRM_ORDER_HISTORY = 'order_history'; - public static $CRM_CUSTOMER_HISTORY = 'customer_history'; public static $CRM_CUSTOMER_CORPORATE_HISTORY = 'customer_corp_history'; public static $CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; public static $CRM_ORDER_NUMBERS = 'order_numbers'; @@ -34,13 +33,9 @@ class RetailCrmHistory return false; } - $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); - $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); - - $api = new RetailCrm\ApiClient($api_host, $api_key); - $historyFilter = array(); - $historyStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_CUSTOMER_HISTORY); + $historyStart = RetailcrmConfigProvider::getCustomersHistorySinceId(); + $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); if ($historyStart && $historyStart > 0) { $historyFilter['sinceId'] = $historyStart; @@ -68,6 +63,7 @@ class RetailCrmHistory $GLOBALS['RETAIL_CRM_HISTORY'] = true; $newUser = new CUser(); + $customerBuilder = new CustomerBuilder(); foreach ($customers as $customer) { if (function_exists('retailCrmBeforeCustomerSave')) { @@ -89,6 +85,8 @@ class RetailCrmHistory unset($customer['externalId']); } + $customerBuilder->setDataCrm($customer)->build(); + if (!isset($customer['externalId'])) { if (!isset($customer['id'])) { continue; @@ -96,14 +94,12 @@ class RetailCrmHistory $registerNewUser = true; - if (!isset($customer['email']) || $customer['email'] == '') { - $login = uniqid('user_' . time()) . '@crm.com'; - $customer['email'] = $login; - } else { + if (!empty($customer['email'])) { $dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $customer['email'])); switch ($dbUser->SelectedRowsCount()) { case 0: $login = $customer['email']; + $customerBuilder->setLogin($login); break; case 1: $arUser = $dbUser->Fetch(); @@ -111,22 +107,16 @@ class RetailCrmHistory $registerNewUser = false; break; default: - $login = uniqid('user_' . time()) . '@crm.com'; + $login = uniqid('user_' . time()) . '@example.com'; + $customerBuilder->setLogin($login); break; } } if ($registerNewUser === true) { - $userPassword = uniqid("R"); - - $arFields = array( - "EMAIL" => $customer['email'], - "LOGIN" => $login, - "ACTIVE" => "Y", - "PASSWORD" => $userPassword, - "CONFIRM_PASSWORD" => $userPassword + $registeredUserID = $newUser->Add( + $customerBuilder->getCustomer()->getObjectToArray() ); - $registeredUserID = $newUser->Add($arFields); if ($registeredUserID === false) { RCrmActions::eventLog( @@ -139,10 +129,10 @@ class RetailCrmHistory } if(RCrmActions::apiMethod( - $api, - 'customersFixExternalIds', - __METHOD__, - array(array('id' => $customer['id'], 'externalId' => $registeredUserID))) == false + $api, + 'customersFixExternalIds', + __METHOD__, + array(array('id' => $customer['id'], 'externalId' => $registeredUserID))) == false ) { continue; } @@ -152,84 +142,19 @@ class RetailCrmHistory } if (isset($customer['externalId'])) { - $arUser = array(); - if (array_key_exists('firstName', $customer)) { - $arUser["NAME"] = $customer['firstName'] - ? RCrmActions::fromJSON($customer['firstName']) : ''; - } - if (array_key_exists('lastName', $customer)) { - $arUser["LAST_NAME"] = $customer['lastName'] - ? RCrmActions::fromJSON($customer['lastName']) : ''; - } - if (array_key_exists('patronymic', $customer)) { - $arUser["SECOND_NAME"] = $customer['patronymic'] - ? RCrmActions::fromJSON($customer['patronymic']) : ''; - } - -// if (array_key_exists('email', $customer)) { -// $arUser["EMAIL"] = $customer['email'] ? RCrmActions::fromJSON($customer['email']) : ''; -// } - + $customerBuilder->setDataCrm($customer); if (isset($customer['phones'])) { - $user = CUser::GetList( - ($by = "ID"), - ($order = "desc"), - array('ID' => $customer['externalId']), - array('FIELDS' => array('PERSONAL_PHONE', 'PERSONAL_MOBILE')) - )->fetch(); - - foreach ($customer['phones'] as $phone) { - if (isset($phone['old_number']) && in_array($phone['old_number'], $user)) { - $key = array_search($phone['old_number'], $user); - if (isset($phone['number'])) { - $arUser[$key] = $phone['number']; - $user[$key] = $phone['number']; - } else { - $arUser[$key] = ''; - $user[$key] = ''; - } - } - - if (isset($phone['number'])) { - if ((!isset($user['PERSONAL_PHONE']) || strlen($user['PERSONAL_PHONE']) == 0) - && $user['PERSONAL_MOBILE'] != $phone['number'] - ) { - $arUser['PERSONAL_PHONE'] = $phone['number']; - $user['PERSONAL_PHONE'] = $phone['number']; - continue; - } - if ((!isset($user['PERSONAL_MOBILE']) || strlen($user['PERSONAL_MOBILE']) == 0) - && $user['PERSONAL_PHONE'] != $phone['number'] - ) { - $arUser['PERSONAL_MOBILE'] = $phone['number']; - $user['PERSONAL_MOBILE'] = $phone['number']; - continue; - } - } - } - } - if (array_key_exists('index', $customer['address'])) { - $arUser["PERSONAL_ZIP"] = $customer['address']['index'] - ? RCrmActions::fromJSON($customer['address']['index']) : ''; - } - if (array_key_exists('city', $customer['address'])) { - $arUser["PERSONAL_CITY"] = $customer['address']['city'] - ? RCrmActions::fromJSON($customer['address']['city']) : ''; + $customerBuilder->setUser( + CUser::GetList( + ($by = "ID"), + ($order = "desc"), + array('ID' => $customer['externalId']), + array('FIELDS' => array('PERSONAL_PHONE', 'PERSONAL_MOBILE')) + )->fetch() + ); } - if (array_key_exists('birthday', $customer)) { - $arUser["PERSONAL_BIRTHDAY"] = date("d.m.Y", strtotime($customer['birthday'])); - } - - if (array_key_exists('email', $customer)) { - $arUser["EMAIL"] = $customer['email'] ? RCrmActions::fromJSON($customer['email']) : ''; - } - - if (array_key_exists('sex', $customer)) { - $arUser["PERSONAL_GENDER"] = $customer['sex'] ? RCrmActions::fromJSON($customer['sex']) : ''; - } - - $u = $newUser->Update($customer['externalId'], $arUser); + $u = $newUser->Update($customer['externalId'], $customerBuilder->getCustomer()->getObjectToArray()); if (!$u) { RCrmActions::eventLog( 'RetailCrmHistory::customerHistory', @@ -248,7 +173,7 @@ class RetailCrmHistory //last id $end = array_pop($customerH); - COption::SetOptionString(self::$MODULE_ID, self::$CRM_CUSTOMER_HISTORY, $end['id']); + RetailcrmConfigProvider::setCustomersHistorySinceId($end['id']); if ($customerHistory['pagination']['totalPageCount'] == 1) { return true; @@ -379,17 +304,27 @@ class RetailCrmHistory unset($order['customer']['externalId']); } + $corporateCustomerBuilder = new CorporateCustomerBuilder(); + $corporateContact = array(); $orderCustomerExtId = isset($order['customer']['externalId']) ? $order['customer']['externalId'] : null; + $corporateCustomerBuilder->setOrderCustomerExtId($orderCustomerExtId) + ->setContragentTypes($contragentTypes) + ->setDataCrm($order) + ->build(); if (RetailCrmOrder::isOrderCorporate($order)) { // Fetch contact only if we think it's data is not fully present in order if (!empty($order['contact'])) { if (isset($order['contact']['email'])) { $corporateContact = $order['contact']; + $orderCustomerExtId = isset($corporateContact['externalId']) ? $corporateContact['externalId'] : null; + $corporateCustomerBuilder->setCorporateContact($corporateContact) + ->setOrderCustomerExtId($orderCustomerExtId); + } else { $response = false; @@ -413,9 +348,12 @@ class RetailCrmHistory if ($response && isset($response['customer'])) { $corporateContact = $response['customer']; + $orderCustomerExtId = isset($corporateContact['externalId']) ? $corporateContact['externalId'] : null; + $corporateCustomerBuilder->setCorporateContact($corporateContact) + ->setOrderCustomerExtId($orderCustomerExtId); } } } @@ -437,9 +375,13 @@ class RetailCrmHistory if (RetailCrmOrder::isOrderCorporate($order) && !empty($corporateContact['email'])) { $login = $corporateContact['email']; $order['customer']['email'] = $corporateContact['email']; + $corporateCustomerBuilder->setLogin($login) + ->setEmail($corporateContact['email']); } else { - $login = uniqid('user_' . time()) . '@crm.com'; + $login = uniqid('user_' . time()) . '@example.com'; $order['customer']['email'] = $login; + $corporateCustomerBuilder->setLogin($login) + ->setEmail($login); } } @@ -452,6 +394,7 @@ class RetailCrmHistory switch ($dbUser->SelectedRowsCount()) { case 0: $login = $order['customer']['email']; + $corporateCustomerBuilder->setLogin($login); break; case 1: $arUser = $dbUser->Fetch(); @@ -459,38 +402,23 @@ class RetailCrmHistory $registerNewUser = false; break; default: - $login = uniqid('user_' . time()) . '@crm.com'; + $login = uniqid('user_' . time()) . '@example.com'; + $corporateCustomerBuilder->setLogin($login); break; } if ($registerNewUser === true) { - $userPassword = uniqid("R"); $userData = RetailCrmOrder::isOrderCorporate($order) ? $corporateContact : $order['customer']; + $corporateCustomerBuilder->setCorporateContact($userData); + $newUser = new CUser(); - $arFields = array( - "NAME" => RCrmActions::fromJSON($userData['firstName']), - "LAST_NAME" => RCrmActions::fromJSON($userData['lastName']), - "SECOND_NAME" => RCrmActions::fromJSON($userData['patronymic']), - "EMAIL" => $order['customer']['email'], - "LOGIN" => $login, - "ACTIVE" => "Y", - "PASSWORD" => $userPassword, - "CONFIRM_PASSWORD" => $userPassword + $registeredUserID = $newUser->Add( + $corporateCustomerBuilder->getCustomer()->getObjectToArray() ); - if ($userData['phones'][0]) { - $arFields['PERSONAL_PHONE'] = $userData['phones'][0]; - } - - if ($userData['phones'][1]) { - $arFields['PERSONAL_MOBILE'] = $userData['phones'][1]; - } - - $registeredUserID = $newUser->Add($arFields); - if ($registeredUserID === false) { RCrmActions::eventLog( 'RetailCrmHistory::orderHistory', @@ -502,30 +430,26 @@ class RetailCrmHistory } if(RCrmActions::apiMethod( - $api, - 'customersFixExternalIds', - __METHOD__, - array(array( - 'id' => $order['customer']['id'], - 'externalId' => $registeredUserID - ))) == false + $api, + 'customersFixExternalIds', + __METHOD__, + array(array( + 'id' => $order['customer']['id'], + 'externalId' => $registeredUserID + ))) == false ) { continue; } } $orderCustomerExtId = isset($registeredUserID) ? $registeredUserID : null; + $corporateCustomerBuilder->setOrderCustomerExtId($orderCustomerExtId); } $buyerProfileToAppend = array(); if (RetailCrmOrder::isOrderCorporate($order) && !empty($order['company'])) { - $buyerProfile = array( - "NAME" => $order['company']['name'], - "USER_ID" => $order['contact']['externalId'], - "PERSON_TYPE_ID" => $contragentTypes['legal-entity'] - ); - + $buyerProfile = $corporateCustomerBuilder->getBuyerProfile()->getObjectToArray(); $buyerProfileToAppend = Bitrix\Sale\OrderUserProperties::getList(array( "filter" => $buyerProfile ))->fetch(); @@ -614,15 +538,19 @@ class RetailCrmHistory $propsRemove = false; $personType = $newOrder->getField('PERSON_TYPE_ID'); - if (RetailCrmOrder::isOrderCorporate($order)) { - $newOrder->setField('PERSON_TYPE_ID', $contragentTypes['legal-entity']); + if (RetailCrmOrder::isOrderCorporate($order) + || (!empty($order['contragentType']) && $order['contragentType'] == 'legal-entity') + ) { $personType = $contragentTypes['legal-entity']; + $newOrder->setField('PERSON_TYPE_ID', $personType); + + $propsRemove = true; } else { if (isset($order['orderType']) && $order['orderType']) { $nType = array(); $tList = RCrmActions::OrderTypesList(array(array('LID' => $site))); - foreach($tList as $type){ + foreach ($tList as $type) { if (isset($optionsOrderTypes[$type['ID']])) { $nType[$optionsOrderTypes[$type['ID']]] = $type['ID']; } @@ -747,6 +675,8 @@ class RetailCrmHistory } } + $order['fio'] = str_replace("clear", "", $order['fio']); + //optionsOrderProps if ($optionsOrderProps[$personType]) { foreach ($optionsOrderProps[$personType] as $key => $orderProp) { @@ -833,6 +763,12 @@ class RetailCrmHistory } } + if (isset($order['company']['id'])) { + if (!empty($order['company']['name'])) { + $order["legalName"] = $order['company']['name']; + } + } + // Corporate clients section if ($optionsLegalDetails[$personType]) { foreach ($optionsLegalDetails[$personType] as $key => $orderProp) { @@ -864,8 +800,8 @@ class RetailCrmHistory RCrmActions::fromJSON( $key == 'legalAddress' ? (isset($order['company']['address']['text']) - ? $order['company']['address']['text'] - : '') + ? $order['company']['address']['text'] + : '') : $order['company'][$key] ) ); @@ -906,6 +842,84 @@ class RetailCrmHistory $basket->setFUserId($fUserId); } + if (isset($order['contact']['id'])) { + $ExtId = null; + $response = RCrmActions::apiMethod( + $api, + 'customersGetById', + __METHOD__, + $order['contact']['id'], + $order['site'] + ); + + if (isset($order['contact']['externalId'])) { + $ExtId = $order['contact']['externalId']; + } + + if (isset($ExtId)) { + $newOrder->setFieldNoDemand('USER_ID', $ExtId); + } else { + $newUser = new CUser(); + $customerBuilder = new CustomerBuilder(); + $customerBuilder->setDataCrm($response['customer'])->build(); + + if (!empty($response['customer']['email'])) { + $registerNewUser = true; + $dbUser = CUser::GetList( + ($by = 'ID'), + ($sort = 'ASC'), + array('=EMAIL' => $response['customer']['email']) + ); + + switch ($dbUser->SelectedRowsCount()) { + case 0: + $login = $response['customer']['email']; + $customerBuilder->setLogin($login); + break; + case 1: + $arUser = $dbUser->Fetch(); + $registeredUserID = $arUser['ID']; + $registerNewUser = false; + break; + default: + $login = uniqid('user_' . time()) . '@example.com'; + $customerBuilder->setLogin($login); + break; + } + + if ($registerNewUser === true) { + $registeredUserID = $newUser->Add( + $customerBuilder->getCustomer()->getObjectToArray() + ); + if ($registeredUserID === false) { + RCrmActions::eventLog( + 'RetailCrmHistory::orderHistory', + 'CUser::Register', + 'Error register user: ' . $newUser->LAST_ERROR + ); + + continue; + } + + if(RCrmActions::apiMethod( + $api, + 'customersFixExternalIds', + __METHOD__, + array(array( + 'id' => $response['customer']['id'], + 'externalId' => $registeredUserID + )) + ) == false + ) { + continue; + } + } + + $newOrder->setFieldNoDemand('USER_ID', $registeredUserID); + } + } + } + if (isset($order['items'])) { $itemUpdate = true; $response = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']); @@ -1146,10 +1160,10 @@ class RetailCrmHistory $order["externalId"] = $newOrder->getId(); if (RCrmActions::apiMethod( - $api, - 'ordersFixExternalIds', - __METHOD__, - array(array('id' => $order['id'], 'externalId' => $newOrder->getId()))) == false + $api, + 'ordersFixExternalIds', + __METHOD__, + array(array('id' => $order['id'], 'externalId' => $newOrder->getId()))) == false ) { continue; } @@ -1300,6 +1314,18 @@ class RetailCrmHistory $orders[$change['order']['id']]['number'] = $change['newValue']; } + if (isset($change['oldValue']) && $change['field'] == 'customer') { + $orders[$change['order']['id']]['customer'] = $change['newValue']; + } + + if (isset($change['oldValue']) && $change['field'] == 'contact') { + $orders[$change['order']['id']]['contact'] = $change['newValue']; + } + + if (isset($change['oldValue']) && $change['field'] == 'company') { + $orders[$change['order']['id']]['company'] = $change['newValue']; + } + if ($change['order']['payments']) { $payments = array(); foreach ($change['order']['payments'] as $payment) { @@ -1380,6 +1406,24 @@ class RetailCrmHistory $orders[$change['order']['id']]['deleted'] = 1; } } + + if ($change['field'] == 'last_name') { + if (true == is_null($change['newValue'])) { + $orders[$change['order']['id']]['lastName'] = 'clear'; + } + } + + if ($change['field'] == 'first_Name') { + if (true == is_null($change['newValue'])) { + $orders[$change['order']['id']]['firstName'] = 'clear'; + } + } + + if ($change['field'] == 'patronymic') { + if (true == is_null($change['newValue'])) { + $orders[$change['order']['id']]['patronymic'] = 'clear'; + } + } } return $orders; diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index 4d1d3f23..b900eb8a 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -92,6 +92,11 @@ class RetailCrmOrder if ($search == 'fio') { $order = array_merge($order, RCrmActions::explodeFIO($prop['VALUE'][0]));//add fio fields } else { + // ignoring a property with a non-set group if the field value is already set + if (!empty($order[$search]) && $prop['PROPS_GROUP_ID'] == 0) { + continue; + } + $order[$search] = $prop['VALUE'][0];//phone, email } } else {//address @@ -157,9 +162,11 @@ class RetailCrmOrder //basket foreach ($arFields['BASKET'] as $position => $product) { $externalId = $position . "_" . $product['PRODUCT_ID']; + if (isset($orderItems[$externalId])) { //update $externalIds = $orderItems[$externalId]['externalIds']; $itemId = $orderItems[$externalId]['id']; + $key = array_search("bitrix", array_column($externalIds, 'code')); if ($externalIds[$key]['code'] == "bitrix") { $externalIds[$key] = array( @@ -184,7 +191,8 @@ class RetailCrmOrder $item = array( 'externalIds' => $externalIds, 'quantity' => $product['QUANTITY'], - 'offer' => array('externalId' => $product['PRODUCT_ID'], + 'offer' => array( + 'externalId' => $product['PRODUCT_ID'], 'xmlId' => $product['PRODUCT_XML_ID'] ), 'productName' => $product['NAME'] @@ -433,6 +441,7 @@ class RetailCrmOrder $arParams['orderCompany'] = isset($arCustomerCorporate['companies']) ? reset($arCustomerCorporate['companies']) : null; + $arParams['contactExId'] = $user['ID']; } else { $arCustomer = RetailCrmUser::customerSend( @@ -465,6 +474,7 @@ class RetailCrmOrder $resCustomers[$order['LID']][] = $arCustomer; } + $resCustomers[$order['LID']][] = $arCustomer; $resOrders[$order['LID']][] = $arOrders; $recOrders[] = $orderId; } diff --git a/intaro.retailcrm/classes/general/user/RetailCrmCorporateClient.php b/intaro.retailcrm/classes/general/user/RetailCrmCorporateClient.php index eb5fa120..514feeef 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmCorporateClient.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmCorporateClient.php @@ -12,7 +12,6 @@ class RetailCrmCorporateClient $contragent = array(); $shops = RetailcrmConfigProvider::getSitesListCorporate(); $optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails(); - $arUser = Bitrix\Main\UserTable::getById($arOrder['USER_ID'])->fetch(); if (count($shops) == 0) { @@ -48,7 +47,7 @@ class RetailCrmCorporateClient foreach ($shops as $shop) { $customerCorporate = array( 'createdAt' => $arOrder['DATE_INSERT'], - "nickName" => $nickName, + "nickName" => $nickName ); if ($fillCorp) { @@ -94,6 +93,7 @@ class RetailCrmCorporateClient if ($send) { $result = RCrmActions::apiMethod($api, 'customersCorporateCreate', __METHOD__, $customerCorporate, $site); + if (!$result) { return false; } diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 157f5a34..699a38b7 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Исправлена кодировка в настройках модуля +- Добавлена поддержка функционала смены клиентов diff --git a/intaro.retailcrm/include.php b/intaro.retailcrm/include.php index 98dfa6b0..22f2565d 100644 --- a/intaro.retailcrm/include.php +++ b/intaro.retailcrm/include.php @@ -26,5 +26,17 @@ CModule::AddAutoloadClasses( 'RetailCrmCorporateClient' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmCorporateClient.php') ? '../../php_interface/retailcrm/RetailCrmCorporateClient.php' : 'classes/general/user/RetailCrmCorporateClient.php', 'RetailcrmConfigProvider' => 'classes/general/RetailcrmConfigProvider.php', 'RetailcrmConstants' => 'classes/general/RetailcrmConstants.php', + 'RetailcrmBuilderInterface' => 'classes/general/RetailcrmBuilderInterface.php', + 'CustomerBuilder' => 'classes/general/CustomerBuilder.php', + 'CorporateCustomerBuilder' => 'classes/general/CorporateCustomerBuilder.php', + 'Customer' => 'classes/general/Model/Customer.php', + 'CustomerAddress' => 'classes/general/Model/CustomerAddress.php', + 'CustomerContragent' => 'classes/general/Model/CustomerContragent.php', + 'BuyerProfile' => 'classes/general/Model/BuyerProfile.php', + 'AdressBuilder' => 'classes/general/AdressBuilder.php', + 'BuilderBase' => 'classes/general/BuilderBase.php', + 'AddressBuilder' => 'classes/general/AddressBuilder.php', + 'AbstractBuilder' => 'classes/general/AbstractBuilder.php', + 'BaseModel' => 'classes/general/Model/BaseModel.php' ) ); diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index da7f0edc..93466def 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,5 +1,5 @@ "5.3.2", - "VERSION_DATE" => "2020-05-04 14:22:00" + "VERSION" => "5.4.0", + "VERSION_DATE" => "2020-07-14 13:00:00" ); diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index efa1e302..dc89209e 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -779,10 +779,10 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { return true; }); - $('.r-dc-button label').change(function(){ - if($(this).find('input').is(':checked') === true){ + $('.r-dc-button label').change(function() { + if ($(this).find('input').is(':checked') === true) { $('tr.r-dc').show('slow'); - } else if($(this).find('input').is(':checked') === false){ + } else if ($(this).find('input').is(':checked') === false) { $('tr.r-dc').hide('slow'); } @@ -790,7 +790,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { }); $('.r-cc-button label').change(function(){ - if($(this).find('input').is(':checked') === true){ + if($(this).find('input').is(':checked') === true) { $('tr.r-cc').show('slow'); } else if($(this).find('input').is(':checked') === false){ $('tr.r-cc').hide('slow'); @@ -1385,16 +1385,14 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { - + > - + @@ -1437,7 +1435,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { - > @@ -1455,24 +1452,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { - - - - - - - - - - > - - - - - Buttons(); ?> diff --git a/tests/classes/general/AddressBuilderTest.php b/tests/classes/general/AddressBuilderTest.php new file mode 100644 index 00000000..becf42a4 --- /dev/null +++ b/tests/classes/general/AddressBuilderTest.php @@ -0,0 +1,68 @@ +addressBuilder = new AddressBuilder(); + $this->addressBuilder->setDataCrm($this->getDataBuilder())->build(); + $this->assertNotEmpty($this->addressBuilder); + $addressResult = $this->addressBuilder->getCustomerAddress()->getObjectToArray(); + + $this->assertEquals("346000", $addressResult["index"]); + $this->assertEquals("RU", $addressResult["country"]); + $this->assertEquals("Ростовская область", $addressResult["region"]); + $this->assertEquals("Ростов-на-Дону", $addressResult["city"]); + $this->assertEquals("Большая Садовая", $addressResult["street"]); + $this->assertEquals("3", $addressResult["building"]); + $this->assertEquals("3", $addressResult["flat"]); + $this->assertEquals("3", $addressResult["floor"]); + $this->assertEquals("3", $addressResult["block"]); + $this->assertEquals("3", $addressResult["house"]); + $this->assertEquals("Дополнительная информация", $addressResult["notes"]); + $this->assertEquals( + "ул. Большая Садовая, д. 3, стр. 3, корп. 3, кв./офис 3, под. 3, эт. 3, Дополнительная информация", + $addressResult["text"] + ); + } + + private function getDataBuilder() + { + return array( + "id" => "13743", + "index" => "346000", + "countryIso" => "RU", + "region" => "Ростовская область", + "regionId" => "73", + "city" => "Ростов-на-Дону", + "cityId" => "4298", + "cityType" => "г.", + "street" => "Большая Садовая", + "streetId" => "1583457", + "streetType" => "ул.", + "building" => "3", + "flat" => "3", + "floor" => "3", + "block" =>"3", + "house" => "3", + "housing" => "3", + "notes" => "Дополнительная информация", + "text" => "ул. Большая Садовая, д. 3, стр. 3, корп. 3, кв./офис 3, под. 3, эт. 3, Дополнительная информация", + ); + } +} diff --git a/tests/classes/general/CustomerBuilderTest.php b/tests/classes/general/CustomerBuilderTest.php new file mode 100644 index 00000000..e72fff6a --- /dev/null +++ b/tests/classes/general/CustomerBuilderTest.php @@ -0,0 +1,92 @@ +customer = new CustomerBuilder(); + $this->customer->setDataCrm($this->getDataBuilder())->build(); + $this->assertNotEmpty($this->customer); + $addressResult = $this->customer->getCustomer()->getObjectToArray(); + + $this->assertEquals("mm@mm.mmm", $addressResult["EMAIL"]); + $this->assertEquals("mmm", $addressResult["NAME"]); + $this->assertEquals("mmm", $addressResult["LAST_NAME"]); + $this->assertEquals("mmm", $addressResult["SECOND_NAME"]); + $this->assertEquals("474747856878", $addressResult["PERSONAL_PHONE"]); + $this->assertEquals("346000", $addressResult["PERSONAL_ZIP"]); + $this->assertEquals("Ростов-на-Дону", $addressResult["PERSONAL_CITY"]); + $this->assertEquals("13.05.2020", $addressResult["PERSONAL_BIRTHDAY"]); + $this->assertEquals("female", $addressResult["PERSONAL_GENDER"]); + } + + private function getDataBuilder() + { + return array( + "type"=>"customer", + "id"=> 20250, + "createdAt"=> "2020-05-13 16:34:54", + "site"=> "bitrix-local", + "marginSumm"=> 0, + "totalSumm"=> 0, + "averageSumm"=> 0, + "ordersCount"=> 0, + "customFields"=> array( + "faxcliente"=> "11", + "tipodecliente"=> "11", + ), + "personalDiscount"=> 0, + "cumulativeDiscount"=> 0, + "address"=> array( + "id"=> 13748, + "index"=> "346000", + "countryIso"=>"RU", + "region"=>"Ростовская область", + "regionId"=> 73, + "city"=> "Ростов-на-Дону", + "cityId"=> 4298, + "cityType"=> "г.", + "street"=> "Большая Садовая", + "streetId"=> 1583457, + "streetType"=>"ул.", + "building"=>"1", + "flat"=> "1", + "floor"=> "1", + "block"=> "1", + "house"=> "1", + "housing"=> "1", + "notes"=> "111", + "text"=>"ул. Большая Садовая, д. 1, стр. 1, корп. 1, кв./офис 1, под. 1, эт. 1, 111", + ), + "firstName"=> "mmm", + "lastName"=> "mmm", + "patronymic"=> "mmm", + "sex"=> "female", + "email"=> "mm@mm.mmm", + "phones"=> array( + "0" => array( + "number"=> "474747856878", + ) + ), + "birthday"=> "2020-05-13", + "create"=> 1 + ); + } +}