Working with a Bitrix order for D7
Rus
Eng
Работа с заказом Битрикс на D7

All English-language materials have been translated fully automatically using the Google service

Bitrix. Working with an order for D7

Get data about the order by its id using \Bitrix\Sale\Internals\OrderTable

if(class_exists('\Bitrix\Sale\Internals\OrderTable'))
	$arOrder = \Bitrix\Sale\Internals\OrderTable::getList(array('order' => array('ID' => 'ASC'), 'filter' => array('ID' => $ORDER_ID)))->Fetch();
else
	$arOrder = CSaleOrder::GetList(array(), array('ID' => $ORDER_ID))->Fetch();

Getting the order object

//we receive an order by id
$order = \Bitrix\Sale\Order::load($orderId);

//we receive an order by order number
$order = \Bitrix\Sale\Order::loadByAccountNumber($orderNumber);

We get all the order parameters

$order->getFields();

Retrieving the most commonly used parameters:

$order->getField("ID"); // ID заказа
$order->getField("LID"); // ID сайта
$order->getField("ACCOUNT_NUMBER"); // Номер заказа
$order->getField("TRACKING_NUMBER");
$order->getField("PAY_SYSTEM_ID"); //* ID платежной системы
$order->getField("DELIVERY_ID"); //* ID службы доставки
$order->getField("DATE_INSERT"); // object(DateTime) Время добавления
$order->getField("DATE_UPDATE"); // object(DateTime) Время обновления
$order->getField("PERSON_TYPE_ID"); // ID типа плательщика (физ/юр лицо)
$order->getField("USER_ID"); // ID пользователя
$order->getField("PAYED"); //* Статус оплаты (Y/N)
$order->getField("DATE_PAYED"); //* object(DateTime) Дата оплаты
$order->getField("EMP_PAYED_ID");
$order->getField("DEDUCTED"); //* Отгрузка заказа
$order->getField("DATE_DEDUCTED"); //* object(DateTime) Дата отгрузки
$order->getField("EMP_DEDUCTED_ID"); //*
$order->getField("REASON_UNDO_DEDUCTED"); //* Причина отмены отгрузки
$order->getField("STATUS_ID"); // Статус заказа (F/N/H  т.п., посмотреть можно тут /bitrix/admin/sale_status.php?lang=ru)
$order->getField("DATE_STATUS"); // object(DateTime) Дата изменения статуса
$order->getField("PRICE_DELIVERY"); //* Стоимость доставки
$order->getField("ALLOW_DELIVERY"); //* Доставка разрешена
$order->getField("RESERVED");
$order->getField("PRICE"); // Сумма заказа
$order->getField("CURRENCY"); // Код валюты
$order->getField("DISCOUNT_VALUE"); // Скидка
$order->getField("TAX_VALUE"); // Налог
$order->getField("SUM_PAID"); //  Оплаченная сумма
$order->getField("USER_DESCRIPTION"); // Комментарий покупателя к заказу
$order->getField("PAY_VOUCHER_NUM"); // Номер документа прихода
$order->getField("PAY_VOUCHER_DATE"); // object(DateTime) Дата прихода
$order->getField("ADDITIONAL_INFO"); // Дополнительная информация
$order->getField("COMMENTS"); // Комментарий администратора
$order->getField("COMPANY_ID"); // Офис
$order->getField("RESPONSIBLE_ID"); // Ответственный
$order->getField("LOCKED_BY"); // ID пользователя, заблокировавший заказ
$order->getField("DATE_LOCK"); // object(DateTime) Дата блокировки
$order->getField("UPDATED_1C");
$order->getField("XML_ID");
$order->getField("ID_1C");
$order->getField("VERSION_1C");
$order->getField("VERSION");
$order->getField("EXTERNAL_ORDER");
$order->getField("CANCELED"); // Омена заказа (N/Y)
$order->getField("EMP_CANCELED_ID");
$order->getField("DATE_CANCELED"); // object(DateTime) Дата отмены
$order->getField("REASON_CANCELED"); // Причина отмены

Updating and saving the order

$order->setField('PAYED', 'Y');
$order->save();

Tracking order status changes

Event before changing the status OnSaleBeforeStatusOrderChange , after changing OnSaleStatusOrderChange

\Bitrix\Main\EventManager::getInstance()->addEventHandler('sale', 'OnSaleStatusOrderChange', ['Handler', 'OnSaleStatusOrderChange']);

class Handler {
  function OnSaleStatusOrderChange($event)
  {
    $parameters = $event->getParameters();
    if ($parameters['VALUE'] === 'F') { //Checking the status by its code
		//Можно по имени с помощью $event->getParameter('NAME')
		$order = $parameters['ENTITY'];

    }

    return new \Bitrix\Main\EventResult(
      \Bitrix\Main\EventResult::SUCCESS
    );
  }
}

Bitrix, we receive a link to pay for the order

$ORDER = \Bitrix\Sale\Order::load($arResult['ORDER']['ID']);
if (!$ORDER->getPaymentCollection()->isEmpty() && $order['PAYED'] != 'Y') {

	/** @var Payment $payment */
	$payment = $ORDER->getPaymentCollection()->current();

	$service = \Bitrix\Sale\PaySystem\Manager::getObjectById($payment->getPaymentSystemId());
	if ($service) {
		$context = \Bitrix\Main\Application::getInstance()->getContext();

		$result = $service->initiatePay(
			$payment,
			$context->getRequest(),
			\Bitrix\Sale\PaySystem\BaseServiceHandler::STRING
		);

		if ($result->isSuccess()) {
			echo $result->getTemplate();
		}
	}
}

Viewing an order by an unauthorized user in Bitrix with sending a link to the order to the user

In the / personal / order / folder, create a detail.php file and place the bitrix: sale.personal.order.detail component in it

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("");
$APPLICATION->IncludeComponent(
	"bitrix:sale.personal.order.detail",
	"",
	Array(
		"ACTIVE_DATE_FORMAT" => "d.m.Y",
		"ALLOW_INNER" => "N",
		"CACHE_GROUPS" => "Y",
		"CACHE_TIME" => "3600",
		"CACHE_TYPE" => "A",
		"CUSTOM_SELECT_PROPS" => array(""),
		"DISALLOW_CANCEL" => "N",
		"ID" => $ID,
		"ONLY_INNER_FULL" => "N",
		"PATH_TO_CANCEL" => "",
		"PATH_TO_COPY" => "",
		"PATH_TO_LIST" => "",
		"PATH_TO_PAYMENT" => "payment.php",
		"PICTURE_HEIGHT" => "110",
		"PICTURE_RESAMPLE_TYPE" => "1",
		"PICTURE_WIDTH" => "110",
		"PROP_1" => array(""),
		"PROP_2" => array(""),
		"REFRESH_PRICES" => "N",
		"RESTRICT_CHANGE_PAYSYSTEM" => array("0"),
		"SET_TITLE" => "Y"
	)
);
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");

Follow the path /bitrix/admin/settings.php?mid=sale&lang=ru&back_url_settings=&tabControl_active_tab=edit1 ( Settings -> Product settings -> Modules settings ) < / p>

We are looking for a group of properties Settings for displaying an order card in the public part and enable the option Allow viewing an order by key without authorization

Use /personal/order/detail.php?ID=#order_id# as the path template. Don't forget to select the required statuses

In the template of the letter sent when setting a specific status, insert a link to the order #ORDER_PUBLIC_URL#

Everyone. Now, when setting a new status in an order, the user will be sent an email with a link to view the order incognito

1C Bitrix and Yandex Checkout, how to generate / receive a link to pay for an order?

Answer from stackOverflow

use Bitrix\Main,
   Bitrix\Main\Loader,
   Bitrix\Sale,
   Bitrix\Sale\Order,
   Bitrix\Sale\PaySystem,
   Bitrix\Sale\Payment;
   Loader::includeModule("sale");
   $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
   $orderClassName = $registry->getOrderClassName();
   $order = $orderClassName::loadByAccountNumber(10);// id заказа
   if ($order->isAllowPay()) {
     $paymentCollection = $order->getPaymentCollection();
     foreach ($paymentCollection as $payment) {
        $arResult["PAYMENT"][$payment->getId()] = $payment->getFieldValues();
        if (intval($payment->getPaymentSystemId()) > 0 && !$payment->isPaid()) {
            $paySystemService = PaySystem\Manager::getObjectById($payment->getPaymentSystemId());
            if (!empty($paySystemService)) {
                $arPaySysAction = $paySystemService->getFieldsValues();
                if ($paySystemService->getField('NEW_WINDOW') === 'N' || $paySystemService->getField('ID') == PaySystem\Manager::getInnerPaySystemId()){
                    $initResult = $paySystemService->initiatePay($payment, null, PaySystem\BaseServiceHandler::STRING);
                    if ($initResult->isSuccess())
                        $arPaySysAction['BUFFERED_OUTPUT'] = $initResult->getTemplate(); // получаем форму оплаты из обработчика
                    else
                        $arPaySysAction["ERROR"] = $initResult->getErrorMessages();
                }
            }
        }
    }
}

Shift order IDs

To do this, go to SQL query and use the command:

ALTER TABLE b_sale_order AUTO_INCREMENT = 100000

where 100000 Id from which numbering should begin

 

Worth reading:

Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Are you developing a new service, making improvements to the existing one and want to be better than your competitors? You have come to the right place. I offer you a comprehensive studio-level website development. From me you can order design, layout, programming, development of non-traditional functionality, implementation of communication between CMS, CRM and Data Analitics, as well as everything else related to sites, except for promotion.

Contact, I will always advise on all questions and help you find the most effective solution for your business. I am engaged in the creation of sites in Novosibirsk and in other regions of Russia, I also work with the CIS countries. You will be satisfied with our cooperation

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site

Contact with me
Send message
By submitting the form, you automatically confirm that you have read and accept Privacy policy of site
Sending successful!
Thank you for contacting :) I will contact you as soon as possible
Sending failed
An error occurred while sending the request. Please wait and try again after a while or call my phone number