M
M
mills2021-06-30 08:26:53
1C-Bitrix
mills, 2021-06-30 08:26:53

Splitting 1 order into 2, how can it be implemented?

Hello!
It is necessary to implement division of the order.
Maybe someone did, tell me how to implement it, please?

For example, in an order there are 2 products marked as a hit and 2 products without a hit marked. Here it is necessary to divide orders 2 by 2, so that there would be 2 orders, respectively, under different numbers ...

I think how to implement it, but so far nothing comes to mind.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2021-06-30
@rpsv

$orderOld = Order::load($id);
$orderNew = Order::create(SITE_ID);

$basketOld = $orderOld->getBasket();
$basketNew = $orderNew->getBasket();

// выбираете нужные товары из старого заказа и добавляете в новый
foreach ($basketOld as $basketItem) {
    /**
     * @var BasketItem $basketItem
     */
    $basketNew->addItem($basketItem);
    $basketOld->deleteItem($basketItem->getInternalIndex());
}

$orderOld->save();
$orderNew->save();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question