B
B
boris tyrepharm2020-01-28 01:14:36
1C-Bitrix
boris tyrepharm, 2020-01-28 01:14:36

Why is the order payment flag not set when using the D7 API?

I ran into a problem when creating payments for an order through D7.
Sometimes, when creating payments (there may be several payments), which fully cover the order amount, the order payment flag is not automatically set.

The code snippet is given below:

<?
$order = Sale\Order::loadByAccountNumber(1000);
$paymentCollection = $order->getPaymentCollection();

$paySystemService = PaySystem\Manager::getObjectById(1);

// цикл для каждой из импортированных оплат
foreach ($importOrderPayments as $importOrderPayment)
{
    $paymentExists = find_payment($importOrderPayment['Document']) // определяется существование оплаты: возвращается id оплаты, либо false если оплаты нет
    if ($paymentExists === false) // оплаты не существует — создаём
    {
        $payment = $paymentCollection->createItem();
        $payment->setFields([
            'PAY_SYSTEM_ID' => $paySystemService->getField("PAY_SYSTEM_ID"),
            'PAY_SYSTEM_NAME' => $paySystemService->getField("NAME"),
            'DATE_PAID' => \Bitrix\Main\Type\DateTime::createFromTimestamp($importOrderPayment['Date']),
            'SUM' => $importOrderPayment['FullPrice'],
            'PAY_VOUCHER_NUM' => $importOrderPayment['Document'],
            'PAY_VOUCHER_DATE' => \Bitrix\Main\Type\DateTime::createFromTimestamp($importOrderPayment['Date']),
            'COMMENTS' => $importOrderPayment['Comments'],
            'PAID' => 'Y',
            'COMPANY_ID' => 1,
            'UPDATED_1C' => 'Y'
        ]);
    }
    else // оплата существует - обновим
    {
        $payment = $paymentCollection->getItemById($paymentExists);
        $payment->setFieldNoDemand('SUM', $importOrderPayment['FullPrice']);
        $payment->setFields([
            'PAY_SYSTEM_ID' => $paySystemService->getField("PAY_SYSTEM_ID"),
            'PAY_SYSTEM_NAME' => $paySystemService->getField("NAME"),
            'DATE_PAID' => \Bitrix\Main\Type\DateTime::createFromTimestamp($importOrderPayment['Date']),
            'PAY_VOUCHER_NUM' => $importOrderPayment['Document'],
            'PAY_VOUCHER_DATE' => \Bitrix\Main\Type\DateTime::createFromTimestamp($importOrderPayment['Date']),
            'COMMENTS' => $importOrderPayment['Comments'],
            'PAID' => 'Y',
            'COMPANY_ID' => 1,
            'UPDATED_1C' => 'Y'
        ]);
    }
}

$order->save();
?>


I also read the Bitrix forum with a similar problem, but did not find an answer:
https://dev.1c-bitrix.ru/support/forum/forum6/topi...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail, 2020-01-29
@RuComMarket

try this
$payment->setPaid("Y");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question