1
0
mirror of synced 2024-12-01 17:56:07 +03:00
bitrix-module/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php

859 lines
20 KiB
PHP
Raw Normal View History

2020-04-24 13:18:18 +03:00
<?php
/**
* PHP version 5.3
*
* RetailcrmConfigProvider class
*
2020-12-15 12:39:38 +03:00
* @category RetailCRM
* @package RetailCRM
2020-04-24 13:18:18 +03:00
*/
IncludeModuleLangFile(__FILE__);
/**
* PHP version 5.3
*
* RetailcrmConfigProvider class
*
2020-12-15 12:39:38 +03:00
* @category RetailCRM
* @package RetailCRM
2020-04-24 13:18:18 +03:00
*/
class RetailcrmConfigProvider
{
/** @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 $corporateClientName;
/** @var bool|null|string */
private static $corporateClientAddress;
/** @var bool|null|string */
private static $corporateClient;
2020-07-23 16:28:36 +03:00
/** @var bool|null|string $shipmentDeducted */
private static $shipmentDeducted;
2020-04-24 13:18:18 +03:00
/** @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;
/** @var array $deliveryTypes */
private static $deliveryTypes;
/** @var array $paymentTypes */
private static $paymentTypes;
/** @var array $integrationPayment */
private static $integrationPayment;
2020-04-24 13:18:18 +03:00
/** @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 $cancellableOrderPaymentStatuses */
private static $cancellableOrderPaymentStatuses;
/** @var array $customFields */
private static $customFields;
/** @var array $infoblocksInventories */
private static $infoblocksInventories;
/** @var array $stores */
private static $stores;
/** @var array $shops */
private static $shops;
/**
* @return bool|string|null
*/
public static function getApiUrl()
{
if (self::isEmptyNotZero(static::$apiUrl)) {
static::$apiUrl = static::getOption(RetailcrmConstants::CRM_API_HOST_OPTION);
}
return static::$apiUrl;
}
/**
* @return bool|string|null
*/
public static function getApiKey()
{
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
*
* @return bool|string|null
*/
public static function getCorporateClientStatus()
{
if (self::isEmptyNotZero(static::$corporateClient)) {
static::$corporateClient = static::getOption(RetailcrmConstants::CRM_CC);
}
return static::$corporateClient;
}
/**
* getSitesList
*
* @return array
*/
public static function getSitesList()
{
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;
}
2020-11-24 12:14:26 +03:00
/**
* isOnlineConsultantEnabled
*
* @return bool
*/
public static function isOnlineConsultantEnabled()
{
return static::getOption(RetailcrmConstants::CRM_ONLINE_CONSULTANT) === 'Y';
}
/**
* getOnlineConsultantScript
*
* @return string
*/
public static function getOnlineConsultantScript()
{
return trim(static::getOption(RetailcrmConstants::CRM_ONLINE_CONSULTANT_SCRIPT, ""));
}
/**
* setOnlineConsultant
*
* @param string $value
*/
public static function setOnlineConsultant($value)
{
static::setOption(RetailcrmConstants::CRM_ONLINE_CONSULTANT, $value);
}
2021-05-31 16:33:02 +03:00
/**
* @return bool|string|null
*/
public static function getCrmPurchasePrice()
{
return static::getOption(RetailcrmConstants::CRM_PURCHASE_PRICE_NULL);
}
public static function getProtocol()
{
return static::getOption(RetailcrmConstants::PROTOCOL);
}
/**
* @return string
*/
public static function getSiteName(): string
{
$siteName = COption::GetOptionString('main', 'site_name');
2021-05-31 16:33:02 +03:00
if (!$siteName) {
2021-05-31 16:33:02 +03:00
return '';
}
return $siteName;
2021-05-31 16:33:02 +03:00
}
/**
* @return mixed
*/
public static function getUsersMap()
{
return static::getUnserializedOption(RetailcrmConstants::CRM_USERS_MAP);
}
/**
* @param array|null $userMap
*
* @return bool
*/
public static function setUsersMap(?array $userMap): bool
{
return static::setOption(RetailcrmConstants::CRM_USERS_MAP, serialize($userMap));
}
2021-09-08 10:05:09 +03:00
/**
* @param $profileId
*
* @return false|string|null
*/
public static function getCrmBasePrice($profileId)
{
return self::getOption(RetailcrmConstants::CRM_CATALOG_BASE_PRICE . '_' . $profileId, 1);
}
public static function setProfileBasePrice($profileId, $priceTypes): void
{
self::setOption(
RetailcrmConstants::CRM_CATALOG_BASE_PRICE . '_' . $profileId,
htmlspecialchars(trim($priceTypes))
);
}
/**
* @return string
*/
public static function getDefaultIcmlPath(): string
{
return (COption::GetOptionString(
'catalog',
'export_default_path',
'/bitrix/catalog_export/'))
. 'retailcrm.xml';
}
2020-11-24 12:14:26 +03:00
/**
* setOnlineConsultantScript
*
* @param string $value
*/
public function setOnlineConsultantScript($value)
{
static::setOption(RetailcrmConstants::CRM_ONLINE_CONSULTANT_SCRIPT, $value);
}
2020-04-24 13:18:18 +03:00
/**
* getOrderTypes
*
* @return array
*/
public static function getOrderTypes()
{
if (self::isEmptyNotZero(static::$orderTypes)) {
static::$orderTypes = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR);
}
return static::$orderTypes;
}
/**
* setOrderTypes
*
* @param array $orderTypesArr
*/
public static function setOrderTypes($orderTypesArr)
{
static::setOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr)));
}
2020-04-24 13:18:18 +03:00
/**
* getDeliveryTypes
*
* @return array
*/
public static function getDeliveryTypes()
{
if (self::isEmptyNotZero(static::$deliveryTypes)) {
static::$deliveryTypes = static::getUnserializedOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR);
}
return static::$deliveryTypes;
}
/**
* setDeliveryTypes
*
* @param array $deliveryTypesArr
*/
public static function setDeliveryTypes($deliveryTypesArr)
{
static::setOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr)));
}
2020-04-24 13:18:18 +03:00
/**
* getPaymentTypes
*
* @return array
*/
public static function getPaymentTypes()
{
if (self::isEmptyNotZero(static::$paymentTypes)) {
static::$paymentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_TYPES);
}
return static::$paymentTypes;
}
/**
* getIntegrationPaymentTypes
*
* @return array
*/
public static function getIntegrationPaymentTypes(): array
{
if (self::isEmptyNotZero(static::$integrationPayment)) {
$option = static::getUnserializedOption(RetailcrmConstants::CRM_INTEGRATION_PAYMENT);
static::$integrationPayment = is_array($option) ? $option : [];
}
return static::$integrationPayment;
}
/**
* setIntegrationPaymentTypes
* @param $integrationPayment
*/
public static function setIntegrationPaymentTypes($integrationPayment)
{
static::setOption(RetailcrmConstants::CRM_INTEGRATION_PAYMENT, serialize(RCrmActions::clearArr($integrationPayment)));
}
/**
* setIntegrationDelivery
* @param $deliveryIntegrationCode
*/
public static function setIntegrationDelivery($deliveryIntegrationCode)
{
static::setOption(RetailcrmConstants::CRM_INTEGRATION_DELIVERY, serialize(RCrmActions::clearArr($deliveryIntegrationCode)));
}
/**
* setPaymentTypes
*
* @param array $paymentTypesArr
*/
public static function setPaymentTypes($paymentTypesArr)
{
static::setOption(RetailcrmConstants::CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr)));
}
2020-04-24 13:18:18 +03:00
/**
* getPaymentStatuses
*
* @return array
*/
public static function getPaymentStatuses()
{
if (self::isEmptyNotZero(static::$paymentStatuses)) {
static::$paymentStatuses = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_STATUSES);
}
return static::$paymentStatuses;
}
/**
* getPaymentStatuses
*
* @param array $paymentStatusesArr
*/
public static function setPaymentStatuses($paymentStatusesArr)
{
static::setOption(RetailcrmConstants::CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr)));
}
2020-04-24 13:18:18 +03:00
/**
* getPayment
*
* @return array
*/
public static function getPayment()
{
if (self::isEmptyNotZero(static::$payment)) {
static::$payment = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT);
}
return static::$payment;
}
/**
* getOrderProps
*
* @return array
*/
public static function getOrderProps()
{
if (self::isEmptyNotZero(static::$orderProps)) {
static::$orderProps = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_PROPS);
}
return static::$orderProps;
}
/**
* getLegalDetails
*
* @return array
*/
public static function getLegalDetails()
{
if (self::isEmptyNotZero(static::$legalDetails)) {
static::$legalDetails = static::getUnserializedOption(RetailcrmConstants::CRM_LEGAL_DETAILS);
}
return static::$legalDetails;
}
/**
* getContragentTypes
*
* @return array
*/
public static function getContragentTypes()
{
if (self::isEmptyNotZero(static::$contragentTypes)) {
static::$contragentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_CONTRAGENT_TYPE);
}
return static::$contragentTypes;
}
/**
* setContragentTypes
*
* @param array $contragentTypeArr
*/
public static function setContragentTypes($contragentTypeArr)
{
static::setOption(RetailcrmConstants::CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr)));
}
2020-04-24 13:18:18 +03:00
/**
* getCustomFields
*
* @return array
*/
public static function getCustomFields()
{
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
*
* @return bool|string|null
*/
public static function getLastOrderId()
{
return static::getOption(RetailcrmConstants::CRM_ORDER_LAST_ID);
}
/**
* getSendPaymentAmount
*
* @return bool|string|null
*/
public static function getSendPaymentAmount()
{
return static::getOption(RetailcrmConstants::SEND_PAYMENT_AMOUNT);
}
/**
* setSendPaymentAmount
*
* @param string $value
*/
public static function setSendPaymentAmount($value)
{
static::setOption(RetailcrmConstants::SEND_PAYMENT_AMOUNT, $value);
}
/**
2020-12-15 12:39:38 +03:00
* Returns true if payment amount should be sent from CMS to RetailCRM.
*
* @return bool|string|null
*/
public static function shouldSendPaymentAmount()
{
return static::getSendPaymentAmount() === 'Y';
}
2020-04-24 13:18:18 +03:00
/**
* setLastOrderId
*
* @param $id
*/
public static function setLastOrderId($id)
{
static::setOption(RetailcrmConstants::CRM_ORDER_LAST_ID, $id);
}
/**
* getFailedOrdersIds
*
* @return array
*/
public static function getFailedOrdersIds()
{
return static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_FAILED_IDS);
}
/**
* setFailedOrdersIds
*
* @param $ids
*/
public static function setFailedOrdersIds($ids)
{
static::setOption(RetailcrmConstants::CRM_ORDER_FAILED_IDS, serialize($ids));
}
/**
* getOrderNumbers
*
* @return bool|string|null
*/
public static function getOrderNumbers()
{
if (self::isEmptyNotZero(self::$orderNumbers)) {
self::$orderNumbers = static::getOption(RetailcrmConstants::CRM_ORDER_NUMBERS);
}
return self::$orderNumbers;
}
/**
* getOrderHistoryDate
*
* @return bool|string|null
*/
public static function getOrderHistoryDate()
{
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);
}
2020-04-24 13:18:18 +03:00
/**
* getCatalogBasePrice
*
* @return bool|string|null
*/
public static function getCatalogBasePrice()
{
if (self::isEmptyNotZero(static::$catalogBasePrice)) {
static::$catalogBasePrice = static::getOption(RetailcrmConstants::CRM_CATALOG_BASE_PRICE);
}
return static::$catalogBasePrice;
}
2021-05-31 16:33:02 +03:00
/**
* @param $profileId
*
* @return false|string|null
*/
public static function getCatalogBasePriceByProfile($profileId)
{
return COption::GetOptionString(
RetailcrmConstants::MODULE_ID,
RetailcrmConstants::CRM_CATALOG_BASE_PRICE . '_' . $profileId,
0
);
}
2020-04-24 13:18:18 +03:00
/**
* getOrderDimensions
*
* @return bool|string|null
*/
public static function getOrderDimensions()
{
if (self::isEmptyNotZero(static::$orderDimensions)) {
static::$orderDimensions = static::getOption(RetailcrmConstants::CRM_ORDER_DIMENSIONS, 'N');
}
return static::$orderDimensions;
}
/**
* getCurrency
*
* @return bool|string|null
*/
public static function getCurrency()
{
if (self::isEmptyNotZero(static::$currency)) {
static::$currency = static::getOption(RetailcrmConstants::CRM_CURRENCY);
}
return static::$currency;
}
/**
* Returns currency from settings. If it's not set - returns Bitrix base currency.
*
* @return bool|string|null
*/
public static function getCurrencyOrDefault()
{
return self::getCurrency() ? self::getCurrency() : \Bitrix\Currency\CurrencyManager::getBaseCurrency();
}
/**
* getInfoblocksInventories
*
* @return array
*/
public static function getInfoblocksInventories()
{
if (self::isEmptyNotZero(static::$infoblocksInventories)) {
static::$infoblocksInventories = static::getUnserializedOption(
RetailcrmConstants::CRM_IBLOCKS_INVENTORIES
);
}
return static::$infoblocksInventories;
}
/**
* getStores
*
* @return array
*/
public static function getStores()
{
if (self::isEmptyNotZero(static::$stores)) {
static::$stores = static::getUnserializedOption(RetailcrmConstants::CRM_STORES);
}
return static::$stores;
}
/**
* getShops
*
* @return array
*/
public static function getShops()
{
if (self::isEmptyNotZero(static::$shops)) {
static::$shops = static::getUnserializedOption(RetailcrmConstants::CRM_SHOPS);
}
return static::$shops;
}
2020-07-23 16:28:36 +03:00
/**
* getShipmentDeducted
*
* @return bool|string|null
*/
public static function getShipmentDeducted()
{
if (self::isEmptyNotZero(static::$shipmentDeducted)) {
static::$shipmentDeducted = static::getOption(RetailcrmConstants::CRM_SHIPMENT_DEDUCTED);
}
2020-04-24 13:18:18 +03:00
2020-07-23 16:28:36 +03:00
return static::$shipmentDeducted;
}
2020-07-23 14:49:55 +03:00
/**
* isPhoneRequired
*
* @return bool|string|null
*/
public static function isPhoneRequired()
{
return COption::GetOptionString("main", "new_user_phone_required") === 'Y';
}
/**
* Return integration_delivery option
*
* @return mixed
*/
public static function getCrmIntegrationDelivery()
{
return static::getUnserializedOption(RetailcrmConstants::CRM_INTEGRATION_DELIVERY);
}
2020-04-24 13:18:18 +03:00
/**
* 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
);
}
/**
* setOption
*
* @param $name
* @param string $value
* @param bool $desc
* @param string $site
*/
private static function setOption($name, string $value = '', bool $desc = false, string $site = ''): bool
2020-04-24 13:18:18 +03:00
{
return COption::SetOptionString(
2020-04-24 13:18:18 +03:00
RetailcrmConstants::MODULE_ID,
$name,
$value,
$desc,
$site
);
}
/**
* 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));
}
/**
* 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;
}
}