1
0
mirror of synced 2025-02-20 08:53:15 +03:00

Customer change

* remove useless request for history
* append new address to corporate customer
* centralized configuration provider
* use companyName filter in event & pass companyName into order
* add AdressBuilder* fixed for regressions
* fixed double contact problem
This commit is contained in:
Pavel 2020-07-14 13:47:26 +03:00 committed by GitHub
parent d0252f4ef2
commit 09f82bcfdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 1706 additions and 186 deletions

View File

@ -1,3 +1,6 @@
## 2020-07-14 v.5.4.0
* Добавлена поддержка функционала смены клиента
## 2020-05-04 v.5.3.2
* Исправлена кодировка в настройках модуля

View File

@ -0,0 +1,61 @@
<?php
/**
* Class AbstractBuilder
*/
abstract class AbstractBuilder
{
/**
* @param string $key
* @param mixed $default
* @return mixed|null
*/
public function getValue($key, $default = NULL)
{
return isset($this->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);
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Class AddressBuilder
*/
class AddressBuilder extends AbstractBuilder implements RetailcrmBuilderInterface
{
/**
* @var CustomerAddress
*/
private $customerAddress;
/** @var array $dataCrm customerHistory */
protected $dataCrm;
/**
* CustomerBuilder constructor.
*/
public function __construct()
{
$this->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;
}
}

View File

@ -0,0 +1,260 @@
<?php
/**
* Class CorporateCustomerBuilder
*/
class CorporateCustomerBuilder extends AbstractBuilder implements RetailcrmBuilderInterface
{
/** @var Customer */
protected $customer;
/**@var CustomerBuilder */
protected $customerBuilder;
/** @var CustomerAddress */
protected $customerAddress;
/** @var array $dataCrm customerHistory */
protected $dataCrm;
/** @var array $corporateContact */
protected $corporateContact;
/** @var int $orderCustomerExtId */
protected $orderCustomerExtId;
/** @var BuyerProfile */
public $buyerProfile;
/** @var bool $registerNewUser */
protected $registerNewUser;
/** @var int $registeredUserID */
protected $registeredUserID;
/**@var AddressBuilder */
protected $addressBuilder;
/**@var array $contragentTypes */
protected $contragentTypes;
/**
* CorporateCustomerBuilder constructor.
*/
public function __construct()
{
$this->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;
}
}

View File

@ -0,0 +1,238 @@
<?php
/**
* Class CustomerBuilder
*/
class CustomerBuilder extends AbstractBuilder implements RetailcrmBuilderInterface
{
/** @var Customer */
protected $customer;
/** @var CustomerAddress */
protected $customerAddress;
/** @var array $dataCrm customerHistory */
protected $dataCrm;
/** @var AddressBuilder */
protected $addressBuilder;
/** @var CUser */
protected $user;
/** @var bool $registerNewUser */
protected $registerNewUser;
/** @var int $registeredUserID */
protected $registeredUserID;
/**
* CustomerBuilder constructor.
*/
public function __construct()
{
$this->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;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Class BaseModel
*/
abstract class BaseModel
{
/**
* @return array
*/
public function getObjectToArray()
{
return $this->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;
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Class BuyerProfile
*/
class BuyerProfile extends BaseModel
{
/**@var string $NAME */
protected $NAME;
/**@var string $USER_ID */
protected $USER_ID;
/**@var string $PERSON_TYPE_ID */
protected $PERSON_TYPE_ID;
/**
* @param string $NAME
* @return $this
*/
public function setName($NAME)
{
$this->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;
}
}

View File

@ -0,0 +1,202 @@
<?php
/**
* Class Customer
*/
class Customer extends BaseModel
{
/**@var string $EMAIL */
protected $EMAIL;
/**@var string $LOGIN */
protected $LOGIN;
/**@var string $ACTIVE */
protected $ACTIVE;
/**@var string $PASSWORD */
protected $PASSWORD;
/**@var string $CONFIRM_PASSWORD */
protected $CONFIRM_PASSWORD;
/**@var string $NAME */
protected $NAME;
/**@var string $LAST_NAME */
protected $LAST_NAME;
/**@var string $SECOND_NAME */
protected $SECOND_NAME;
/**@var string $PERSONAL_MOBILE */
protected $PERSONAL_MOBILE;
/**@var string $PERSONAL_PHONE */
protected $PERSONAL_PHONE;
/**@var string $PERSONAL_ZIP */
protected $PERSONAL_ZIP;
/**@var string $PERSONAL_CITY */
protected $PERSONAL_CITY;
/**@var string $PERSONAL_BIRTHDAY */
protected $PERSONAL_BIRTHDAY;
/**@var string $PERSONAL_GENDER */
protected $PERSONAL_GENDER;
/**
* @param string $EMAIL
* @return $this
*/
public function setEmail($EMAIL)
{
$this->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;
}
}

View File

@ -0,0 +1,202 @@
<?php
/**
* Class CustomerAddress
*/
class CustomerAddress extends BaseModel
{
/**@var string $index */
protected $index;
/**@var string $country */
protected $country;
/**@var string $region */
protected $region;
/**@var string $city */
protected $city;
/**@var string $street */
protected $street;
/**@var string $building */
protected $building;
/**@var string $house */
protected $house;
/**@var string $block */
protected $block;
/**@var string $flat */
protected $flat;
/**@var string $floor */
protected $floor;
/**@var string $intercomCode */
protected $intercomCode;
/**@var string $metro */
protected $metro;
/**@var string $notes */
protected $notes;
/**@var string $text */
protected $text;
/**
* @param string $index
* @return $this
*/
public function setIndex($index)
{
$this->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;
}
}

View File

@ -0,0 +1,132 @@
<?php
/**
* Class CustomerContragent
*/
class CustomerContragent extends BaseModel
{
/**@var string $contragentType */
protected $contragentType;
/**@var string $legalName */
protected $legalName;
/**@var string $legalAddress */
protected $legalAddress;
/**@var string $certificateNumber */
protected $certificateNumber;
/**@var string $certificateDate */
protected $certificateDate;
/**@var string $bank */
protected $bank;
/**@var string $bankAddress */
protected $bankAddress;
/**@var string $corrAccount */
protected $corrAccount;
/**@var string $bankAccount */
protected $bankAccount;
/**
* @param string $contragentType
* @return $this
*/
public function setContragentType($contragentType)
{
$this->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;
}
}

View File

@ -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));

View File

@ -0,0 +1,20 @@
<?php
IncludeModuleLangFile(__FILE__);
interface RetailcrmBuilderInterface
{
/**
* Set data array customerHistory
*
* @param array $dataCrm
*
* @return RetailcrmBuilderInterface
*/
public function setDataCrm($dataCrm);
/**
* Build result
*/
public function build();
}

View File

@ -401,6 +401,26 @@ class RetailcrmConfigProvider
return static::getOption(RetailcrmConstants::CRM_ORDER_HISTORY_DATE);
}
/**
* Returns customers history since ID
*
* @return int
*/
public static function getCustomersHistorySinceId()
{
return (int) static::getOption(RetailcrmConstants::CRM_CUSTOMERS_HISTORY_SINCE_ID);
}
/**
* Sets new customers history since ID
*
* @param int $sinceId
*/
public static function setCustomersHistorySinceId($sinceId)
{
static::setOption(RetailcrmConstants::CRM_CUSTOMERS_HISTORY_SINCE_ID, $sinceId);
}
/**
* getCatalogBasePrice
*

View File

@ -39,11 +39,11 @@ class RetailcrmConstants
const CRM_ORDER_LAST_ID = 'order_last_id';
const CRM_ORDER_SITES = 'sites_ids';
const CRM_ORDER_DISCHARGE = 'order_discharge';
const CRM_SITES_LIST = 'sites_list';
const CRM_ORDER_PROPS = 'order_props';
const CRM_LEGAL_DETAILS = 'legal_details';
const CRM_CUSTOM_FIELDS = 'custom_fields';
const CRM_CONTRAGENT_TYPE = 'contragent_type';
const CRM_SITES_LIST = 'sites_list';
const CRM_SITES_LIST_CORPORATE = 'shops-corporate';
const CRM_ORDER_NUMBERS = 'order_numbers';
const CRM_CANCEL_ORDER = 'cansel_order';
@ -70,6 +70,7 @@ class RetailcrmConstants
const CRM_DIMENSIONS = 'order_dimensions';
const PROTOCOL = 'protocol';
const CRM_ORDER_FAILED_IDS = 'order_failed_ids';
const CRM_CUSTOMERS_HISTORY_SINCE_ID = 'customer_history';
const CRM_ORDER_HISTORY_DATE = 'order_history_date';
const CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
const CRM_ORDER_DIMENSIONS = 'order_dimensions';

View File

@ -37,6 +37,14 @@
<field id="contragent.certificate_date" group="customerContragent">certificateDate</field>
<field id="contragent.bank" group="customerContragent">bank</field>
<field id="contragent.bank_address" group="customerContragent">bankAddress</field>
<field id="contragent.i_n_n" group="customerContragent">INN</field>
<field id="contragent.o_k_p_o" group="customerContragent">OKPO</field>
<field id="contragent.k_p_p" group="customerContragent">KPP</field>
<field id="contragent.o_g_r_n" group="customerContragent">OGRN</field>
<field id="contragent.o_g_r_n_i_p" group="customerContragent">OGRNIP</field>
<field id="contragent.certificate_number" group="customerContragent">certificateNumber</field>
<field id="contragent.certificate_date" group="customerContragent">certificateDate</field>
<field id="contragent.b_i_k" group="customerContragent">BIK</field>
<field id="contragent.corr_account" group="customerContragent">corrAccount</field>
<field id="contragent.bank_account" group="customerContragent">bankAccount</field>

View File

@ -84,6 +84,10 @@
"type": "bool",
"default": false
},
"subscribed": {
"type": "bool",
"default": false
},
"commentary": {
"type": "string"
},

View File

@ -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,

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1 +1 @@
- Исправлена кодировка в настройках модуля
- Добавлена поддержка функционала смены клиентов

View File

@ -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'
)
);

View File

@ -1,5 +1,5 @@
<?
$arModuleVersion = array(
"VERSION" => "5.3.2",
"VERSION_DATE" => "2020-05-04 14:22:00"
"VERSION" => "5.4.0",
"VERSION_DATE" => "2020-07-14 13:00:00"
);

View File

@ -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')) {
<tr class="heading r-dc-button">
<td colspan="2" class="option-other-heading">
<b>
<label><input class="addr" type="checkbox" name="discount_round" value="Y" <?php if($optionDiscRound === 'Y') echo "checked"; ?>>
<?php echo GetMessage('ROUND_HEADER'); ?>
</label>
<label><input class="addr" type="checkbox" name="discount_round" value="Y" <?php if($optionDiscRound === 'Y') echo "checked"; ?>><?php echo "Округление цены товара при сборе одинаковых товарных позиций" ?></label>
</b>
</td>
</tr>
<tr class="r-dc" <?php if($optionDiscRound !== 'Y') echo 'style="display: none;"'; ?>>
<td class="option-head" colspan="2">
<b><?php echo GetMessage('ROUND_LABEL'); ?></b>
<b><?php echo "При включенной опции округление будет происходить в меньшую сторону" ?></b>
</td>
</tr>
@ -1437,7 +1435,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</select>
</td>
</tr>
<tr class="r-cc" <?php if($optionCorpClient !== 'Y') echo 'style="display: none;"'; ?>>
<td colspan="2" class="option-head option-other-top option-other-bottom">
<b>
@ -1455,24 +1452,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
<?php endforeach;?>
</td>
</tr>
<tr class="heading r-purchaseprice-button">
<td colspan="2" class="option-other-heading">
<b>
<label><input class="addr" type="checkbox" name="purchasePrice_null" value="Y"
<?php if($optionPricePrchaseNull === 'Y')
echo "checked"; ?>><?php
echo GetMessage('PURCHASE_HEADER'); ?></label>
</b>
</td>
</tr>
<tr class="r-purchaseprice" <?php if($optionPricePrchaseNull !== 'Y') echo 'style="display: none;"'; ?>>
<td class="option-head" colspan="2">
<b><?php echo GetMessage('PURCHASE_ICML'); ?></b>
</td>
</tr>
<?php endif;?>
<?php $tabControl->Buttons(); ?>
<input type="hidden" name="Update" value="Y" />

View File

@ -0,0 +1,68 @@
<?php
/**
* Class AddressBuilderTest
*/
class AddressBuilderTest extends \PHPUnit\Framework\TestCase
{
/**@var object $addressBuilder */
public $addressBuilder;
/**@var array $dataCrm */
protected $dataCrm;
public function setUp()
{
parent::setUp();
}
public function testAddressBuild()
{
$this->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, Дополнительная информация",
);
}
}

View File

@ -0,0 +1,92 @@
<?php
/**
* Class CustomerBuilderTest
*/
class CustomerBuilderTest extends \PHPUnit\Framework\TestCase
{
/**@var object $customer */
public $customer;
/**@var object $addressBuilder */
public $addressBuilder;
/**@var array $dataCrm */
protected $dataCrm;
public function setUp()
{
parent::setUp();
}
public function testCustomerBuild()
{
$this->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
);
}
}