Totals.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Order\Invoice;
  7. use Magento\Sales\Model\Order;
  8. /**
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Totals extends \Magento\Sales\Block\Order\Totals
  13. {
  14. /**
  15. * @param \Magento\Framework\View\Element\Template\Context $context
  16. * @param \Magento\Framework\Registry $registry
  17. * @param array $data
  18. */
  19. public function __construct(
  20. \Magento\Framework\View\Element\Template\Context $context,
  21. \Magento\Framework\Registry $registry,
  22. array $data = []
  23. ) {
  24. parent::__construct($context, $registry, $data);
  25. $this->_isScopePrivate = true;
  26. }
  27. /**
  28. * @var Order|null
  29. */
  30. protected $_invoice = null;
  31. /**
  32. * @return Order
  33. */
  34. public function getInvoice()
  35. {
  36. if ($this->_invoice === null) {
  37. if ($this->hasData('invoice')) {
  38. $this->_invoice = $this->_getData('invoice');
  39. } elseif ($this->_coreRegistry->registry('current_invoice')) {
  40. $this->_invoice = $this->_coreRegistry->registry('current_invoice');
  41. } elseif ($this->getParentBlock()->getInvoice()) {
  42. $this->_invoice = $this->getParentBlock()->getInvoice();
  43. }
  44. }
  45. return $this->_invoice;
  46. }
  47. /**
  48. * @param Order $invoice
  49. * @return $this
  50. */
  51. public function setInvoice($invoice)
  52. {
  53. $this->_invoice = $invoice;
  54. return $this;
  55. }
  56. /**
  57. * Get totals source object
  58. *
  59. * @return Order
  60. */
  61. public function getSource()
  62. {
  63. return $this->getInvoice();
  64. }
  65. /**
  66. * Initialize order totals array
  67. *
  68. * @return $this
  69. */
  70. protected function _initTotals()
  71. {
  72. parent::_initTotals();
  73. $this->removeTotal('base_grandtotal');
  74. return $this;
  75. }
  76. }