Changing amount of orderline item along with price

Hello,

i want to change the amount of an order line item via script/DAL

the order line item dataset has 4 columns related to the price and quantity ordered

quantity / total_price

price_definition

price

 

i created my custom controller (inheriting from AbstractController) and this is my code to change the orderline item

/** @var EntityRepositoryInterface $orderLineItemRepository */

$orderLineItemRepository = $this->container->get(‚order_line_item.repository‘);

$orderedProducts = $this->oiUtils->getOrderedProducts($orderLineItemRepository, $orderID, $context); // $orderID is generated earlier and is the qualified UUID of the respecting order

my own class oiUtils has the function getOrderedProducts which returns an array with all order line items from the order described by $orderID

i then loop through the order line items and compare the quantity value with another value i received from another source.

if the values differ i want to update the order line item with the new quantity, as well as the new price depending on the quantity.

by using the DAL directly i cannot achieve only a change of quantity, but not in total price

 

$orderLineItemRepository->update(

[

[‚id‘ => $orderLineItem->getId(), ‚quantity‘ => $reportedAmount],

],

Context::createDefaultContext()

);

this changes the quantity, but won’t change the total_price, i cannot override the total_price value „manually“

$orderLineItemRepository->update(

[

[‚id‘ => $orderLineItem->getId(), ‚quantity‘ => $reportedAmount, ‚totalPrice‘ => $newTotal],

],

Context::createDefaultContext()

);

 

won’t change anything.

 

so ye i think i need to call some specific event or what ever, but tbh, searching the documentation won’t yield useful information. anyone had such a problem or has already solved such a problem?

 

 

 

if i adjust the quantity and go to the orders tab in the administration later on i can just tap the edit button and accept and the real price will be calculated without problem