K
K
kentos2020-10-07 10:31:30
1C-Bitrix
kentos, 2020-10-07 10:31:30

Why is the snippet not working?

Hello, I found a snippet on the Internet, and I don’t understand why it might not work?

Main\EventManager::getInstance()->addEventHandler(
        'sale', 'OnSaleOrderSaved', 'PayLink'
);

function PayLink(Main\Event $event) {
    CModule::IncludeModule("sale");
    $order = $event->getParameter("ENTITY");
    $paymentIds = $order->getPaymentSystemId();
    $personTypeId = $order->getPersonTypeId();
    $propertyCollection = $order->getPropertyCollection();

    if ($paymentIds[0] == 10) {
        $orderPropertyId = ($personTypeId == 1) ? 55 : 56;
        $somePropValue = $propertyCollection->getItemByOrderPropertyId($orderPropertyId);
        if (!$somePropValue) {
            CSaleOrderPropsValue::Add(array(
                'ORDER_ID' => $order->getId(),
                'ORDER_PROPS_ID' => $orderPropertyId,
                'NAME' => "Ссылка на оплату",
                'VALUE' => "https://" . $_SERVER["SERVER_NAME"] . "/pay.php?ORDER_ID=" . $order->getId(),
                'CODE' => "PAY_LINK",
            ));
        } else {
            $propValue = $somePropValue->getValue();
            if (empty($propValue)) {
                // $somePropValue->setValue("https://pk-optex.ru/personal/order/payment/?ORDER_ID=".$order->getId());
                $somePropValue->setValue("https://" . $_SERVER["SERVER_NAME"] . "/pay.php?ORDER_ID=" . $order->getId());
                $somePropValue->save();
            }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail, 2020-10-07
@RuComMarket

Firstly, this is an event with static properties, i.e. not universal. you got these properties? they precisely have the specified ID?
secondly, where are you trying to check this code? did you add this event handler at least in init.php?
thirdly, learn to debug, Bitrix will show you exactly what is not working.
but in general, judging by the question, I recommend starting studying Bitrix with easier things in order to understand the structure and logic, then you will not call the handlers snippets, and you can write such functionality yourself for your project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question