53 行
1.7KB

  1. <?php
  2. namespace Lc\ShopBundle\Services\Order;
  3. use Lc\ShopBundle\Context\OrderPaymentInterface;
  4. trait OrderUtilsPaymentTrait
  5. {
  6. public function createOrderPayment($orderShop, $meanPayment, $amount, $reference = null, $comment = null, $paidAt = null)
  7. {
  8. $classOrderPayment = $this->em->getClassMetadata(OrderPaymentInterface::class)->getName();
  9. $orderPayment = new $classOrderPayment;
  10. $orderPayment->setOrderShop($orderShop);
  11. $orderPayment->setMeanPayment($meanPayment);
  12. $orderPayment->setAmount($amount);
  13. $orderPayment->setReference($reference);
  14. $orderPayment->setComment($comment);
  15. $orderPayment->setEditable(false);
  16. if ($paidAt) {
  17. $orderPayment->setPaidAt($paidAt);
  18. } else {
  19. $orderPayment->setPaidAt(new \DateTime('now'));
  20. }
  21. $this->em->persist($orderPayment);
  22. $this->em->flush();
  23. return $orderPayment ;
  24. }
  25. public function isOrderPaid($order)
  26. {
  27. if ($this->getTotalOrderPayments($order) >= $this->priceUtils->getTotalWithTax($order)) {
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. }
  33. public function getTotalOrderPayments($order): float
  34. {
  35. $totalAmount = floatval(0);
  36. foreach ($order->getOrderPayments() as $orderPayment) {
  37. $totalAmount = $orderPayment->getAmount() + $totalAmount;
  38. }
  39. return $totalAmount;
  40. }
  41. }