Answer the question
In order to leave comments, you need to log in
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();
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question