Skip to content

Commit

Permalink
Editing quantity from pimcore order details page updates order total …
Browse files Browse the repository at this point in the history
…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,
  • Loading branch information
pdchaudhary authored Jul 30, 2020
1 parent c50588c commit 1e74551
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions bundles/EcommerceFrameworkBundle/OrderManager/Order/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 1e74551

Please sign in to comment.