Cost.php 738 B

123456789101112131415161718192021222324252627
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\Order\Invoice\Total;
  7. class Cost extends AbstractTotal
  8. {
  9. /**
  10. * Collect total cost of invoiced items
  11. *
  12. * @param \Magento\Sales\Model\Order\Invoice $invoice
  13. * @return $this
  14. */
  15. public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
  16. {
  17. $baseInvoiceTotalCost = 0;
  18. foreach ($invoice->getAllItems() as $item) {
  19. if (!$item->getHasChildren()) {
  20. $baseInvoiceTotalCost += $item->getBaseCost() * $item->getQty();
  21. }
  22. }
  23. $invoice->setBaseCost($baseInvoiceTotalCost);
  24. return $this;
  25. }
  26. }