$dbBasketItems = CSaleBasket::GetList(
array(
"NAME" => "ASC",
"ID" => "ASC"
),
array(
"FUSER_ID" => CSaleBasket::GetBasketUserID(),
"LID" => SITE_ID,
"ORDER_ID" => "NULL"
),
false,
false,
array('PRODUCT_ID','NAME','PRICE','CURRENCY','QUANTITY','WEIGHT','DIMENSIONS')
);
$products = array();
while ($arItems = $dbBasketItems->Fetch())
{
$ar_res = CCatalogProduct::GetByID($arItems['PRODUCT_ID']);
$arItems["WEIGHT"] = $ar_res['WEIGHT'];
$products[] = $arItems;
}
$basket = Bitrix\Sale\Basket::create(SITE_ID);
foreach ($products as $product)
{
$item = $basket->createItem("catalog", $product["PRODUCT_ID"]);
unset($product["PRODUCT_ID"]);
$item->setFields($product);
}
$order = Bitrix\Sale\Order::create(SITE_ID, $userId);
$order->setPersonTypeId(8);
$order->setBasket($basket);
$propertyCollection = $order->getPropertyCollection();
$nameProperty = getPropertyByCode($propertyCollection, 'NAME');
$nameProperty->setValue($orderData->name);
....
$shipmentCollection = $order->getShipmentCollection();
$shipment = $shipmentCollection->createItem(
Bitrix\Sale\Delivery\Services\Manager::getObjectById(1)
);
$shipmentItemCollection = $shipment->getShipmentItemCollection();
foreach ($basket as $basketItem)
{
$item = $shipmentItemCollection->createItem($basketItem);
$item->setQuantity($basketItem->getQuantity());
}
$paymentCollection = $order->getPaymentCollection();
$payment = $paymentCollection->createItem(
Bitrix\Sale\PaySystem\Manager::getObjectById(1)
);
$payment->setField("SUM", $order->getPrice());
$payment->setField("CURRENCY", $order->getCurrency());
$order->save();
CSaleBasket::DeleteAll(CSaleBasket::GetBasketUserID());
$result['num'] = $order->GetId();
echo json_encode($result);