centralized configuration provider
This commit is contained in:
parent
f730fb59f4
commit
a4d941ebec
3 changed files with 436 additions and 20 deletions
367
intaro.retailcrm/classes/general/RetailcrmConfig.php
Normal file
367
intaro.retailcrm/classes/general/RetailcrmConfig.php
Normal file
|
@ -0,0 +1,367 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* RetailcrmConfig class
|
||||
*
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* RetailcrmConfig class
|
||||
*
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
class RetailcrmConfig
|
||||
{
|
||||
/** @var bool|null|string */
|
||||
private static $apiUrl;
|
||||
|
||||
/** @var bool|null|string */
|
||||
private static $apiKey;
|
||||
|
||||
/** @var bool|null|string */
|
||||
private static $catalogBasePrice;
|
||||
|
||||
/** @var bool|null|string */
|
||||
private static $currency;
|
||||
|
||||
/** @var bool|null|string */
|
||||
private static $orderDimensions;
|
||||
|
||||
/** @var bool|null|string */
|
||||
private static $corporateClient;
|
||||
|
||||
/** @var array $sitesList */
|
||||
private static $sitesList;
|
||||
|
||||
/** @var array $orderTypes */
|
||||
private static $orderTypes;
|
||||
|
||||
/** @var array $deliveryTypes */
|
||||
private static $deliveryTypes;
|
||||
|
||||
/** @var array $paymentTypes */
|
||||
private static $paymentTypes;
|
||||
|
||||
/** @var array $paymentStatuses */
|
||||
private static $paymentStatuses;
|
||||
|
||||
/** @var array $payment */
|
||||
private static $payment;
|
||||
|
||||
/** @var array $orderProps */
|
||||
private static $orderProps;
|
||||
|
||||
/** @var array $legalDetails */
|
||||
private static $legalDetails;
|
||||
|
||||
/** @var array $contragentTypes */
|
||||
private static $contragentTypes;
|
||||
|
||||
/** @var array $customFields */
|
||||
private static $customFields;
|
||||
|
||||
/**
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getApiUrl()
|
||||
{
|
||||
if (empty(static::$apiUrl)) {
|
||||
static::$apiUrl = static::getOption(RetailcrmConstants::CRM_API_HOST_OPTION);
|
||||
}
|
||||
|
||||
return static::$apiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getApiKey()
|
||||
{
|
||||
if (empty(static::$apiKey)) {
|
||||
static::$apiKey = static::getOption(RetailcrmConstants::CRM_API_KEY_OPTION);
|
||||
}
|
||||
|
||||
return static::$apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCorporateClient
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getCorporateClient()
|
||||
{
|
||||
if (empty(static::$corporateClient)) {
|
||||
static::$corporateClient = static::getOption(RetailcrmConstants::CRM_CC);
|
||||
}
|
||||
|
||||
return static::$corporateClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* getSitesList
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSitesList()
|
||||
{
|
||||
if (empty(static::$sitesList)) {
|
||||
static::$sitesList = static::getUnserializedOption(RetailcrmConstants::CRM_SITES_LIST);
|
||||
}
|
||||
|
||||
return static::$sitesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderTypes()
|
||||
{
|
||||
if (empty(static::$orderTypes)) {
|
||||
static::$orderTypes = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR);
|
||||
}
|
||||
|
||||
return static::$orderTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDeliveryTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getDeliveryTypes()
|
||||
{
|
||||
if (empty(static::$deliveryTypes)) {
|
||||
static::$deliveryTypes = static::getUnserializedOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR);
|
||||
}
|
||||
|
||||
return static::$deliveryTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPaymentTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaymentTypes()
|
||||
{
|
||||
if (empty(static::$paymentTypes)) {
|
||||
static::$paymentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_TYPES);
|
||||
}
|
||||
|
||||
return static::$paymentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPaymentStatuses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaymentStatuses()
|
||||
{
|
||||
if (empty(static::$paymentStatuses)) {
|
||||
static::$paymentStatuses = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_STATUSES);
|
||||
}
|
||||
|
||||
return static::$paymentStatuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPayment
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPayment()
|
||||
{
|
||||
if (empty(static::$payment)) {
|
||||
static::$payment = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT);
|
||||
}
|
||||
|
||||
return static::$payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderProps
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderProps()
|
||||
{
|
||||
if (empty(static::$orderProps)) {
|
||||
static::$orderProps = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_PROPS);
|
||||
}
|
||||
|
||||
return static::$orderProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* getLegalDetails
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getLegalDetails()
|
||||
{
|
||||
if (empty(static::$legalDetails)) {
|
||||
static::$legalDetails = static::getUnserializedOption(RetailcrmConstants::CRM_LEGAL_DETAILS);
|
||||
}
|
||||
|
||||
return static::$legalDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* getContragentTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getContragentTypes()
|
||||
{
|
||||
if (empty(static::$contragentTypes)) {
|
||||
static::$contragentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_CONTRAGENT_TYPE);
|
||||
}
|
||||
|
||||
return static::$contragentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCustomFields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCustomFields()
|
||||
{
|
||||
if (empty(static::$customFields)) {
|
||||
static::$customFields = static::getUnserializedOption(RetailcrmConstants::CRM_CUSTOM_FIELDS);
|
||||
}
|
||||
|
||||
return static::$customFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* getLastOrderId
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getLastOrderId()
|
||||
{
|
||||
return static::getOption(RetailcrmConstants::CRM_ORDER_LAST_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* getFailedOrdersIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getFailedOrdersIds()
|
||||
{
|
||||
return static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_FAILED_IDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderNumbers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderNumbers()
|
||||
{
|
||||
return static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_NUMBERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderHistoryDate
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getOrderHistoryDate()
|
||||
{
|
||||
return static::getOption(RetailcrmConstants::CRM_ORDER_HISTORY_DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* getCatalogBasePrice
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getCatalogBasePrice()
|
||||
{
|
||||
if (empty(static::$catalogBasePrice)) {
|
||||
static::$catalogBasePrice = static::getOption(RetailcrmConstants::CRM_CATALOG_BASE_PRICE);
|
||||
}
|
||||
|
||||
return static::$catalogBasePrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderDimensions
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getOrderDimensions()
|
||||
{
|
||||
if (empty(static::$orderDimensions)) {
|
||||
static::$orderDimensions = static::getOption(RetailcrmConstants::CRM_ORDER_DIMENSIONS, 'N');
|
||||
}
|
||||
|
||||
return static::$orderDimensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCurrency
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getCurrency()
|
||||
{
|
||||
if (empty(static::$currency)) {
|
||||
static::$currency = static::getOption(RetailcrmConstants::CRM_CURRENCY);
|
||||
}
|
||||
|
||||
return static::$currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps Bitrix COption::GetOptionString(...)
|
||||
*
|
||||
* @param string $option
|
||||
* @param int|string $def
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
private static function getOption($option, $def = 0)
|
||||
{
|
||||
return COption::GetOptionString(
|
||||
RetailcrmConstants::MODULE_ID,
|
||||
$option,
|
||||
$def
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps Bitrix unserialize(COption::GetOptionString(...))
|
||||
*
|
||||
* @param string $option
|
||||
* @param int|string $def
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function getUnserializedOption($option, $def = 0)
|
||||
{
|
||||
return unserialize(static::getOption($option, $def));
|
||||
}
|
||||
}
|
51
intaro.retailcrm/classes/general/RetailcrmConstants.php
Normal file
51
intaro.retailcrm/classes/general/RetailcrmConstants.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* Constants class
|
||||
*
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* Constants class
|
||||
*
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
class RetailcrmConstants
|
||||
{
|
||||
const MODULE_ID = 'intaro.retailcrm';
|
||||
const CRM_API_HOST_OPTION = 'api_host';
|
||||
const CRM_API_KEY_OPTION = 'api_key';
|
||||
const CRM_ORDER_TYPES_ARR = 'order_types_arr';
|
||||
const CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
||||
const CRM_PAYMENT_TYPES = 'pay_types_arr';
|
||||
const CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
|
||||
const CRM_PAYMENT = 'payment_arr'; //order payment Y/N
|
||||
const CRM_ORDER_LAST_ID = 'order_last_id';
|
||||
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_ORDER_FAILED_IDS = 'order_failed_ids';
|
||||
const CRM_ORDER_HISTORY_DATE = 'order_history_date';
|
||||
const CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
|
||||
const CRM_ORDER_NUMBERS = 'order_numbers';
|
||||
const CRM_ORDER_DIMENSIONS = 'order_dimensions';
|
||||
const CRM_CURRENCY = 'currency';
|
||||
const CRM_CC = 'cc';
|
||||
}
|
|
@ -325,15 +325,15 @@ class RetailCrmOrder
|
|||
public static function uploadOrders($pSize = 50, $failed = false, $orderList = false)
|
||||
{
|
||||
if (!CModule::IncludeModule("iblock")) {
|
||||
RCrmActions::eventLog('RetailCrmOrder::uploadOrders', 'iblock', 'module not found');
|
||||
RCrmActions::eventLog(__CLASS__ . '::' . __METHOD__, 'iblock', 'module not found');
|
||||
return true;
|
||||
}
|
||||
if (!CModule::IncludeModule("sale")) {
|
||||
RCrmActions::eventLog('RetailCrmOrder::uploadOrders', 'sale', 'module not found');
|
||||
RCrmActions::eventLog(__CLASS__ . '::' . __METHOD__, 'sale', 'module not found');
|
||||
return true;
|
||||
}
|
||||
if (!CModule::IncludeModule("catalog")) {
|
||||
RCrmActions::eventLog('RetailCrmOrder::uploadOrders', 'catalog', 'module not found');
|
||||
RCrmActions::eventLog(__CLASS__ . '::' . __METHOD__, 'catalog', 'module not found');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -366,20 +366,16 @@ class RetailCrmOrder
|
|||
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);
|
||||
|
||||
$optionCorpClient = COption::GetOptionString(self::$MODULE_ID, self::$CRM_CC, 0);
|
||||
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||
$optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0));
|
||||
$optionsDelivTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0));
|
||||
$optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0));
|
||||
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
|
||||
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
|
||||
$optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0));
|
||||
$optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
|
||||
$optionsContragentType = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CONTRAGENT_TYPE, 0));
|
||||
$optionsCustomFields = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CUSTOM_FIELDS, 0));
|
||||
$optionsSitesList = RetailcrmConfig::getSitesList();
|
||||
$optionsOrderTypes = RetailcrmConfig::getOrderTypes();
|
||||
$optionsDelivTypes = RetailcrmConfig::getDeliveryTypes();
|
||||
$optionsPayTypes = RetailcrmConfig::getPaymentTypes();
|
||||
$optionsPayStatuses = RetailcrmConfig::getPaymentStatuses(); // --statuses
|
||||
$optionsPayment = RetailcrmConfig::getPayment();
|
||||
$optionsOrderProps = RetailcrmConfig::getOrderProps();
|
||||
$optionsLegalDetails = RetailcrmConfig::getLegalDetails();
|
||||
$optionsContragentType = RetailcrmConfig::getContragentTypes();
|
||||
$optionsCustomFields = RetailcrmConfig::getCustomFields();
|
||||
|
||||
$getSite = function ($key) use ($optionsSitesList) {
|
||||
if ($optionsSitesList) {
|
||||
|
@ -393,7 +389,7 @@ class RetailCrmOrder
|
|||
return null;
|
||||
};
|
||||
|
||||
$api = new RetailCrm\ApiClient($api_host, $api_key);
|
||||
$api = new RetailCrm\ApiClient(RetailcrmConfig::getApiUrl(), RetailcrmConfig::getApiKey());
|
||||
|
||||
$arParams = array(
|
||||
'optionsOrderTypes' => $optionsOrderTypes,
|
||||
|
@ -428,7 +424,9 @@ class RetailCrmOrder
|
|||
continue;
|
||||
}
|
||||
|
||||
if ("Y" == $optionCorpClient && $optionsContragentType[$order['PERSON_TYPE_ID']] == 'legal-entity') {
|
||||
if ("Y" == RetailcrmConfig::getCorporateClient()
|
||||
&& $optionsContragentType[$order['PERSON_TYPE_ID']] == 'legal-entity'
|
||||
) {
|
||||
// TODO check if order is corporate, and if it IS - make corporate order
|
||||
$arCustomer = RetailCrmUser::customerSend(
|
||||
$user,
|
||||
|
@ -524,7 +522,7 @@ class RetailCrmOrder
|
|||
return false;
|
||||
}
|
||||
|
||||
if ("Y" == $optionCorpClient) {
|
||||
if ("Y" == RetailcrmConfig::getCorporateClient()) {
|
||||
foreach ($resOrders as $packKey => $pack) {
|
||||
foreach ($pack as $key => $orderData) {
|
||||
if (isset($orderData['contragent']['contragentType'])
|
||||
|
|
Loading…
Add table
Reference in a new issue