1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

Loyalty feature installer (#118)

* fixes for crash during the installation
* add LP activate option
This commit is contained in:
Сергей Чазов 2020-08-24 09:33:43 +03:00 committed by Павел
parent 2538fc2b4c
commit c03fd3b3e0
14 changed files with 1431 additions and 1097 deletions

View file

@ -0,0 +1,11 @@
<?php
return [
'controllers' => [
'value' => [
'namespaces' => [
'\\Intaro\\RetailCrm\\Controller' => 'api'
],
],
'readonly' => true,
]
];

View file

@ -1,5 +1,12 @@
<?php
use Intaro\RetailCrm\Component\ServiceLocator;
IncludeModuleLangFile(__FILE__);
require_once __DIR__ . '/../../lib/component/servicelocator.php';
require_once __DIR__ . '/../../lib/service/utils.php';
class RCrmActions
{
public static $MODULE_ID = 'intaro.retailcrm';
@ -227,7 +234,7 @@ class RCrmActions
public static function clearArr($arr)
{
/** @var \Intaro\RetailCrm\Service\Utils $utils */
$utils = \Intaro\RetailCrm\Component\ServiceLocator::get(\Intaro\RetailCrm\Service\Utils::class);
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
return $utils->clearArray($arr);
}
@ -240,7 +247,7 @@ class RCrmActions
public static function toJSON($str)
{
/** @var \Intaro\RetailCrm\Service\Utils $utils */
$utils = \Intaro\RetailCrm\Component\ServiceLocator::get(\Intaro\RetailCrm\Service\Utils::class);
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
return $utils->toUTF8($str);
}
@ -253,7 +260,7 @@ class RCrmActions
public static function fromJSON($str)
{
/** @var \Intaro\RetailCrm\Service\Utils $utils */
$utils = \Intaro\RetailCrm\Component\ServiceLocator::get(\Intaro\RetailCrm\Service\Utils::class);
$utils = ServiceLocator::get(\Intaro\RetailCrm\Service\Utils::class);
return $utils->fromUTF8($str);
}

View file

@ -12,8 +12,12 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
use Intaro\RetailCrm\Component\ConfigProvider;
IncludeModuleLangFile(__FILE__);
require_once __DIR__ . '/../../lib/component/configprovider.php';
/**
* PHP version 5.3
*
@ -25,6 +29,6 @@ IncludeModuleLangFile(__FILE__);
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class RetailcrmConfigProvider extends \Intaro\RetailCrm\Component\ConfigProvider
class RetailcrmConfigProvider extends ConfigProvider
{
}

View file

@ -12,8 +12,12 @@
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
use Intaro\RetailCrm\Component\Constants;
IncludeModuleLangFile(__FILE__);
require_once __DIR__ . '/../../lib/component/constants.php';
/**
* PHP version 5.3
*
@ -25,6 +29,6 @@ IncludeModuleLangFile(__FILE__);
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion4
*/
class RetailcrmConstants extends \Intaro\RetailCrm\Component\Constants
class RetailcrmConstants extends Constants
{
}

View file

@ -14,6 +14,8 @@
IncludeModuleLangFile(__FILE__);
require_once __DIR__ . '/../../lib/component/dependencyloader.php';
/**
* PHP version 5.3
*

File diff suppressed because it is too large Load diff

View file

@ -68,6 +68,8 @@ $MESS ['MESS_2'] = 'Произошла ошибка сервера, обрати
$MESS ['ORDER_TYPES_LIST_CUSTOM'] = 'Внимание! Используется не стандартное соответвие типов заказов.';
$MESS ['ORDER_UPL_START'] = 'Начать выгрузку';
$MESS ['LOYALTY_PROGRAM_TITLE'] = 'Программа лояльности';
$MESS ['LOYALTY_PROGRAM_TOGGLE_MSG'] = 'Включить программу лояльности';
$MESS ['OTHER_OPTIONS'] = 'Прочие настройки';
$MESS ['ORDERS_OPTIONS'] = 'Настройки заказов';
$MESS ['ORDER_NUMBERS'] = 'Транслировать номера заказов созданных в црм в магазин';

View file

@ -156,7 +156,8 @@ trait CustomersTrait
*
* @return CustomerChangeResponse|null
*/
public function customersEdit(CustomersEditRequest $request): ?CustomerChangeResponse {
public function customersEdit(CustomersEditRequest $request): ?CustomerChangeResponse
{
$serialized = Serializer::serializeArray($request);
$response = $this->client->customersEdit($serialized['customer'], $request->by, $request->site);

View file

@ -11,6 +11,7 @@
*/
namespace Intaro\RetailCrm\Component;
use Bitrix\Currency\CurrencyManager;
use Bitrix\Main\ArgumentNullException;
use Bitrix\Main\ArgumentOutOfRangeException;
use Bitrix\Main\Config\Option;
@ -99,7 +100,10 @@ class ConfigProvider
/** @var array $integrationDeliveriesMapping */
protected static $integrationDeliveriesMapping;
/** @var bool|null|string $loyaltyProgramStatus */
protected static $loyaltyProgramStatus;
/**
* @return bool|string|null
*/
@ -500,7 +504,7 @@ class ConfigProvider
*/
public static function getCurrencyOrDefault()
{
return self::getCurrency() ? self::getCurrency() : \Bitrix\Currency\CurrencyManager::getBaseCurrency();
return self::getCurrency() ?: CurrencyManager::getBaseCurrency();
}
/**
@ -660,4 +664,21 @@ class ConfigProvider
{
return empty($value) && $value !== 0;
}
/**
* @return bool|string|null
*/
public static function getLoyaltyProgramStatus()
{
return static::getOption(Constants::LOYALTY_PROGRAM_TOGGLE);
}
/**
* @param bool|string|null $loyaltyProgramStatus
* @throws \Bitrix\Main\ArgumentOutOfRangeException
*/
public static function setLoyaltyProgramStatus($loyaltyProgramStatus): void
{
static::setOption(Constants::LOYALTY_PROGRAM_TOGGLE, $loyaltyProgramStatus);
}
}

View file

@ -69,4 +69,5 @@ class Constants
public const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
public const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
public const CORPORATE_CONTRAGENT_TYPE = 'legal-entity';
public const LOYALTY_PROGRAM_TOGGLE = 'loyalty_program_toggle';
}

View file

@ -11,6 +11,9 @@
*/
namespace Intaro\RetailCrm\Component;
use CModule;
use RCrmActions;
/**
* Class DependencyLoader
*

View file

@ -85,7 +85,27 @@ class ServiceLocator
{
return static::$services[$name] ?? null;
}
/**
* Get or create service (instantiates service if it wasn't created earlier; $name must be FQN).
*
* @param string $name
*
* @return mixed
*/
public static function getOrCreate(string $name)
{
$service = static::$services[$name];
if (null === $service) {
static::$services[$name] = new $name();
return static::$services[$name];
}
return $service;
}
/**
* Sets service into ServiceContainer.
*

View file

@ -0,0 +1,34 @@
<?php
namespace Intaro\RetailCrm\Controller;
use Bitrix\Main\Engine\ActionFilter\Authentication;
use Bitrix\Main\Engine\Controller;
use Intaro\RetailCrm\Component\ConfigProvider;
class AdminPanel extends Controller
{
public function configureActions(): array
{
return [
'loyaltyProgramToggle' => [
'-prefilters' => [
Authentication::class,
],
],
];
}
/**
* @return string[]
* @throws \Bitrix\Main\ArgumentOutOfRangeException
*/
public function LoyaltyProgramToggleAction(): array
{
$status = ConfigProvider::getLoyaltyProgramStatus();
$newStatus = $status === 'N' || $status === null ? 'Y' : 'N';
ConfigProvider::setLoyaltyProgramStatus($newStatus);
return ['newStatus' => $newStatus];
}
}

File diff suppressed because it is too large Load diff