Skip to content

Commit

Permalink
ref #94529 Исправление ошибки дублирования скидок (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocmonavtik authored Apr 1, 2024
1 parent 85749c8 commit 830fe34
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2024-03-28 v.6.5.11
- Исправлена ошибка дублирования скидок

## 2024-03-18 v.6.5.10
- Добавлена валидация прав API ключа

Expand Down
34 changes: 22 additions & 12 deletions intaro.retailcrm/classes/general/RestNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class RestNormalizer
{
public $clear = true;
private $validation = array();
private $originalValidation = array();
private $validation = [];
private $originalValidation = [];
private $server;

/**
Expand Down Expand Up @@ -55,9 +55,11 @@ final public function normalize($data, $key = false, $file = '/bitrix/modules/in
$file = $server . $file;
if (is_null($file) || is_file($file) === false
|| json_decode(file_get_contents($file)) === null
|| $this->parseConfig($file) === false) {
RCrmActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect file normalize.');
return false;
|| $this->parseConfig($file) === false
) {
RCrmActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect file normalize.');

return false;
}

if (is_string($data)) {
Expand All @@ -72,6 +74,7 @@ final public function normalize($data, $key = false, $file = '/bitrix/modules/in

if (!is_array($data) || count($data) < 1) {
RCrmActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect data array.');

return false;
}

Expand All @@ -88,7 +91,7 @@ final public function normalize($data, $key = false, $file = '/bitrix/modules/in
*/
final private function formatting($data, $skip = false)
{
$formatted = array();
$formatted = [];

foreach ($data as $code => $value) {
if (isset($this->validation[ $code ]) && $this->validation[ $code ]['type'] == 'skip') {
Expand All @@ -99,13 +102,15 @@ final private function formatting($data, $skip = false)
$formatted[ $code ] = $this->formatting($value, true);
}

if (empty($formatted[$code] && $formatted[$code] !== 0)) {
//Удаление пустых переменных, кроме значений равных 0
if (empty($formatted[$code]) && $formatted[$code] !== 0 && $formatted[$code] !== 0.0) {
if ($this->clear === true) {
unset($formatted[ $code ]);
}

if (isset($this->validation[ $code ]['required']) && $this->validation[ $code ]['required'] === true) {
$formatted = array();
$formatted = [];

break;
}
}
Expand Down Expand Up @@ -174,7 +179,8 @@ final private function setString($data, $validation)
$data = trim((string) $data);

if (isset($validation['default']) && is_string($validation['default']) && trim($validation['default']) != ''
&& ($data == '' || is_string($data) === false)) {
&& ($data == '' || is_string($data) === false)
) {
$data = trim($validation['default']);
} elseif ($data == '' || is_string($data) === false) {
return null;
Expand Down Expand Up @@ -302,7 +308,8 @@ final private function setEnum($data, $validation)
} elseif (isset($validation['default']) && in_array($validation['default'], $validation['values']) === false) {
return null;
} elseif (in_array($data, $validation['values']) === false
&& isset($validation['default']) && in_array($validation['default'], $validation['values'])) {
&& isset($validation['default']) && in_array($validation['default'], $validation['values'])
) {
$data = $validation['default'];
} elseif (in_array($data, $validation['values']) === false) {
return null;
Expand All @@ -327,10 +334,13 @@ final private function multiConvert($data)
if (is_array($value)) {
$value = array_diff($value, array('', NULL));
}

$data[$APPLICATION->ConvertCharset($code, SITE_CHARSET, 'utf-8')] = is_array($value)
? $this->multiConvert($value)
: $APPLICATION->ConvertCharset($value, SITE_CHARSET, 'utf-8');
? $this->multiConvert($value)
: $APPLICATION->ConvertCharset($value, SITE_CHARSET, 'utf-8')
;
}

return $data;
} else {
return $APPLICATION->ConvertCharset($data, SITE_CHARSET, 'utf-8');
Expand Down
2 changes: 2 additions & 0 deletions intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ public static function orderSend(
} elseif ($product['BASE_PRICE'] >= $product['PRICE']) {
$item['discountManualAmount'] = self::getDiscountManualAmount($product);
$item['initialPrice'] = (double) $product['BASE_PRICE'];
$order['discountManualAmount'] = 0;
$order['discountManualPercent'] = 0;
} else {
$item['discountManualAmount'] = 0;
$item['initialPrice'] = $product['PRICE'];
Expand Down
2 changes: 1 addition & 1 deletion intaro.retailcrm/description.ru
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Добавлена валидация прав API ключа
- Исправлена ошибка дублирования скидок
4 changes: 2 additions & 2 deletions intaro.retailcrm/install/version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$arModuleVersion = [
'VERSION' => '6.5.10',
'VERSION_DATE' => '2024-03-18 14:30:00'
'VERSION' => '6.5.11',
'VERSION_DATE' => '2024-03-28 12:00:00'
];

0 comments on commit 830fe34

Please sign in to comment.