Subtotal.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\Order\Creditmemo\Total;
  7. class Subtotal extends AbstractTotal
  8. {
  9. /**
  10. * Collect Creditmemo subtotal
  11. *
  12. * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
  13. * @return $this
  14. */
  15. public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
  16. {
  17. $subtotal = 0;
  18. $baseSubtotal = 0;
  19. $subtotalInclTax = 0;
  20. $baseSubtotalInclTax = 0;
  21. foreach ($creditmemo->getAllItems() as $item) {
  22. if ($item->getOrderItem()->isDummy()) {
  23. continue;
  24. }
  25. $item->calcRowTotal();
  26. $subtotal += $item->getRowTotal();
  27. $baseSubtotal += $item->getBaseRowTotal();
  28. $subtotalInclTax += $item->getRowTotalInclTax();
  29. $baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
  30. }
  31. $creditmemo->setSubtotal($subtotal);
  32. $creditmemo->setBaseSubtotal($baseSubtotal);
  33. $creditmemo->setSubtotalInclTax($subtotalInclTax);
  34. $creditmemo->setBaseSubtotalInclTax($baseSubtotalInclTax);
  35. $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $subtotal);
  36. $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseSubtotal);
  37. return $this;
  38. }
  39. }