WIP: move already refactored components to the new structure, first code for repositories
This commit is contained in:
parent
879162f0ef
commit
c2778b4382
12 changed files with 866 additions and 712 deletions
|
@ -3,7 +3,7 @@
|
|||
/**
|
||||
* Class Logger
|
||||
*
|
||||
* @author pavel
|
||||
* @author retailCRM
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://help.retailcrm.pro/docs/Developers
|
||||
*/
|
||||
|
|
|
@ -25,583 +25,6 @@ IncludeModuleLangFile(__FILE__);
|
|||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
class RetailcrmConfigProvider
|
||||
class RetailcrmConfigProvider extends \Intaro\RetailCrm\Component\ConfigProvider
|
||||
{
|
||||
/** @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;
|
||||
|
||||
/** @var bool|null|string $shipmentDeducted */
|
||||
private static $shipmentDeducted;
|
||||
|
||||
/** @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 $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderTypes()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$orderTypes)) {
|
||||
static::$orderTypes = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR);
|
||||
}
|
||||
|
||||
return static::$orderTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDeliveryTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getDeliveryTypes()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$deliveryTypes)) {
|
||||
static::$deliveryTypes = static::getUnserializedOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR);
|
||||
}
|
||||
|
||||
return static::$deliveryTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPaymentTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaymentTypes()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$paymentTypes)) {
|
||||
static::$paymentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_TYPES);
|
||||
}
|
||||
|
||||
return static::$paymentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPaymentStatuses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaymentStatuses()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$paymentStatuses)) {
|
||||
static::$paymentStatuses = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_STATUSES);
|
||||
}
|
||||
|
||||
return static::$paymentStatuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* getShipmentDeducted
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getShipmentDeducted()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$shipmentDeducted)) {
|
||||
static::$shipmentDeducted = static::getOption(RetailcrmConstants::CRM_SHIPMENT_DEDUCTED);
|
||||
}
|
||||
|
||||
return static::$shipmentDeducted;
|
||||
}
|
||||
|
||||
/**
|
||||
* isPhoneRequired
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function isPhoneRequired()
|
||||
{
|
||||
return COption::GetOptionString("main", "new_user_phone_required") === 'Y';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, $value = "", $desc = false, $site = "")
|
||||
{
|
||||
COption::SetOptionString(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,56 +25,6 @@ IncludeModuleLangFile(__FILE__);
|
|||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
class RetailcrmConstants
|
||||
class RetailcrmConstants extends \Intaro\RetailCrm\Component\Constants
|
||||
{
|
||||
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_DELIVERY_SERVICES_ARR = 'deliv_services_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_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_CORPORATE = 'shops-corporate';
|
||||
const CRM_ORDER_NUMBERS = 'order_numbers';
|
||||
const CRM_CANCEL_ORDER = 'cansel_order';
|
||||
const CRM_INVENTORIES_UPLOAD = 'inventories_upload';
|
||||
const CRM_STORES = 'stores';
|
||||
const CRM_SHOPS = 'shops';
|
||||
const CRM_IBLOCKS_INVENTORIES = 'iblocks_inventories';
|
||||
const CRM_PRICES_UPLOAD = 'prices_upload';
|
||||
const CRM_PRICES = 'prices';
|
||||
const CRM_PRICE_SHOPS = 'price_shops';
|
||||
const CRM_IBLOCKS_PRICES = 'iblock_prices';
|
||||
const CRM_COLLECTOR = 'collector';
|
||||
const CRM_COLL_KEY = 'coll_key';
|
||||
const CRM_UA = 'ua';
|
||||
const CRM_UA_KEYS = 'ua_keys';
|
||||
const CRM_DISCOUNT_ROUND = 'discount_round';
|
||||
const CRM_CC = 'cc';
|
||||
const CRM_CORP_SHOPS = 'shops-corporate';
|
||||
const CRM_CORP_NAME = 'nickName-corporate';
|
||||
const CRM_CORP_ADDRESS = 'adres-corporate';
|
||||
const CRM_API_VERSION = 'api_version';
|
||||
const CRM_CURRENCY = 'currency';
|
||||
const CRM_ADDRESS_OPTIONS = 'address_options';
|
||||
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';
|
||||
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
|
||||
const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
|
||||
const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
|
||||
}
|
||||
|
|
|
@ -25,80 +25,6 @@ IncludeModuleLangFile(__FILE__);
|
|||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
class RetailcrmDependencyLoader
|
||||
class RetailcrmDependencyLoader extends \Intaro\RetailCrm\Component\DependencyLoader
|
||||
{
|
||||
/** @var int */
|
||||
const LEGACY_LOADER = 0;
|
||||
|
||||
/** @var int */
|
||||
const D7_LOADER = 1;
|
||||
|
||||
/** @var int $loader */
|
||||
private static $loader = self::D7_LOADER;
|
||||
|
||||
/**
|
||||
* Loads dependencies
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function loadDependencies()
|
||||
{
|
||||
foreach (self::getDependencies() as $dependency) {
|
||||
if (self::LEGACY_LOADER == self::$loader) {
|
||||
if (!CModule::IncludeModule($dependency)) {
|
||||
RCrmActions::eventLog(
|
||||
__CLASS__ . '::' . __METHOD__,
|
||||
$dependency,
|
||||
'module not found'
|
||||
);
|
||||
|
||||
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
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return array("iblock", "sale", "catalog");
|
||||
}
|
||||
}
|
||||
|
|
616
intaro.retailcrm/lib/component/configprovider.php
Normal file
616
intaro.retailcrm/lib/component/configprovider.php
Normal file
|
@ -0,0 +1,616 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component;
|
||||
|
||||
use Bitrix\Main\ArgumentNullException;
|
||||
use Bitrix\Main\ArgumentOutOfRangeException;
|
||||
use Bitrix\Main\Config\Option;
|
||||
|
||||
/**
|
||||
* Class ConfigProvider
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component
|
||||
*/
|
||||
class ConfigProvider
|
||||
{
|
||||
/** @var bool|null|string */
|
||||
protected static $apiUrl;
|
||||
|
||||
/** @var bool|null|string */
|
||||
protected static $apiKey;
|
||||
|
||||
/** @var bool|null|string */
|
||||
protected static $catalogBasePrice;
|
||||
|
||||
/** @var bool|null|string */
|
||||
protected static $currency;
|
||||
|
||||
/** @var bool|null|string */
|
||||
protected static $orderDimensions;
|
||||
|
||||
/** @var bool|null|string */
|
||||
protected static $corporateClientName;
|
||||
|
||||
/** @var bool|null|string */
|
||||
protected static $corporateClientAddress;
|
||||
|
||||
/** @var bool|null|string */
|
||||
protected static $corporateClient;
|
||||
|
||||
/** @var bool|null|string $shipmentDeducted */
|
||||
protected static $shipmentDeducted;
|
||||
|
||||
/** @var array $sitesList */
|
||||
protected static $sitesList;
|
||||
|
||||
/** @var array $sitesListCorporate */
|
||||
protected static $sitesListCorporate;
|
||||
|
||||
/** @var bool|null|string $orderNumbers */
|
||||
protected static $orderNumbers;
|
||||
|
||||
/** @var array $orderTypes */
|
||||
protected static $orderTypes;
|
||||
|
||||
/** @var array $deliveryTypes */
|
||||
protected static $deliveryTypes;
|
||||
|
||||
/** @var array $paymentTypes */
|
||||
protected static $paymentTypes;
|
||||
|
||||
/** @var array $paymentStatuses */
|
||||
protected static $paymentStatuses;
|
||||
|
||||
/** @var array $payment */
|
||||
protected static $payment;
|
||||
|
||||
/** @var array $orderProps */
|
||||
protected static $orderProps;
|
||||
|
||||
/** @var array $legalDetails */
|
||||
protected static $legalDetails;
|
||||
|
||||
/** @var array $contragentTypes */
|
||||
protected static $contragentTypes;
|
||||
|
||||
/** @var array $cancellableOrderPaymentStatuses */
|
||||
protected static $cancellableOrderPaymentStatuses;
|
||||
|
||||
/** @var array $customFields */
|
||||
protected static $customFields;
|
||||
|
||||
/** @var array $infoblocksInventories */
|
||||
protected static $infoblocksInventories;
|
||||
|
||||
/** @var array $stores */
|
||||
protected static $stores;
|
||||
|
||||
/** @var array $shops */
|
||||
protected static $shops;
|
||||
|
||||
/**
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getApiUrl()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$apiUrl)) {
|
||||
static::$apiUrl = static::getOption(Constants::CRM_API_HOST_OPTION);
|
||||
}
|
||||
|
||||
return static::$apiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getApiKey()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$apiKey)) {
|
||||
static::$apiKey = static::getOption(Constants::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(Constants::CRM_CORP_NAME);
|
||||
}
|
||||
|
||||
return static::$corporateClientName;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCorporateClientAddress
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getCorporateClientAddress()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$corporateClientAddress)) {
|
||||
static::$corporateClientAddress = static::getUnserializedOption(Constants::CRM_CORP_ADDRESS);
|
||||
}
|
||||
|
||||
return static::$corporateClientAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCorporateClient
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getCorporateClientStatus()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$corporateClient)) {
|
||||
static::$corporateClient = static::getOption(Constants::CRM_CC);
|
||||
}
|
||||
|
||||
return static::$corporateClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* getSitesList
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSitesList(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$sitesList)) {
|
||||
static::$sitesList = static::getUnserializedOption(Constants::CRM_SITES_LIST);
|
||||
}
|
||||
|
||||
return static::$sitesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* getSitesListCorporate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSitesListCorporate(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$sitesListCorporate)) {
|
||||
static::$sitesListCorporate = static::getUnserializedOption(
|
||||
Constants::CRM_SITES_LIST_CORPORATE
|
||||
);
|
||||
}
|
||||
|
||||
return static::$sitesListCorporate;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderTypes(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$orderTypes)) {
|
||||
static::$orderTypes = static::getUnserializedOption(Constants::CRM_ORDER_TYPES_ARR);
|
||||
}
|
||||
|
||||
return static::$orderTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDeliveryTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getDeliveryTypes(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$deliveryTypes)) {
|
||||
static::$deliveryTypes = static::getUnserializedOption(Constants::CRM_DELIVERY_TYPES_ARR);
|
||||
}
|
||||
|
||||
return static::$deliveryTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPaymentTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaymentTypes(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$paymentTypes)) {
|
||||
static::$paymentTypes = static::getUnserializedOption(Constants::CRM_PAYMENT_TYPES);
|
||||
}
|
||||
|
||||
return static::$paymentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPaymentStatuses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPaymentStatuses(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$paymentStatuses)) {
|
||||
static::$paymentStatuses = static::getUnserializedOption(Constants::CRM_PAYMENT_STATUSES);
|
||||
}
|
||||
|
||||
return static::$paymentStatuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPayment
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPayment(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$payment)) {
|
||||
static::$payment = static::getUnserializedOption(Constants::CRM_PAYMENT);
|
||||
}
|
||||
|
||||
return static::$payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderProps
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderProps(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$orderProps)) {
|
||||
static::$orderProps = static::getUnserializedOption(Constants::CRM_ORDER_PROPS);
|
||||
}
|
||||
|
||||
return static::$orderProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* getLegalDetails
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getLegalDetails(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$legalDetails)) {
|
||||
static::$legalDetails = static::getUnserializedOption(Constants::CRM_LEGAL_DETAILS);
|
||||
}
|
||||
|
||||
return static::$legalDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* getContragentTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getContragentTypes(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$contragentTypes)) {
|
||||
static::$contragentTypes = static::getUnserializedOption(Constants::CRM_CONTRAGENT_TYPE);
|
||||
}
|
||||
|
||||
return static::$contragentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCustomFields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCustomFields(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$customFields)) {
|
||||
static::$customFields = static::getUnserializedOption(Constants::CRM_CUSTOM_FIELDS);
|
||||
}
|
||||
|
||||
return static::$customFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCancellableOrderPaymentStatuses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCancellableOrderPaymentStatuses(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$cancellableOrderPaymentStatuses)) {
|
||||
static::$cancellableOrderPaymentStatuses = static::getUnserializedOption(
|
||||
Constants::CRM_CANCEL_ORDER
|
||||
);
|
||||
}
|
||||
|
||||
return static::$cancellableOrderPaymentStatuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* getLastOrderId
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getLastOrderId()
|
||||
{
|
||||
return static::getOption(Constants::CRM_ORDER_LAST_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* setLastOrderId
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public static function setLastOrderId($id): void
|
||||
{
|
||||
static::setOption(Constants::CRM_ORDER_LAST_ID, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* getFailedOrdersIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getFailedOrdersIds(): array
|
||||
{
|
||||
return static::getUnserializedOption(Constants::CRM_ORDER_FAILED_IDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* setFailedOrdersIds
|
||||
*
|
||||
* @param $ids
|
||||
*/
|
||||
public static function setFailedOrdersIds($ids): void
|
||||
{
|
||||
static::setOption(Constants::CRM_ORDER_FAILED_IDS, serialize($ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderNumbers
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getOrderNumbers()
|
||||
{
|
||||
if (self::isEmptyNotZero(self::$orderNumbers)) {
|
||||
self::$orderNumbers = static::getOption(Constants::CRM_ORDER_NUMBERS);
|
||||
}
|
||||
|
||||
return self::$orderNumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderHistoryDate
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getOrderHistoryDate()
|
||||
{
|
||||
return static::getOption(Constants::CRM_ORDER_HISTORY_DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns customers history since ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getCustomersHistorySinceId(): int
|
||||
{
|
||||
return (int) static::getOption(Constants::CRM_CUSTOMERS_HISTORY_SINCE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new customers history since ID
|
||||
*
|
||||
* @param int $sinceId
|
||||
*/
|
||||
public static function setCustomersHistorySinceId($sinceId): void
|
||||
{
|
||||
static::setOption(Constants::CRM_CUSTOMERS_HISTORY_SINCE_ID, $sinceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* getCatalogBasePrice
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getCatalogBasePrice()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$catalogBasePrice)) {
|
||||
static::$catalogBasePrice = static::getOption(Constants::CRM_CATALOG_BASE_PRICE);
|
||||
}
|
||||
|
||||
return static::$catalogBasePrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderDimensions
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getOrderDimensions()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$orderDimensions)) {
|
||||
static::$orderDimensions = static::getOption(Constants::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(Constants::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(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$infoblocksInventories)) {
|
||||
static::$infoblocksInventories = static::getUnserializedOption(
|
||||
Constants::CRM_IBLOCKS_INVENTORIES
|
||||
);
|
||||
}
|
||||
|
||||
return static::$infoblocksInventories;
|
||||
}
|
||||
|
||||
/**
|
||||
* getStores
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStores(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$stores)) {
|
||||
static::$stores = static::getUnserializedOption(Constants::CRM_STORES);
|
||||
}
|
||||
|
||||
return static::$stores;
|
||||
}
|
||||
|
||||
/**
|
||||
* getShops
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getShops(): array
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$shops)) {
|
||||
static::$shops = static::getUnserializedOption(Constants::CRM_SHOPS);
|
||||
}
|
||||
|
||||
return static::$shops;
|
||||
}
|
||||
|
||||
/**
|
||||
* getShipmentDeducted
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function getShipmentDeducted()
|
||||
{
|
||||
if (self::isEmptyNotZero(static::$shipmentDeducted)) {
|
||||
static::$shipmentDeducted = static::getOption(Constants::CRM_SHIPMENT_DEDUCTED);
|
||||
}
|
||||
|
||||
return static::$shipmentDeducted;
|
||||
}
|
||||
|
||||
/**
|
||||
* isPhoneRequired
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public static function isPhoneRequired()
|
||||
{
|
||||
return static::getExternalOption("main", "new_user_phone_required") === 'Y';
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps Bitrix \COption::GetOptionString(...)
|
||||
*
|
||||
* @param string $option
|
||||
* @param int|string $def
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected static function getOption($option, $def = 0): ?string
|
||||
{
|
||||
return static::getExternalOption(Constants::MODULE_ID, $option, $def);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns option from provided module
|
||||
*
|
||||
* @param string $moduleId
|
||||
* @param string $option
|
||||
* @param int $def
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected static function getExternalOption(string $moduleId, string $option, $def = 0): ?string
|
||||
{
|
||||
try {
|
||||
return Option::get($moduleId, $option, $def);
|
||||
} catch (ArgumentNullException | ArgumentOutOfRangeException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setOption
|
||||
*
|
||||
* @param $name
|
||||
* @param string $value
|
||||
* @param string $site
|
||||
*
|
||||
* @throws \Bitrix\Main\ArgumentOutOfRangeException
|
||||
*/
|
||||
protected static function setOption($name, $value = "", $site = ""): void
|
||||
{
|
||||
Option::set(
|
||||
Constants::MODULE_ID,
|
||||
$name,
|
||||
$value,
|
||||
$site
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps Bitrix unserialize(\COption::GetOptionString(...))
|
||||
*
|
||||
* @param string $option
|
||||
* @param int|string $def
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function getUnserializedOption($option, $def = 0)
|
||||
{
|
||||
return unserialize(static::getOption($option, $def), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if value is empty and not zero (0 - digit)
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isEmptyNotZero($value): bool
|
||||
{
|
||||
return empty($value) && $value !== 0;
|
||||
}
|
||||
}
|
71
intaro.retailcrm/lib/component/constants.php
Normal file
71
intaro.retailcrm/lib/component/constants.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component;
|
||||
|
||||
/**
|
||||
* Class Constants
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component
|
||||
*/
|
||||
class Constants
|
||||
{
|
||||
public const MODULE_ID = 'intaro.retailcrm';
|
||||
public const CRM_API_HOST_OPTION = 'api_host';
|
||||
public const CRM_API_KEY_OPTION = 'api_key';
|
||||
public const CRM_ORDER_TYPES_ARR = 'order_types_arr';
|
||||
public const CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
||||
public const CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr';
|
||||
public const CRM_PAYMENT_TYPES = 'pay_types_arr';
|
||||
public const CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
|
||||
public const CRM_PAYMENT = 'payment_arr'; //order payment Y/N
|
||||
public const CRM_ORDER_LAST_ID = 'order_last_id';
|
||||
public const CRM_ORDER_SITES = 'sites_ids';
|
||||
public const CRM_ORDER_DISCHARGE = 'order_discharge';
|
||||
public const CRM_SITES_LIST = 'sites_list';
|
||||
public const CRM_ORDER_PROPS = 'order_props';
|
||||
public const CRM_LEGAL_DETAILS = 'legal_details';
|
||||
public const CRM_CUSTOM_FIELDS = 'custom_fields';
|
||||
public const CRM_CONTRAGENT_TYPE = 'contragent_type';
|
||||
public const CRM_SITES_LIST_CORPORATE = 'shops-corporate';
|
||||
public const CRM_ORDER_NUMBERS = 'order_numbers';
|
||||
public const CRM_CANCEL_ORDER = 'cansel_order';
|
||||
public const CRM_INVENTORIES_UPLOAD = 'inventories_upload';
|
||||
public const CRM_STORES = 'stores';
|
||||
public const CRM_SHOPS = 'shops';
|
||||
public const CRM_IBLOCKS_INVENTORIES = 'iblocks_inventories';
|
||||
public const CRM_PRICES_UPLOAD = 'prices_upload';
|
||||
public const CRM_PRICES = 'prices';
|
||||
public const CRM_PRICE_SHOPS = 'price_shops';
|
||||
public const CRM_IBLOCKS_PRICES = 'iblock_prices';
|
||||
public const CRM_COLLECTOR = 'collector';
|
||||
public const CRM_COLL_KEY = 'coll_key';
|
||||
public const CRM_UA = 'ua';
|
||||
public const CRM_UA_KEYS = 'ua_keys';
|
||||
public const CRM_DISCOUNT_ROUND = 'discount_round';
|
||||
public const CRM_CC = 'cc';
|
||||
public const CRM_CORP_SHOPS = 'shops-corporate';
|
||||
public const CRM_CORP_NAME = 'nickName-corporate';
|
||||
public const CRM_CORP_ADDRESS = 'adres-corporate';
|
||||
public const CRM_API_VERSION = 'api_version';
|
||||
public const CRM_CURRENCY = 'currency';
|
||||
public const CRM_ADDRESS_OPTIONS = 'address_options';
|
||||
public const CRM_DIMENSIONS = 'order_dimensions';
|
||||
public const PROTOCOL = 'protocol';
|
||||
public const CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
||||
public const CRM_CUSTOMERS_HISTORY_SINCE_ID = 'customer_history';
|
||||
public const CRM_ORDER_HISTORY_DATE = 'order_history_date';
|
||||
public const CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
|
||||
public const CRM_ORDER_DIMENSIONS = 'order_dimensions';
|
||||
public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
|
||||
public const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
|
||||
public const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
|
||||
}
|
95
intaro.retailcrm/lib/component/dependencyloader.php
Normal file
95
intaro.retailcrm/lib/component/dependencyloader.php
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component;
|
||||
|
||||
/**
|
||||
* Class DependencyLoader
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component
|
||||
*/
|
||||
class DependencyLoader
|
||||
{
|
||||
/** @var int */
|
||||
const LEGACY_LOADER = 0;
|
||||
|
||||
/** @var int */
|
||||
const D7_LOADER = 1;
|
||||
|
||||
/** @var int $loader */
|
||||
private static $loader = self::D7_LOADER;
|
||||
|
||||
/**
|
||||
* Loads dependencies
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function loadDependencies()
|
||||
{
|
||||
foreach (self::getDependencies() as $dependency) {
|
||||
if (self::LEGACY_LOADER == self::$loader) {
|
||||
if (!CModule::IncludeModule($dependency)) {
|
||||
RCrmActions::eventLog(
|
||||
__CLASS__ . '::' . __METHOD__,
|
||||
$dependency,
|
||||
'module not found'
|
||||
);
|
||||
|
||||
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
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return array("iblock", "sale", "catalog");
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ namespace Intaro\RetailCrm\Component\Json\Strategy\Deserialize;
|
|||
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Accessor;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Name;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\SerializedName;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Type;
|
||||
use Intaro\RetailCrm\Component\Json\Strategy\AnnotationReaderTrait;
|
||||
use Intaro\RetailCrm\Component\Json\Strategy\StrategyFactory;
|
||||
|
@ -71,10 +71,10 @@ class EntityStrategy implements DeserializeStrategyInterface
|
|||
$type = '';
|
||||
$name = $property->getName();
|
||||
$accessorData = static::annotationReader()->getPropertyAnnotation($property, Accessor::class);
|
||||
$nameData = static::annotationReader()->getPropertyAnnotation($property, Name::class);
|
||||
$nameData = static::annotationReader()->getPropertyAnnotation($property, SerializedName::class);
|
||||
$typeData = static::annotationReader()->getPropertyAnnotation($property, Type::class);
|
||||
|
||||
if ($nameData instanceof Name) {
|
||||
if ($nameData instanceof SerializedName) {
|
||||
$name = !empty($nameData->name) ? $nameData->name : $name;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Intaro\RetailCrm\Component\Json\Strategy\Serialize;
|
|||
|
||||
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Accessor;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Name;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\SerializedName;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\Type;
|
||||
use Intaro\RetailCrm\Component\Json\Strategy\AnnotationReaderTrait;
|
||||
use Intaro\RetailCrm\Component\Json\Strategy\StrategyFactory;
|
||||
|
@ -69,10 +69,10 @@ class EntityStrategy implements SerializeStrategyInterface
|
|||
$value = $property->getValue($object);
|
||||
}
|
||||
|
||||
$nameData = static::annotationReader()->getPropertyAnnotation($property, Name::class);
|
||||
$nameData = static::annotationReader()->getPropertyAnnotation($property, SerializedName::class);
|
||||
$typeData = static::annotationReader()->getPropertyAnnotation($property, Type::class);
|
||||
|
||||
if ($nameData instanceof Name) {
|
||||
if ($nameData instanceof SerializedName) {
|
||||
$name = !empty($nameData->name) ? $nameData->name : $name;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ class Customer extends AbstractApiModel
|
|||
public $contragent;
|
||||
|
||||
/**
|
||||
* Список пользователских полей
|
||||
* Список пользовательских полей
|
||||
*
|
||||
* @var array $customFields
|
||||
*
|
||||
|
|
34
intaro.retailcrm/lib/repository/abstractrepository.php
Normal file
34
intaro.retailcrm/lib/repository/abstractrepository.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Model\Api
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Repository;
|
||||
|
||||
use Bitrix\Main\ORM\Entity;
|
||||
|
||||
/**
|
||||
* Class AbstractRepository
|
||||
*
|
||||
* @package Intaro\RetailCrm\Repository
|
||||
*/
|
||||
class AbstractRepository
|
||||
{
|
||||
/**
|
||||
* Returns fields list for entity
|
||||
*
|
||||
* @param \Bitrix\Main\ORM\Entity $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getEntityFields(Entity $entity): array
|
||||
{
|
||||
return array_keys($entity->getFields());
|
||||
}
|
||||
}
|
39
intaro.retailcrm/lib/repository/userrepository.php
Normal file
39
intaro.retailcrm/lib/repository/userrepository.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Model\Api
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Repository;
|
||||
|
||||
use Bitrix\Main\ORM\Objectify\EntityObject;
|
||||
use Bitrix\Main\UserTable;
|
||||
|
||||
/**
|
||||
* Class UserRepository
|
||||
*
|
||||
* @package Intaro\RetailCrm\Repository
|
||||
*/
|
||||
class UserRepository extends AbstractRepository
|
||||
{
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Bitrix\Main\ORM\Objectify\EntityObject|null
|
||||
* @throws \Bitrix\Main\ArgumentException
|
||||
* @throws \Bitrix\Main\ObjectPropertyException
|
||||
* @throws \Bitrix\Main\SystemException
|
||||
*/
|
||||
public function getById(int $id): ?EntityObject
|
||||
{
|
||||
$result = (UserTable::query())
|
||||
->setSelect($this->getEntityFields(UserTable::getEntity()))
|
||||
->addFilter('=ID', $id)->exec();
|
||||
return $result->fetchObject();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue