<?
if (CSaleBasket::Add($arFields)){
//...
} else {
global $APPLICATION;
echo $APPLICATION->LAST_ERROR;
}
while( $ob = $res->GetNextElement() ) {
$arFields[] = $ob->GetFields();//Тут ошибка. эта переменная используется в качестве параметра функции addProperty.
}
function addProperty(&$arFields)
{
// Выбираем опции
$arOrder = Array(
"SORT" => "ASC"
);
$arSelect = Array(
"ID",
"IBLOCK_ID",
"CODE",
"NAME",
"PROPERTY_OPTION_TYPE",
);
$arFilter = Array(
"IBLOCK_ID" => '19',
);
$res = CIBlockElement::GetList(
$arOrder,
$arFilter,
false,
false,
$arSelect
);
$counter = 0;
while ($ob = $res->GetNextElement()) {
$arItem = $ob->GetFields();
$arFields['PROPS'][$arItem['CODE']] = [
'CODE' => $arItem['CODE'],
'VALUE' => '1',
'SORT' => $counter += 100,//Про сортировку свойств не надо забывать. ID был лишним.
'NAME' => $arItem['NAME'],
];
}
}
Из новинок есть контроллеры AJAX. Но эта задумка ближе к REST, т.к. нацелена на обмен JSON.
\Bitrix\Main\Loader::includeModule("iblock");
\Bitrix\Main\Loader::includeModule("catalog");
\Bitrix\Main\Loader::includeModule("sale");
$ordersIds = array_column(\Bitrix\Sale\Internals\BasketTable::getList([
"select" => [
"ORDER_ID"
],
"filter" => [
"!ORDER_ID" => false,
"PRODUCT.IBLOCK.IBLOCK_ID" => $IBLOCK_ID//Тут надо задать ID вашего каталога
],
"group" => [
"ORDER_ID"
]
])->fetchAll(), "ORDER_ID");
https://domain.com/rest/1/XXXXXXXXXX/sale.order.get?id=1
<?php
\Bitrix\Main\Loader::includeModule("catalog");
$allProductPrices = \Bitrix\Catalog\PriceTable::getList([
"filter" => [
"PRODUCT_ID" => $productId,
]
])->fetchAll();
$bxEventManager = \Bitrix\Main\EventManager::getInstance();
$bxEventManager->addEventHandler(
'sale',
'OnSaleShipmentEntitySaved',
array(
"\\Gricuk\\Shipment",
"onSaleShipmentSavedHandler"
)
);
<?php
namespace Gricuk;
use Bitrix\Main\Event;
use Bitrix\Main\EventResult;
use Bitrix\Main\Result;
class Shipment
{
public static function onSaleShipmentSavedHandler(\Bitrix\Main\Event $event)
{
/** @var \Bitrix\Sale\Shipment $shipment */
$shipment = $event->getParameter("ENTITY");
$oldValues = $event->getParameter("VALUES");
$shipmentFields = $shipment->getFieldValues();
/**
* Ключ - статус ДОСТАВКИ
* Значение - статус ЗАКАЗА
*/
$statusMap = [
"DR" => "F",
"DB" => "RS"
];
if (isset($statusMap[$shipmentFields["STATUS_ID"]])) {
try {
$orderId = $shipment->getParentOrderId();
$order = \Bitrix\Sale\Order::load($orderId);
$order->setField("STATUS_ID", $statusMap[$shipmentFields["STATUS_ID"]]);
/** @var Result $saveResult */
$saveResult = $order->save();
if (!$saveResult->isSuccess()) {
\Bitrix\Main\Diag\Debug::dumpToFile($saveResult, '$saveResult', 'onSaleShipmentSavedHandler.log');
}
} catch (\Exception $e) {
\Bitrix\Main\Diag\Debug::dumpToFile($e, '$e', 'onSaleShipmentSavedHandler.log');
}
}
}
}
Array
(
[6197] => S1076
[6181] => S1024
[7345] => S1237
[6192] => S1067
[7455] => S1158
[8831] => 7386
[8830] => 7385
[8829] => 7384
[8828] => 7383
)