Grand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\Quote\Address\Total;
  7. class Grand extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
  8. {
  9. /**
  10. * Collect grand total address amount
  11. *
  12. * @param \Magento\Quote\Model\Quote $quote
  13. * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
  14. * @param \Magento\Quote\Model\Quote\Address\Total $total
  15. * @return $this
  16. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  17. */
  18. public function collect(
  19. \Magento\Quote\Model\Quote $quote,
  20. \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
  21. \Magento\Quote\Model\Quote\Address\Total $total
  22. ) {
  23. $grandTotal = $total->getGrandTotal();
  24. $baseGrandTotal = $total->getBaseGrandTotal();
  25. $totals = array_sum($total->getAllTotalAmounts());
  26. $baseTotals = array_sum($total->getAllBaseTotalAmounts());
  27. $total->setGrandTotal($grandTotal + $totals);
  28. $total->setBaseGrandTotal($baseGrandTotal + $baseTotals);
  29. return $this;
  30. }
  31. /**
  32. * Add grand total information to address
  33. *
  34. * @param \Magento\Quote\Model\Quote $quote
  35. * @param \Magento\Quote\Model\Quote\Address\Total $total
  36. * @return $this
  37. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  38. */
  39. public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
  40. {
  41. return [
  42. 'code' => $this->getCode(),
  43. 'title' => __('Grand Total'),
  44. 'value' => $total->getGrandTotal(),
  45. 'area' => 'footer',
  46. ];
  47. }
  48. }