Москва, ул. Борисовские
Пруды, 18 корп.1

(495)518-7678

          8 800 222 1977
global $USER; $uploaddir = '/home/bitrix/www/upload/'; $uploadfile = $uploaddir . basename($_FILES['file']['name']); echo '
';
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
    //echo "Файл корректен и был успешно загружен.\n";
} else {
   // echo "Возможная атака с помощью файловой загрузки!\n";
}

$file = CFile::MakeFileArray("/home/bitrix/www/upload/".$_FILES['file']["name"]);
use Bitrix\Main,    
    Bitrix\Main\Localization\Loc as Loc,    
    Bitrix\Main\Loader,    
    Bitrix\Main\Config\Option,    
    Bitrix\Sale\Delivery,    
    Bitrix\Sale\PaySystem,    
    Bitrix\Sale,    
    Bitrix\Sale\Order,    
    Bitrix\Sale\DiscountCouponsManager,    
    Bitrix\Main\Context;
    
if (!Loader::IncludeModule('sale'))
    die();

function getPropertyByCode($propertyCollection, $code)  {
    foreach ($propertyCollection as $property)
    {
        if($property->getField('CODE') == $code)
            return $property;
    }
}

$siteId = \Bitrix\Main\Context::getCurrent()->getSite();

$fio = $_POST['name']." ".$_POST['surname']." ".$_POST['fathername'];
$phone = 'Моб: '.$_POST['mob']." Дом/Офис: ".$_POST['dom'];
$email = $_POST['email'];

$currencyCode = Option::get('sale', 'default_currency', 'RUB');

DiscountCouponsManager::init();

$order = Order::create($siteId, \CSaleUser::GetAnonymousUserID());

$order->setPersonTypeId(1);
$basket = Sale\Basket::loadItemsForFUser(\CSaleBasket::GetBasketUserID(), $siteId)->getOrderableItems();

/* Действия над товарами
$basketItems = $basket->getBasketItems();
foreach ($basketItems as $basketItem) {
    
}
*/

$order->setBasket($basket);

/*Shipment*/
$shipmentCollection = $order->getShipmentCollection();
$shipment = $shipmentCollection->createItem();
$shipmentItemCollection = $shipment->getShipmentItemCollection();
$shipment->setField('CURRENCY', $order->getCurrency());
foreach ($order->getBasket() as $item)
{
    $shipmentItem = $shipmentItemCollection->createItem($item);
    $shipmentItem->setQuantity($item->getQuantity());
}
$arDeliveryServiceAll = Delivery\Services\Manager::getRestrictedObjectsList($shipment);
$shipmentCollection = $shipment->getCollection();

if (!empty($arDeliveryServiceAll)) {
    reset($arDeliveryServiceAll);
    $deliveryObj = current($arDeliveryServiceAll);

    if ($deliveryObj->isProfile()) {
        $name = $deliveryObj->getNameWithParent();
    } else {
        $name = $deliveryObj->getName();
    }

    $shipment->setFields(array(
        'DELIVERY_ID' => $deliveryObj->getId(),
        'DELIVERY_NAME' => $name,
        'CURRENCY' => $order->getCurrency()
    ));

    $shipmentCollection->calculateDelivery();
}
/**/

/*Payment*/
$arPaySystemServiceAll = [];
$paySystemId = intval($_POST['oplata']);
$paymentCollection = $order->getPaymentCollection();

$remainingSum = $order->getPrice() - $paymentCollection->getSum();
if ($remainingSum > 0 || $order->getPrice() == 0)
{
    $extPayment = $paymentCollection->createItem();
    $extPayment->setField('SUM', $remainingSum);
    $arPaySystemServices = PaySystem\Manager::getListWithRestrictions($extPayment);

    $arPaySystemServiceAll += $arPaySystemServices;

    if (array_key_exists($paySystemId, $arPaySystemServiceAll))
    {
        $arPaySystem = $arPaySystemServiceAll[$paySystemId];
    }
    else
    {
        reset($arPaySystemServiceAll);

        $arPaySystem = current($arPaySystemServiceAll);
    }

    if (!empty($arPaySystem))
    {
        $extPayment->setFields(array(
            'PAY_SYSTEM_ID' => $arPaySystem["ID"],
            'PAY_SYSTEM_NAME' => $arPaySystem["NAME"]
        ));
    }
    else
        $extPayment->delete();
}
/**/

$order->doFinalAction(true);
$propertyCollection = $order->getPropertyCollection();
$emailProperty = getPropertyByCode($propertyCollection, 'EMAIL');
$emailProperty->setValue($email);

$nameProperty = getPropertyByCode($propertyCollection, 'FIO');
$nameProperty->setValue($fio);

$phoneProperty = getPropertyByCode($propertyCollection, 'PHONE');
$phoneProperty->setValue($phone);

$fileProperty = getPropertyByCode($propertyCollection, 'FILE');
$fileProperty->setValue($file);

$address = "Время доставки день: ".$_POST['day']." месяц: ".$_POST['month']." Часы: ".$_POST['hour']." Минуты: ".$_POST['minute']."Адрес: Улица".$_POST['street']." Метро: ".$_POST['metro']." Дом: ".$_POST['house']. "Корпус: ".$_POST['corpus']." Квартира: ".$_POST['flat'];
$addressProperty = getPropertyByCode($propertyCollection, 'ADDRESS');
$addressProperty->setValue($address);

$order->setField('CURRENCY', $currencyCode);
$order->setField('COMMENTS', $_POST['comment']);
$order->save();

$orderId = $order->GetId();
CSaleOrderProps::DoSaveOrderProps($orderId, 1, Array(20=>array($file))); 
echo "

Спасибо

Ваш заказ принят к обработке. В ближайшее время наши менеджеры свяжутся с Вами. Номер Вашего заказа - $orderId

"?>

Товара нет в наличичии