M
M
mills2021-08-04 13:29:46
1C-Bitrix
mills, 2021-08-04 13:29:46

Deleting a product from an existing order without editing the discounts of other products in the order, how?

Hello!
Tell me, please, here I am deleting a product from an existing order, but when deleting, discounts on other products in the order disappear. Discounts disappear, most likely due to the fact that they are not in the cart rules ...
How can I do something that would delete only the specified product and not edit others, as well as recalculate the amount?

use Bitrix\Sale;

$order = Sale\Order::load($orderId);
$basket = Sale\Order::load($orderId)->getBasket();

foreach ($basket as $basketItem) {
   if ($basketItem->getField('PRODUCT_XML_ID')==$PRODUCT_ID) {
$zapID = $basketItem->getField('ID');
$basket->getItemById($zapID)->delete();
   }//endif

}//endforeach

$basket->save();
$order->refreshData();

$discount = $order->getDiscount();
\Bitrix\Sale\DiscountCouponsManager::clearApply(true);
\Bitrix\Sale\DiscountCouponsManager::useSavedCouponsForApply(true);
$discount->setOrderRefresh(true);
$discount->setApplyResult(array());
$discount->calculate();

$order->doFinalAction(true);
$result = $order->save();


I also have a question, please send me the documentation on how to ADD an existing product to an existing order, or maybe someone has an operating time, it would be cool if they shared the code.
I do all this to change the order from 1s.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mills, 2021-08-08
@mills

In my questions, the option is:
Create a basket rule for the goods added and immediately delete them, since they are not needed for the future.
In my case, I create discounts for goods that are transferred from 1s, then I delete everything from the order and add new products to the order already with discounts that are in the rules for the cart, and then I delete all the rules that have been created.
Works not bad.
If anyone is interested, write, I'll show what I wrote for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question