1
0
Fork 0
mirror of synced 2025-04-18 16:41:02 +00:00

added nullable for 1 arg Utils::handleApiErrors etc

This commit is contained in:
Sergey Chazov 2021-05-27 15:01:16 +03:00 committed by Neur0toxine
parent 91ca788c79
commit 50463bb3eb
6 changed files with 46 additions and 36 deletions

View file

@ -2,7 +2,10 @@
use Bitrix\Main\ArgumentException;
use Bitrix\Main\ArgumentNullException;
use Bitrix\Main\ArgumentOutOfRangeException;
use Bitrix\Main\Context;
use Bitrix\Main\NotSupportedException;
use Bitrix\Main\SystemException;
use Bitrix\Sale\Basket;
use Bitrix\Sale\Delivery\Services\EmptyDeliveryService;
use Bitrix\Sale\Delivery\Services\Manager;
@ -11,12 +14,11 @@ use Bitrix\Sale\Internals\PaymentTable;
use Bitrix\Sale\Location\Search\Finder;
use Bitrix\Sale\Order;
use Bitrix\Sale\OrderUserProperties;
use Bitrix\Sale\Payment;
use Intaro\RetailCrm\Service\ManagerService;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Component\Handlers\EventsHandlers;
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Service\LoyaltyService;
IncludeModuleLangFile(__FILE__);
class RetailCrmHistory
@ -1571,25 +1573,29 @@ class RetailCrmHistory
/**
* Update shipment in order
*
* @param order object
* @param options delivery types
* @param order from crm
* @param \Bitrix\Sale\Order $bitrixOrder
* @param array $optionsDelivTypes
* @param array $crmOrder
*
* @return void
* @return bool|null
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\ArgumentNullException
* @throws \Bitrix\Main\ObjectNotFoundException
* @throws \Bitrix\Main\SystemException
*/
public static function deliveryUpdate(Bitrix\Sale\Order $order, $optionsDelivTypes, $orderCrm)
public static function deliveryUpdate(Bitrix\Sale\Order $bitrixOrder, $optionsDelivTypes, $crmOrder)
{
if (!$order instanceof Bitrix\Sale\Order) {
if (!$bitrixOrder instanceof Bitrix\Sale\Order) {
return false;
}
if ($order->getId()) {
if ($bitrixOrder->getId()) {
$update = true;
} else {
$update = false;
}
$crmCode = $orderCrm['delivery']['code'] ?? false;
$crmCode = $crmOrder['delivery']['code'] ?? false;
$noDeliveryId = EmptyDeliveryService::getEmptyDeliveryServiceId();
if ($crmCode === false || !isset($optionsDelivTypes[$crmCode])) {
@ -1597,9 +1603,9 @@ class RetailCrmHistory
} else {
$deliveryId = $optionsDelivTypes[$crmCode];
if (isset($orderCrm['delivery']['service']['code'])) {
if (isset($crmOrder['delivery']['service']['code'])) {
$deliveryCode = Manager::getCodeById($deliveryId);
$serviceCode = $orderCrm['delivery']['service']['code'];
$serviceCode = $crmOrder['delivery']['service']['code'];
$service = Manager::getService($deliveryId);
if (is_object($service)) {
@ -1613,7 +1619,7 @@ class RetailCrmHistory
if ($deliveryCode) {
try {
$deliveryService = Manager::getObjectByCode($deliveryCode . ':' . $serviceCode);
} catch (Bitrix\Main\SystemException $systemException) {
} catch (SystemException $systemException) {
RCrmActions::eventLog('RetailCrmHistory::deliveryEdit', '\Bitrix\Sale\Delivery\Services\Manager::getObjectByCode', $systemException->getMessage());
}
@ -1625,31 +1631,33 @@ class RetailCrmHistory
}
$delivery = Manager::getObjectById($deliveryId);
$shipmentColl = $order->getShipmentCollection();
$shipmentColl = $bitrixOrder->getShipmentCollection();
if ($delivery) {
if (!$update) {
$shipment = $shipmentColl->createItem($delivery);
$shipment->setFields(array(
'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
'CURRENCY' => $order->getCurrency(),
'DELIVERY_NAME' => $delivery->getName(),
'BASE_PRICE_DELIVERY' => $crmOrder['delivery']['cost'],
'CURRENCY' => $bitrixOrder->getCurrency(),
'DELIVERY_NAME' => $delivery->getName(),
'CUSTOM_PRICE_DELIVERY' => 'Y'
));
} else {
foreach ($shipmentColl as $shipment) {
if (!$shipment->isSystem()) {
$shipment->setFields(array(
'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
'CURRENCY' => $order->getCurrency(),
'DELIVERY_ID' => $deliveryId,
'DELIVERY_NAME' => $delivery->getName(),
'BASE_PRICE_DELIVERY' => $crmOrder['delivery']['cost'],
'CURRENCY' => $bitrixOrder->getCurrency(),
'DELIVERY_ID' => $deliveryId,
'DELIVERY_NAME' => $delivery->getName(),
'CUSTOM_PRICE_DELIVERY' => 'Y'
));
}
}
}
}
return true;
}
/**
@ -1708,11 +1716,11 @@ class RetailCrmHistory
if (!$shipment->isSystem()) {
try {
$shipment->tryUnreserve();
} catch (Main\ArgumentOutOfRangeException $ArgumentOutOfRangeException) {
} catch (ArgumentOutOfRangeException $ArgumentOutOfRangeException) {
RCrmActions::eventLog('RetailCrmHistory::unreserveShipment', '\Bitrix\Sale\Shipment::tryUnreserve()', $ArgumentOutOfRangeException->getMessage());
return false;
} catch (Main\NotSupportedException $NotSupportedException) {
} catch (NotSupportedException $NotSupportedException) {
RCrmActions::eventLog('RetailCrmHistory::unreserveShipment', '\Bitrix\Sale\Shipment::tryUnreserve()', $NotSupportedException->getMessage());
return false;
@ -1753,7 +1761,7 @@ class RetailCrmHistory
$nowPaymentId = RCrmActions::getFromPaymentExternalId($paymentCrm['externalId']);
$nowPayment = $paymentsList[$nowPaymentId];
//update data
if ($nowPayment instanceof \Bitrix\Sale\Payment) {
if ($nowPayment instanceof Payment) {
$nowPayment->setField('SUM', $paymentCrm['amount']);
if ($optionsPayTypes[$paymentCrm['type']] != $nowPayment->getField('PAY_SYSTEM_ID')) {
$nowPayment->setField('PAY_SYSTEM_ID', $optionsPayTypes[$paymentCrm['type']]);

View file

@ -30,7 +30,7 @@ if (checkLoadIntaro()) {
if ('Y' === $arResult['LOYALTY_STATUS'] && $USER->IsAuthorized()) {
/** @var CustomerService $customerService */
$customerService = ServiceLocator::get(CustomerService::class);
$customer = $customerService->createModel($USER->GetID());
$customer = $customerService->createModel($USER->GetID());
$customerService->createCustomer($customer);

View file

@ -30,7 +30,7 @@ if (checkLoadIntaro()) {
if ('Y' === $arResult['LOYALTY_STATUS'] && $USER->IsAuthorized()) {
/** @var CustomerService $customerService */
$customerService = ServiceLocator::get(CustomerService::class);
$customer = $customerService->createModel($USER->GetID());
$customer = $customerService->createModel($USER->GetID());
$customerService->createCustomer($customer);
@ -46,19 +46,17 @@ if (checkLoadIntaro()) {
['CODE', '=', 'AGREEMENT_PERSONAL_DATA_CODE'],
]
);
$agreementLoyaltyProgram = AgreementRepository::getFirstByWhere(
['AGREEMENT_TEXT'],
[
['CODE', '=', 'AGREEMENT_LOYALTY_PROGRAM_CODE'],
]
);
$arResult['AGREEMENT_PERSONAL_DATA'] = $agreementPersonalData['AGREEMENT_TEXT'];
$arResult['AGREEMENT_LOYALTY_PROGRAM'] = $agreementLoyaltyProgram['AGREEMENT_TEXT'];
} catch (ObjectPropertyException | ArgumentException | SystemException $exception) {
Logger::getInstance()->write($exception->getMessage(), Constants::TEMPLATES_ERROR);
}
$arResult['AGREEMENT_PERSONAL_DATA'] = $agreementPersonalData['AGREEMENT_TEXT'];
$arResult['AGREEMENT_LOYALTY_PROGRAM'] = $agreementLoyaltyProgram['AGREEMENT_TEXT'];
} else {
AddMessage2Log(GetMessage('INTARO_NOT_INSTALLED'));
}

View file

@ -29,7 +29,7 @@ function checkLoadIntaro(): bool
}
if (checkLoadIntaro()) {
$arResult['LOYALTY_STATUS'] = ConfigProvider::getLoyaltyProgramStatus();
$arResult['LOYALTY_STATUS'] = ConfigProvider::getLoyaltyProgramStatus();
$arResult['PERSONAL_LOYALTY_STATUS'] = LoyaltyAccountService::getLoyaltyPersonalStatus();
if ($arResult['LOYALTY_STATUS'] === 'Y' && $arResult['PERSONAL_LOYALTY_STATUS'] === true) {

View file

@ -4,7 +4,7 @@ $(document).ready(function() {
let basketItemsHidden = window.__BASKET_ITEMS__;
let inputBonuses = $('#bonus-input').val();
if (/(?<![-\d])(?<!\d[.,])\d*$/.test(inputBonuses) === false) {
if (/^[1-9]+$/.test(inputBonuses) === false) {
$('#bonus-input-error').html(window.__MESS__.VALIDATE_BONUS_ERROR);
return;
}

View file

@ -174,12 +174,16 @@ class Utils
}
/**
* @param \Intaro\RetailCrm\Model\Api\Response\AbstractApiResponseModel $response
* @param string $errorMsg
* @param \Intaro\RetailCrm\Model\Api\Response\AbstractApiResponseModel|null $response
* @param string $errorMsg
*/
public static function handleApiErrors(AbstractApiResponseModel $response, $errorMsg = 'ERROR')
public static function handleApiErrors(?AbstractApiResponseModel $response, string $errorMsg = 'ERROR')
{
if (isset($response->errorMsg) && !empty($response->errorMsg)) {
if (
$response instanceof AbstractApiResponseModel
&& isset($response->errorMsg)
&& !empty($response->errorMsg)
) {
$errorDetails = '';
if (isset($response->errors) && is_array($response->errors)) {