WIP: fix for history
This commit is contained in:
parent
d01a5ae0aa
commit
ffcadda9cb
6 changed files with 223 additions and 77 deletions
|
@ -42,12 +42,24 @@ class RetailcrmConfigProvider
|
|||
/** @var bool|null|string */
|
||||
private static $orderDimensions;
|
||||
|
||||
/** @var bool|null|string */
|
||||
private static $corporateClientName;
|
||||
|
||||
/** @var bool|null|string */
|
||||
private static $corporateClientAddress;
|
||||
|
||||
/** @var bool|null|string */
|
||||
private static $corporateClient;
|
||||
|
||||
/** @var array $sitesList */
|
||||
private static $sitesList;
|
||||
|
||||
/** @var array $sitesListCorporate */
|
||||
private static $sitesListCorporate;
|
||||
|
||||
/** @var bool|null|string $orderNumbers */
|
||||
private static $orderNumbers;
|
||||
|
||||
/** @var array $orderTypes */
|
||||
private static $orderTypes;
|
||||
|
||||
|
@ -72,6 +84,9 @@ class RetailcrmConfigProvider
|
|||
/** @var array $contragentTypes */
|
||||
private static $contragentTypes;
|
||||
|
||||
/** @var array $cancellableOrderPaymentStatuses */
|
||||
private static $cancellableOrderPaymentStatuses;
|
||||
|
||||
/** @var array $customFields */
|
||||
private static $customFields;
|
||||
|
||||
|
@ -89,7 +104,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getApiUrl()
|
||||
{
|
||||
if (empty(static::$apiUrl)) {
|
||||
if (self::isEmptyNotZero(static::$apiUrl)) {
|
||||
static::$apiUrl = static::getOption(RetailcrmConstants::CRM_API_HOST_OPTION);
|
||||
}
|
||||
|
||||
|
@ -101,13 +116,41 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getApiKey()
|
||||
{
|
||||
if (empty(static::$apiKey)) {
|
||||
if (self::isEmptyNotZero(static::$apiKey)) {
|
||||
static::$apiKey = static::getOption(RetailcrmConstants::CRM_API_KEY_OPTION);
|
||||
}
|
||||
|
||||
return static::$apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCorporateClientName
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getCorporateClientName()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$corporateClientName)) {
|
||||
static::$corporateClientName = static::getUnserializedOption(RetailcrmConstants::CRM_CORP_NAME);
|
||||
}
|
||||
|
||||
return static::$corporateClientName;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCorporateClientAddress
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getCorporateClientAddress()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$corporateClientAddress)) {
|
||||
static::$corporateClientAddress = static::getUnserializedOption(RetailcrmConstants::CRM_CORP_ADDRESS);
|
||||
}
|
||||
|
||||
return static::$corporateClientAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCorporateClient
|
||||
*
|
||||
|
@ -115,7 +158,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getCorporateClientStatus()
|
||||
{
|
||||
if (empty(static::$corporateClient)) {
|
||||
if (self::isEmptyNotZero(static::$corporateClient)) {
|
||||
static::$corporateClient = static::getOption(RetailcrmConstants::CRM_CC);
|
||||
}
|
||||
|
||||
|
@ -129,13 +172,29 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getSitesList()
|
||||
{
|
||||
if (empty(static::$sitesList)) {
|
||||
if (self::isEmptyNotZero(static::$sitesList)) {
|
||||
static::$sitesList = static::getUnserializedOption(RetailcrmConstants::CRM_SITES_LIST);
|
||||
}
|
||||
|
||||
return static::$sitesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* getSitesListCorporate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSitesListCorporate()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$sitesListCorporate)) {
|
||||
static::$sitesListCorporate = static::getUnserializedOption(
|
||||
RetailcrmConstants::CRM_SITES_LIST_CORPORATE
|
||||
);
|
||||
}
|
||||
|
||||
return static::$sitesListCorporate;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderTypes
|
||||
*
|
||||
|
@ -143,7 +202,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getOrderTypes()
|
||||
{
|
||||
if (empty(static::$orderTypes)) {
|
||||
if (self::isEmptyNotZero(static::$orderTypes)) {
|
||||
static::$orderTypes = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR);
|
||||
}
|
||||
|
||||
|
@ -157,7 +216,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getDeliveryTypes()
|
||||
{
|
||||
if (empty(static::$deliveryTypes)) {
|
||||
if (self::isEmptyNotZero(static::$deliveryTypes)) {
|
||||
static::$deliveryTypes = static::getUnserializedOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR);
|
||||
}
|
||||
|
||||
|
@ -171,7 +230,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getPaymentTypes()
|
||||
{
|
||||
if (empty(static::$paymentTypes)) {
|
||||
if (self::isEmptyNotZero(static::$paymentTypes)) {
|
||||
static::$paymentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_TYPES);
|
||||
}
|
||||
|
||||
|
@ -185,7 +244,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getPaymentStatuses()
|
||||
{
|
||||
if (empty(static::$paymentStatuses)) {
|
||||
if (self::isEmptyNotZero(static::$paymentStatuses)) {
|
||||
static::$paymentStatuses = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_STATUSES);
|
||||
}
|
||||
|
||||
|
@ -199,7 +258,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getPayment()
|
||||
{
|
||||
if (empty(static::$payment)) {
|
||||
if (self::isEmptyNotZero(static::$payment)) {
|
||||
static::$payment = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT);
|
||||
}
|
||||
|
||||
|
@ -213,7 +272,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getOrderProps()
|
||||
{
|
||||
if (empty(static::$orderProps)) {
|
||||
if (self::isEmptyNotZero(static::$orderProps)) {
|
||||
static::$orderProps = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_PROPS);
|
||||
}
|
||||
|
||||
|
@ -227,7 +286,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getLegalDetails()
|
||||
{
|
||||
if (empty(static::$legalDetails)) {
|
||||
if (self::isEmptyNotZero(static::$legalDetails)) {
|
||||
static::$legalDetails = static::getUnserializedOption(RetailcrmConstants::CRM_LEGAL_DETAILS);
|
||||
}
|
||||
|
||||
|
@ -241,7 +300,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getContragentTypes()
|
||||
{
|
||||
if (empty(static::$contragentTypes)) {
|
||||
if (self::isEmptyNotZero(static::$contragentTypes)) {
|
||||
static::$contragentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_CONTRAGENT_TYPE);
|
||||
}
|
||||
|
||||
|
@ -255,13 +314,29 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getCustomFields()
|
||||
{
|
||||
if (empty(static::$customFields)) {
|
||||
if (self::isEmptyNotZero(static::$customFields)) {
|
||||
static::$customFields = static::getUnserializedOption(RetailcrmConstants::CRM_CUSTOM_FIELDS);
|
||||
}
|
||||
|
||||
return static::$customFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCancellableOrderPaymentStatuses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCancellableOrderPaymentStatuses()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$cancellableOrderPaymentStatuses)) {
|
||||
static::$cancellableOrderPaymentStatuses = static::getUnserializedOption(
|
||||
RetailcrmConstants::CRM_CANCEL_ORDER
|
||||
);
|
||||
}
|
||||
|
||||
return static::$cancellableOrderPaymentStatuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* getLastOrderId
|
||||
*
|
||||
|
@ -305,11 +380,15 @@ class RetailcrmConfigProvider
|
|||
/**
|
||||
* getOrderNumbers
|
||||
*
|
||||
* @return array
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getOrderNumbers()
|
||||
{
|
||||
return static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_NUMBERS);
|
||||
if (self::isEmptyNotZero(self::$orderNumbers)) {
|
||||
self::$orderNumbers = static::getOption(RetailcrmConstants::CRM_ORDER_NUMBERS);
|
||||
}
|
||||
|
||||
return self::$orderNumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -329,7 +408,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getCatalogBasePrice()
|
||||
{
|
||||
if (empty(static::$catalogBasePrice)) {
|
||||
if (self::isEmptyNotZero(static::$catalogBasePrice)) {
|
||||
static::$catalogBasePrice = static::getOption(RetailcrmConstants::CRM_CATALOG_BASE_PRICE);
|
||||
}
|
||||
|
||||
|
@ -343,7 +422,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getOrderDimensions()
|
||||
{
|
||||
if (empty(static::$orderDimensions)) {
|
||||
if (self::isEmptyNotZero(static::$orderDimensions)) {
|
||||
static::$orderDimensions = static::getOption(RetailcrmConstants::CRM_ORDER_DIMENSIONS, 'N');
|
||||
}
|
||||
|
||||
|
@ -357,7 +436,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getCurrency()
|
||||
{
|
||||
if (empty(static::$currency)) {
|
||||
if (self::isEmptyNotZero(static::$currency)) {
|
||||
static::$currency = static::getOption(RetailcrmConstants::CRM_CURRENCY);
|
||||
}
|
||||
|
||||
|
@ -381,7 +460,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getInfoblocksInventories()
|
||||
{
|
||||
if (empty(static::$infoblocksInventories)) {
|
||||
if (self::isEmptyNotZero(static::$infoblocksInventories)) {
|
||||
static::$infoblocksInventories = static::getUnserializedOption(
|
||||
RetailcrmConstants::CRM_IBLOCKS_INVENTORIES
|
||||
);
|
||||
|
@ -397,7 +476,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getStores()
|
||||
{
|
||||
if (empty(static::$stores)) {
|
||||
if (self::isEmptyNotZero(static::$stores)) {
|
||||
static::$stores = static::getUnserializedOption(RetailcrmConstants::CRM_STORES);
|
||||
}
|
||||
|
||||
|
@ -411,7 +490,7 @@ class RetailcrmConfigProvider
|
|||
*/
|
||||
public static function getShops()
|
||||
{
|
||||
if (empty(static::$shops)) {
|
||||
if (self::isEmptyNotZero(static::$shops)) {
|
||||
static::$shops = static::getUnserializedOption(RetailcrmConstants::CRM_SHOPS);
|
||||
}
|
||||
|
||||
|
@ -466,4 +545,16 @@ class RetailcrmConfigProvider
|
|||
{
|
||||
return unserialize(static::getOption($option, $def));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if value is empty and not zero (0 - digit)
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isEmptyNotZero($value)
|
||||
{
|
||||
return empty($value) && $value !== 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,9 +43,10 @@ class RetailcrmConstants
|
|||
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 = 'sites_list';
|
||||
const CRM_SITES_LIST_CORPORATE = 'shops-corporate';
|
||||
const CRM_ORDER_NUMBERS = 'order_numbers';
|
||||
const CRM_CANSEL_ORDER = 'cansel_order';
|
||||
const CRM_CANCEL_ORDER = 'cansel_order';
|
||||
const CRM_INVENTORIES_UPLOAD = 'inventories_upload';
|
||||
const CRM_STORES = 'stores';
|
||||
const CRM_SHOPS = 'shops';
|
||||
|
@ -62,7 +63,7 @@ class RetailcrmConstants
|
|||
const CRM_CC = 'cc';
|
||||
const CRM_CORP_SHOPS = 'shops-corporate';
|
||||
const CRM_CORP_NAME = 'nickName-corporate';
|
||||
const CRM_CORP_ADRES = 'adres-corporate';
|
||||
const CRM_CORP_ADDRESS = 'adres-corporate';
|
||||
const CRM_API_VERSION = 'api_version';
|
||||
const CRM_CURRENCY = 'currency';
|
||||
const CRM_ADDRESS_OPTIONS = 'address_options';
|
||||
|
|
|
@ -27,6 +27,15 @@ IncludeModuleLangFile(__FILE__);
|
|||
*/
|
||||
class RetailcrmDependencyLoader
|
||||
{
|
||||
/** @var int */
|
||||
const LEGACY_LOADER = 0;
|
||||
|
||||
/** @var int */
|
||||
const D7_LOADER = 1;
|
||||
|
||||
/** @var int $loader */
|
||||
private static $loader = self::D7_LOADER;
|
||||
|
||||
/**
|
||||
* Loads dependencies
|
||||
*
|
||||
|
@ -35,20 +44,54 @@ class RetailcrmDependencyLoader
|
|||
public static function loadDependencies()
|
||||
{
|
||||
foreach (self::getDependencies() as $dependency) {
|
||||
if (!CModule::IncludeModule($dependency)) {
|
||||
RCrmActions::eventLog(
|
||||
__CLASS__ . '::' . __METHOD__,
|
||||
$dependency,
|
||||
'module not found'
|
||||
);
|
||||
if (self::LEGACY_LOADER == self::$loader) {
|
||||
if (!CModule::IncludeModule($dependency)) {
|
||||
RCrmActions::eventLog(
|
||||
__CLASS__ . '::' . __METHOD__,
|
||||
$dependency,
|
||||
'module not found'
|
||||
);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (!\Bitrix\Main\Loader::includeModule($dependency)) {
|
||||
RCrmActions::eventLog(
|
||||
__CLASS__ . '::' . __METHOD__,
|
||||
$dependency,
|
||||
'module not found'
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
} catch (\Bitrix\Main\LoaderException $exception) {
|
||||
RCrmActions::eventLog(
|
||||
__CLASS__ . '::' . __METHOD__,
|
||||
$dependency,
|
||||
sprintf('error while trying to load module: %s', $exception->getMessage())
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set loader mode. Use RetailcrmDependencyLoader::LEGACY_LOADER or RetailcrmDependencyLoader::D7_LOADER
|
||||
*
|
||||
* @param $loader
|
||||
*/
|
||||
public static function setLoader($loader)
|
||||
{
|
||||
if (in_array($loader, array(self::LEGACY_LOADER, self::D7_LOADER))) {
|
||||
self::$loader = $loader;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of required modules names
|
||||
*
|
||||
|
|
|
@ -200,8 +200,8 @@ class RetailCrmEvent
|
|||
$corpAddress = '';
|
||||
$contragent = array();
|
||||
$userCorp = array();
|
||||
$corpName = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_NAME, 0));
|
||||
$corpAddress = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_ADRES, 0));
|
||||
$corpName = RetailcrmConfigProvider::getCorporateClientName();
|
||||
$corpAddress = RetailcrmConfigProvider::getCorporateClientAddress();
|
||||
|
||||
foreach ($arOrder['PROPS']['properties'] as $prop) {
|
||||
if ($prop['CODE'] == $corpName) {
|
||||
|
@ -441,9 +441,9 @@ class RetailCrmEvent
|
|||
return false;
|
||||
}
|
||||
|
||||
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||
$optionsPaymentTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0));
|
||||
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
|
||||
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
|
||||
$optionsPaymentTypes = RetailcrmConfigProvider::getPaymentTypes();
|
||||
$optionsPayStatuses = RetailcrmConfigProvider::getPayment();
|
||||
|
||||
$arPayment = array(
|
||||
'ID' => $event->getId(),
|
||||
|
|
|
@ -228,40 +228,27 @@ class RetailCrmHistory
|
|||
public static function orderHistory()
|
||||
{
|
||||
global $USER;
|
||||
|
||||
if (is_object($USER) == false) {
|
||||
$USER = new RetailUser;
|
||||
$USER = new RetailUser();
|
||||
}
|
||||
if (!CModule::IncludeModule("iblock")) {
|
||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'iblock', 'module not found');
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!CModule::IncludeModule("sale")) {
|
||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'sale', 'module not found');
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!CModule::IncludeModule("catalog")) {
|
||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'catalog', 'module not found');
|
||||
|
||||
if (!RetailcrmDependencyLoader::loadDependencies()) {
|
||||
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);
|
||||
$optionsOrderTypes = RetailcrmConfigProvider::getOrderTypes();
|
||||
$optionsDelivTypes = array_flip(RetailcrmConfigProvider::getDeliveryTypes());
|
||||
$optionsPayStatuses = array_flip(RetailcrmConfigProvider::getPaymentStatuses()); // --statuses
|
||||
$optionsOrderProps = RetailcrmConfigProvider::getOrderProps();
|
||||
$optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails();
|
||||
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
|
||||
$optionsOrderNumbers = RetailcrmConfigProvider::getOrderNumbers();
|
||||
$optionsCanselOrder = RetailcrmConfigProvider::getCancellableOrderPaymentStatuses();
|
||||
$currency = RetailcrmConfigProvider::getCurrencyOrDefault();
|
||||
$contragentTypes = array_flip(RetailcrmConfigProvider::getContragentTypes());
|
||||
|
||||
$optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0));
|
||||
$optionsDelivTypes = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0)));
|
||||
$optionsPayStatuses = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0))); // --statuses
|
||||
$optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0));
|
||||
$optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
|
||||
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||
$optionsOrderNumbers = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_NUMBERS, 0);
|
||||
$optionsCanselOrder = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CANSEL_ORDER, 0));
|
||||
$optionsCurrency = COption::GetOptionString(self::$MODULE_ID, self::$CRM_CURRENCY, 0);
|
||||
$currency = $optionsCurrency ? $optionsCurrency : \Bitrix\Currency\CurrencyManager::getBaseCurrency();
|
||||
|
||||
$api = new RetailCrm\ApiClient($api_host, $api_key);
|
||||
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
|
||||
$historyFilter = array();
|
||||
$historyStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY);
|
||||
|
@ -436,9 +423,11 @@ class RetailCrmHistory
|
|||
"PASSWORD" => $userPassword,
|
||||
"CONFIRM_PASSWORD" => $userPassword
|
||||
);
|
||||
|
||||
if ($order['customer']['phones'][0]) {
|
||||
$arFields['PERSONAL_PHONE'] = $order['customer']['phones'][0];
|
||||
}
|
||||
|
||||
if ($order['customer']['phones'][1]) {
|
||||
$arFields['PERSONAL_MOBILE'] = $order['customer']['phones'][1];
|
||||
}
|
||||
|
@ -467,8 +456,39 @@ class RetailCrmHistory
|
|||
$order['customer']['externalId'] = $registeredUserID;
|
||||
}
|
||||
|
||||
$buyerProfileToAppend = array();
|
||||
|
||||
if (!empty($storedCorporateCustomer) && !empty($order['company'])) {
|
||||
$buyerProfile = array(
|
||||
"NAME" => $order['company']['name'],
|
||||
"USER_ID" => $order['contact']['externalId'],
|
||||
"PERSON_TYPE_ID" => $contragentTypes['legal-entity']
|
||||
);
|
||||
|
||||
$buyerProfileToAppend = Bitrix\Sale\OrderUserProperties::getList(array(
|
||||
"filter" => $buyerProfile
|
||||
))->fetch();
|
||||
|
||||
if (empty($buyerProfileToAppend)) {
|
||||
$buyerProfileInstance = new CSaleOrderUserProps();
|
||||
|
||||
if ($buyerProfileInstance->Add($buyerProfile)) {
|
||||
$buyerProfileToAppend = Bitrix\Sale\OrderUserProperties::getList(array(
|
||||
"filter" => $buyerProfile
|
||||
))->fetch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$newOrder = Bitrix\Sale\Order::create($site, $order['customer']['externalId'], $currency);
|
||||
|
||||
if (isset($buyerProfileToAppend['ID']) && isset($optionsLegalDetails['legalName'])) {
|
||||
$newOrder->setFields(array(
|
||||
$optionsLegalDetails['legalName'] => $buyerProfileToAppend['NAME'],
|
||||
'PERSON_TYPE_ID' => $buyerProfileToAppend['PERSON_TYPE_ID']
|
||||
));
|
||||
}
|
||||
|
||||
if (!is_object($newOrder) || !$newOrder instanceof \Bitrix\Sale\Order) {
|
||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::create', 'Error order create');
|
||||
|
||||
|
|
|
@ -2,14 +2,6 @@
|
|||
IncludeModuleLangFile(__FILE__);
|
||||
class RetailCrmCorporateClient
|
||||
{
|
||||
public static $MODULE_ID = 'intaro.retailcrm';
|
||||
public static $CRM_SITES_LIST = 'shops-corporate';
|
||||
public static $CRM_CORP_NAME = 'nickName-corporate';
|
||||
public static $CRM_LEGAL_DETAILS = 'legal_details';
|
||||
public static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
||||
public static $CRM_CORP_ADDRESS = 'adres-corporate';
|
||||
public static $CRM_ORDER_PROPS = 'order_props';
|
||||
|
||||
public static function clientSend($arOrder, $api, $contragentType, $send = false, $fillCorp = false, $site = null)
|
||||
{
|
||||
if (!$api || empty($contragentType)) {
|
||||
|
@ -18,11 +10,10 @@ class RetailCrmCorporateClient
|
|||
|
||||
$address = array();
|
||||
$contragent = array();
|
||||
$shops = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||
$corpName = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_NAME, 0));
|
||||
$corpAdres = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_ADDRESS, 0));
|
||||
$shops = RetailcrmConfigProvider::getSitesListCorporate();
|
||||
$optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails();
|
||||
|
||||
$arUser = Bitrix\Main\UserTable::getById($arOrder['USER_ID'])->fetch();
|
||||
$optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
|
||||
|
||||
if (count($shops) == 0) {
|
||||
RCrmActions::eventLog('RetailCrmCorporateClient::clientSend()', '$shops', 'No stores selected for download');
|
||||
|
@ -31,11 +22,11 @@ class RetailCrmCorporateClient
|
|||
}
|
||||
|
||||
foreach ($arOrder['PROPS']['properties'] as $prop) {
|
||||
if ($prop['CODE'] == $corpName) {
|
||||
if ($prop['CODE'] == RetailcrmConfigProvider::getCorporateClientName()) {
|
||||
$nickName = $prop['VALUE'][0];
|
||||
}
|
||||
|
||||
if ($prop['CODE'] == $corpAdres) {
|
||||
if ($prop['CODE'] == RetailcrmConfigProvider::getCorporateClientAddress()) {
|
||||
$address = $prop['VALUE'][0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue