Exemplo n.º 1
0
 /**
  * @param \Generated\Shared\Transfer\RefundTransfer $refundTransfer
  * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
  * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] array $salesOrderItems
  *
  * @return \Generated\Shared\Transfer\RefundTransfer
  */
 public function calculateRefund(RefundTransfer $refundTransfer, OrderTransfer $orderTransfer, array $salesOrderItems)
 {
     $refundedItemAmount = 0;
     foreach ($orderTransfer->getItems() as $itemTransfer) {
         if ($this->shouldItemRefunded($itemTransfer, $salesOrderItems)) {
             $refundTransfer->addItem($itemTransfer);
         } else {
             $refundedItemAmount += (int) $itemTransfer->getRefundableAmount();
         }
     }
     if ($refundedItemAmount === 0) {
         $refundTransfer->setExpenses($orderTransfer->getExpenses());
     }
     $this->calculateRefundableExpenseAmount($refundTransfer);
     $this->setCanceledExpenseAmount($refundTransfer);
     return $refundTransfer;
 }