+7 495 008 8452 пн.-пт. 10:00 – 17:00
Загрузка...
Если у вас возникли какие либо вопросы которые вы не смогли решить по нашим публикациям самостоятельно,
то ждем ваше обращение в нашей службе тех поддержки.


Процедура оформления заказа на d7

Так можно ручками создать заказ
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");

global $USER;

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 = 'Пупкин Василий';
$phone = '9511111111';
$email = 'pupkin@mail.ru';

$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 = 1;
$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);

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

$order->setField('CURRENCY', $currencyCode);
//Комментарий менеджера
$order->setField('COMMENTS', 'Комментарии менеджера');
//Комментарий покупателя
$order->setField('USER_DESCRIPTION', 'Комментарии покупателя');

$order->save();

$orderId = $order->GetId();

Доставки и оплаты пока в тесте. Но вроде работать должно
https://github.com/SidiGi/bitrix-info/...0%B8%D0...

PS Компонент для оформления заказа на новом апи:
https://github.com/SidiGi/bitrix-order




Назад в раздел

Подписаться на новые материалы раздела:
Загрузка...