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

codestyle fix after codereview

This commit is contained in:
Sergey Chazov 2020-10-12 14:24:17 +03:00
parent 940c5314c0
commit f644be561f
11 changed files with 52 additions and 86 deletions

View file

@ -8197,7 +8197,7 @@ BX.namespace('BX.Sale.OrderAjaxComponent');
for (i = 0; i < this.paySystemPagination.currentPage.length; i++) {
//скрываем бонусный способ оплаты
if (this.paySystemPagination.currentPage[i].CODE === 'INTARO_BONUS' && this.loyaltyStatus === "Y") {
if (this.paySystemPagination.currentPage[i].CODE === 'INTARO_BONUS') {
continue;
}

View file

@ -1,20 +1,19 @@
$(document).ready(function() {
let intervalId;
function make_ajax_request() {
function makeAjaxRequest() {
setTimeout(function() {
$('#bonus-msg').html('Сколько бонусов потратить?');
BX.Sale.OrderAjaxComponent.sendRequest();
}, 1005);
}
$('#bonus-input')
.on('keydown', function() {
$('#bonus-input').on('keydown', function() {
$('#bonus-msg').html('Обработка информации');
clearInterval(intervalId);
})
$('#bonus-input').keyup(function(){
$('#bonus-input').keyup(function() {
let availableBonuses = Number.parseInt($('#available-bonus-input').val());
let inputBonuses = Number.parseInt($('#bonus-input').val());
if (inputBonuses > availableBonuses) {
@ -22,10 +21,8 @@ $(document).ready(function() {
}else{
$('#bonus-input-error').html(null);
}
});
$('#bonus-input').on('keydown',
_.debounce(make_ajax_request, 1000));
});
_.debounce(makeAjaxRequest, 1000));
});

View file

@ -56,7 +56,8 @@ class intaro_retailcrm extends CModule
['EVENT_NAME' => 'OnSaleComponentOrderResultPrepared', 'FROM_MODULE' => 'sale'],
];
public const V5 = 'v5';
public const V5 = 'v5';
public const INTARO_BONUS = 'INTARO_BONUS';
public $MODULE_ID = 'intaro.retailcrm';
public $OLD_MODULE_ID = 'intaro.intarocrm';
public $MODULE_VERSION;
@ -1616,6 +1617,7 @@ class intaro_retailcrm extends CModule
[
'NAME' => self::BONUS_PAY_SYSTEM_NAME,
'PSA_NAME' => self::BONUS_PAY_SYSTEM_NAME,
'CODE' => self::INTARO_BONUS,
'ACTION_FILE' => self::BONUS_PAY_SYSTEM_CODE,
'DESCRIPTION' => self::BONUS_PAY_SYSTEM_DESCRIPTION,
'RESULT_FILE' => '',

View file

@ -15,6 +15,8 @@ use Intaro\RetailCrm\Component\ApiClient\Traits\BaseClientTrait;
use Intaro\RetailCrm\Component\ApiClient\Traits\CustomersCorporateTrait;
use Intaro\RetailCrm\Component\ApiClient\Traits\CustomersTrait;
use Intaro\RetailCrm\Component\ApiClient\Traits\LoyaltyTrait;
use Intaro\RetailCrm\Component\Json\Deserializer;
use Intaro\RetailCrm\Model\Api\Response\Settings\CredentialsResponse;
use RetailCrm\Response\ApiResponse;
/**
@ -99,7 +101,6 @@ use RetailCrm\Response\ApiResponse;
* @method ApiResponse statisticUpdate()
* @method ApiResponse getSite()
* @method ApiResponse setSite($site)
* @method ApiResponse getCredentials()
*/
class ClientAdapter
{
@ -130,4 +131,14 @@ class ClientAdapter
throw new \RuntimeException(sprintf("Method '%s' doesn't exist.", $name));
}
/**
* @return \Intaro\RetailCrm\Model\Api\Response\Settings\CredentialsResponse
*/
public function getCredentials(): CredentialsResponse
{
$response = $this->client->getCredentials();
return Deserializer::deserializeArray($response->getResponseBody(), CredentialsResponse::class);
}
}

View file

@ -12,6 +12,8 @@
*/
namespace Intaro\RetailCrm\Component\Loyalty;
IncludeModuleLangFile(__FILE__);
use Bitrix\Main\ArgumentException;
use Bitrix\Main\Event;
use Bitrix\Main\HttpRequest;
@ -20,6 +22,7 @@ use Bitrix\Main\SystemException;
use Bitrix\Sale\PaySystem\Manager;
use Exception;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Repository\PaySystemActionRepository;
use Intaro\RetailCrm\Service\LoyaltyService;
@ -30,8 +33,6 @@ use Intaro\RetailCrm\Service\LoyaltyService;
*/
class EventsHandlers
{
const BONUS_ERROR_MSG = 'Нельзя потратить такое количество бонусов';
/**
* @param \Bitrix\Main\Event $event
*/
@ -113,19 +114,16 @@ class EventsHandlers
public function OnSaleComponentOrderResultPreparedHandler($order, $arUserResult, HttpRequest $request, $arParams, &$arResult): void
{
if (ConfigProvider::getLoyaltyProgramStatus() === 'Y') {
$isBonusError = false;
$bonusInput = (int)$request->get('bonus-input');
$availableBonuses = (int)$request->get('available-bonuses');
if ($bonusInput > $availableBonuses) {
$arResult['LOYALTY']['ERROR'] = self::BONUS_ERROR_MSG;
$isBonusError = true;
$arResult['LOYALTY']['ERROR'] = GetMessage('BONUS_ERROR_MSG');
return;
}
if (
$bonusInput > 0
if ($bonusInput > 0
&& $availableBonuses > 0
&& $isBonusError === false
&& $arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE'] >= $bonusInput
) {
$arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE'] -= $bonusInput;
@ -148,7 +146,8 @@ class EventsHandlers
if (isset($_POST['bonus-input'], $_POST['available-bonuses'])
&& $isNew
&& (int)$_POST['available-bonuses'] >= (int)$_POST['bonus-input']) {
&& (int) $_POST['available-bonuses'] >= (int) $_POST['bonus-input']
) {
$orderId = $order->getId();
$bonusCount = $_POST['bonus-input'];
$service = new LoyaltyService();

View file

@ -35,26 +35,25 @@ class AdminPanel extends Controller
/**
* @param $templates
* @param string $defreplace
* @param string $replaceDefaultTemplate
* @return array
*/
public function createSaleTemplateAction($templates, $defreplace = 'N'): array
public function createSaleTemplateAction($templates, $replaceDefaultTemplate = 'N'): array
{
$templateName = $defreplace === 'Y' ? '.default' : Constants::MODULE_ID;
$templateName = $replaceDefaultTemplate === 'Y' ? '.default' : Constants::MODULE_ID;
foreach ($templates as $template) {
$pathFrom = $_SERVER['DOCUMENT_ROOT']
. '/bitrix/modules/'
. Constants::MODULE_ID
. '/install/export/local/components/intaro/sale.order.ajax/templates/.default';
$pathTo = $_SERVER['DOCUMENT_ROOT']
. $template['location']
. $template['name']
. '/components/bitrix/sale.order.ajax/'
. $templateName;
if ($defreplace === 'Y' && file_exists($pathTo)) {
if ($replaceDefaultTemplate === 'Y' && file_exists($pathTo)) {
$backPath = $_SERVER['DOCUMENT_ROOT']
. $template['location']
. $template['name']

View file

@ -0,0 +1,2 @@
<?php
$MESS["BONUS_ERROR_MSG"] = 'Нельзя потратить такое количество бонусов';

View file

@ -50,6 +50,7 @@ class TemplateRepository extends AbstractRepository
];
}
}
closedir($handle);
}
}

View file

@ -16,6 +16,7 @@ use Bitrix\Catalog\GroupTable;
use Bitrix\Main\ArgumentException;
use Bitrix\Main\ObjectPropertyException;
use Bitrix\Main\SystemException;
use Intaro\RetailCrm\Component\ApiClient\ClientAdapter;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Factory\ClientFactory;
use Intaro\RetailCrm\Model\Api\Request\Loyalty\LoyaltyCalculateRequest;
@ -78,7 +79,8 @@ class LoyaltyService
$request->order->discountManualPercent = $discountPercent;
}
$client = new SettingsService();
/** @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter $client*/
$client = ClientFactory::createClientAdapter();
$credentials = $client->getCredentials();
$request->site = $credentials->sitesAvailable[0];
@ -100,11 +102,14 @@ class LoyaltyService
$product->quantity = $item['QUANTITY'];
try {
$price = GroupTable::query()->setSelect(['NAME'])->where(
[
['ID', '=', $item['PRICE_TYPE_ID']],
]
)->fetch();
$price = GroupTable::query()
->setSelect(['NAME'])
->where(
[
['ID', '=', $item['PRICE_TYPE_ID']],
]
)
->fetch();
$product->priceType->code = $price['NAME'];
} catch (ObjectPropertyException | ArgumentException | SystemException $e) {

View file

@ -1,48 +0,0 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Service
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Service;
use Intaro\RetailCrm\Component\Factory\ClientFactory;
use Intaro\RetailCrm\Component\Json\Deserializer;
use Intaro\RetailCrm\Model\Api\Response\Settings\CredentialsResponse;
/**
* Class SettingsService
*
* @package Intaro\RetailCrm\Service
*/
class SettingsService
{
/**
* @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter
*/
private $client;
/**
* LoyaltyService constructor.
*/
public function __construct()
{
$this->client = ClientFactory::createClientAdapter();
}
/**
* @return \Intaro\RetailCrm\Model\Api\Response\Settings\CredentialsResponse
*/
public function getCredentials(): CredentialsResponse
{
$response = $this->client->getCredentials();
return Deserializer::deserializeArray($response->getResponseBody(), CredentialsResponse::class);
}
}

View file

@ -786,12 +786,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
);
}
function replaceDefaultSaleTemplates(){
function replaceDefaultSaleTemplates() {
let templates = [];
let i = 0;
$('#lp-templates input:checkbox:checked')
.each(
$('#lp-templates input:checkbox:checked').each(
function(index, checkbox){
templates[i] = {
'name': $(checkbox).val(),
@ -800,9 +799,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
i++;
}
);
let requestAddress = 'intaro:retailcrm.api.adminpanel.createSaleTemplate';
BX.ajax.runAction(requestAddress,
BX.ajax.runAction('intaro:retailcrm.api.adminpanel.createSaleTemplate',
{
data: {
sessid: BX.bitrix_sessid(),
@ -995,7 +993,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
}
</style>
<div method="POST" action="<?php echo $uri; ?>" id="FORMACTION">
<form method="POST" action="<?php echo $uri; ?>" id="FORMACTION">
<?php
echo bitrix_sessid_post();
$tabControl->BeginNextTab();