From 1e7455153418cf1cfe7beefb0b4c3aef757907c8 Mon Sep 17 00:00:00 2001 From: pravin chaudhary <30948231+pdchaudhary@users.noreply.github.com> Date: Thu, 30 Jul 2020 19:56:03 +0530 Subject: [PATCH] Editing quantity from pimcore order details page updates order total and order item total Issue : https://github.com/pimcore/pimcore/issues/6852 Editing quantity from pimcore order details page it is not updating order item total and order total so using this we can update order on chaning qunitiy, --- .../OrderManager/Order/Agent.php | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/bundles/EcommerceFrameworkBundle/OrderManager/Order/Agent.php b/bundles/EcommerceFrameworkBundle/OrderManager/Order/Agent.php index f875f4da75f..e5dcdad351f 100644 --- a/bundles/EcommerceFrameworkBundle/OrderManager/Order/Agent.php +++ b/bundles/EcommerceFrameworkBundle/OrderManager/Order/Agent.php @@ -175,24 +175,54 @@ public function itemChangeAmount(OrderItem $item, $amount) } /** - * start item complaint + * change order item * * @param OrderItem $item - * @param float $quantity + * @param float $amount * * @return Note */ - public function itemComplaint(OrderItem $item, $quantity) + public function itemChangeAmount(OrderItem $item, $amount) { + // init + + $amount = floatval($amount); + // add log note $note = $this->createNote($item); $note->setTitle(__FUNCTION__); - $note->addData('quantity', 'text', $quantity); - + $oldAmount = $item->getAmount(); + $note->addData('amount.old', 'text', $oldAmount); + $note->addData('amount.new', 'text', $amount); + $oldTotalPrice = $item->getTotalPrice(); + $unitPrice = $oldTotalPrice/$oldAmount; + $newTotalPrice =$unitPrice*$amount; + // change + $item->setAmount($amount); + $item->setTotalPrice( $newTotalPrice); // save + $item->save(); $note->save(); - + $this->updateOrder($item,$oldTotalPrice,$newTotalPrice); return $note; + + } + + + public function updateOrder($item,$oldTotalPrice,$newTotalPrice) + { + + $order = $item->getParent(); + $subTotalNetPrice = $order->getSubTotalNetPrice(); + $subTotalPrice = $order->getSubTotalPrice(); + $totalNetPrice = $order->getTotalNetPrice(); + $totalPrice = $order->getTotalPrice(); + $replacedvalue = $newTotalPrice -$oldTotalPrice; + $order->setSubTotalNetPrice($subTotalNetPrice +$replacedvalue); + $order->setSubTotalPrice($subTotalPrice+$replacedvalue); + $order->setTotalNetPrice($totalNetPrice+$replacedvalue); + $order->setTotalPrice($totalPrice+$replacedvalue); + $order->save(); } /**