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

add correction for first payment

This commit is contained in:
Sergey Chazov 2020-10-20 15:13:36 +03:00 committed by Neur0toxine
parent b081e2d15a
commit f2abca9dc6

View file

@ -23,7 +23,6 @@ use Bitrix\Sale\Order;
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;
@ -107,7 +106,7 @@ class EventsHandlers
}
/**
* Обработчик события, вызываемого при обновлении заказа
* Обработчик события, вызываемого при обновлении еще не сохраненного заказа
*
* @param \Bitrix\Sale\Order $order
* @param array $arUserResult
@ -157,7 +156,7 @@ class EventsHandlers
$service = new LoyaltyService();
$response = $service->sendBonusPayment($orderId, $bonusCount);
//TODO - заглушка до появления api на стороне CRM. После появления реального апи - убрать
//TODO - заглушка до появления api на стороне CRM. После появления реального апи - убрать следующую строку
$response->success = true;
if ($response->success) {
@ -166,6 +165,16 @@ class EventsHandlers
$paymentCollection = $order->getPaymentCollection();
if ($bonusPaySystem !== null) {
if (count($paymentCollection) === 1) {
/** @var \Bitrix\Sale\Payment $payment */
foreach ($paymentCollection as $payment){
$oldSum = $payment->getField('SUM');
$payment->setField('SUM', $oldSum - $bonusCount);
break;
}
}
$service = Manager::getObjectById($bonusPaySystem->getId());
$newPayment = $paymentCollection->createItem($service);