0, 'NAME' => 'Счёт по выполненным работам для контрагента ' . $counteragent . ' №' . $id, 'BASE_PRICE' => $work_price, 'CURRENCY' => 'RUB', 'QUANTITY' => 1) ); $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, 2); $order->setPersonTypeId(1); $order->setBasket($basket); $order->setField('USER_DESCRIPTION', $recom); $order->setField('PRICE', $work_price); $order->doFinalAction(true); $propertyCollection = $order->getPropertyCollection(); foreach ($propertyCollection->getGroups() as $group){ foreach ($propertyCollection->getGroupProperties($group['ID']) as $property){ $p = $property->getProperty(); if($p["CODE"] == "PHONE"){ $property->setValue($phone); } if($p["CODE"] == "EMAIL"){ $property->setValue($email); } } } $nameProperty = $propertyCollection->getPayerName(); $nameProperty->setValue($counteragent); $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(3) ); $payment->setField("SUM", $work_price); $payment->setField("CURRENCY", "RUB"); $result = $order->save(); $orderId = $order->GetId(); if($result->isSuccess()){ echo $orderId; }else{ echo "Ошибка создания заказа"; } // $basket = Sale\Basket::loadItemsForFUser(2, "s1"); // $basket->save(); // // $order = Order::create("s1", 2); // $order->setPersonTypeId(1); // // /*Payment*/ // $paymentCollection = $order->getPaymentCollection(); // $extPayment = $paymentCollection->createItem(); // $extPayment->setFields(array( // 'PAY_SYSTEM_ID' => 3, // 'PAY_SYSTEM_NAME' => 'Оплата банковской картой', // 'SUM' => $work_price, // )); // // /**/ // $order->doFinalAction(true); // $propertyCollection = $order->getPropertyCollection(); // // foreach ($propertyCollection->getGroups() as $group){ // foreach ($propertyCollection->getGroupProperties($group['ID']) as $property){ // $p = $property->getProperty(); // if($p["CODE"] == "PHONE"){ // $property->setValue($phone); // } // if($p["CODE"] == "EMAIL"){ // $property->setValue($email); // } // } // } // $nameProp = $propertyCollection->getPayerName(); // $nameProp->setValue($counteragent); // $order->setField('USER_DESCRIPTION', $recom); // $order->setField('CURRENCY', 'RUB'); // // if(!empty($basket->getQuantityList())){ // $order->save(); // $orderId = $order->GetId(); // // if($orderId > 0){ // $arFields = array( // "PRODUCT_ID" => 0, // "PRICE" => $work_price, // "CURRENCY" => "RUB", // "QUANTITY" => 1, // "DELAY" => "N", // "CAN_BUY" => "Y", // "NAME" => "Счёт по выполненным работам для контрагента $counteragent №$id", // "ORDER_ID" => $orderId, // ); // CSaleBasket::Add($arFields); // echo "Заказ создан"; // }else{ // echo "Ошибка создания заказа"; // } // } } ?>