Totals.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Order\Creditmemo;
  7. use Magento\Sales\Model\Order\Creditmemo;
  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 Creditmemo|null
  29. */
  30. protected $_creditmemo = null;
  31. /**
  32. * @return Creditmemo|null
  33. */
  34. public function getCreditmemo()
  35. {
  36. if ($this->_creditmemo === null) {
  37. if ($this->hasData('creditmemo')) {
  38. $this->_creditmemo = $this->_getData('creditmemo');
  39. } elseif ($this->_coreRegistry->registry('current_creditmemo')) {
  40. $this->_creditmemo = $this->_coreRegistry->registry('current_creditmemo');
  41. } elseif ($this->getParentBlock()->getCreditmemo()) {
  42. $this->_creditmemo = $this->getParentBlock()->getCreditmemo();
  43. }
  44. }
  45. return $this->_creditmemo;
  46. }
  47. /**
  48. * @param Creditmemo $creditmemo
  49. * @return $this
  50. */
  51. public function setCreditmemo($creditmemo)
  52. {
  53. $this->_creditmemo = $creditmemo;
  54. return $this;
  55. }
  56. /**
  57. * Get totals source object
  58. *
  59. * @return Creditmemo
  60. */
  61. public function getSource()
  62. {
  63. return $this->getCreditmemo();
  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. if ((double)$this->getSource()->getAdjustmentPositive()) {
  75. $total = new \Magento\Framework\DataObject(
  76. [
  77. 'code' => 'adjustment_positive',
  78. 'value' => $this->getSource()->getAdjustmentPositive(),
  79. 'label' => __('Adjustment Refund'),
  80. ]
  81. );
  82. $this->addTotal($total);
  83. }
  84. if ((double)$this->getSource()->getAdjustmentNegative()) {
  85. $total = new \Magento\Framework\DataObject(
  86. [
  87. 'code' => 'adjustment_negative',
  88. 'value' => $this->getSource()->getAdjustmentNegative(),
  89. 'label' => __('Adjustment Fee'),
  90. ]
  91. );
  92. $this->addTotal($total);
  93. }
  94. /**
  95. <?php if ($this->getCanDisplayTotalPaid()): ?>
  96. <tr>
  97. <td colspan="6" class="a-right"><strong><?= __('Total Paid') ?></strong></td>
  98. <td class="last a-right"><strong><?= $_order->formatPrice($_creditmemo->getTotalPaid()) ?></strong></td>
  99. </tr>
  100. <?php endif; ?>
  101. <?php if ($this->getCanDisplayTotalRefunded()): ?>
  102. <tr>
  103. <td colspan="6" class="a-right"><strong><?= __('Total Refunded') ?></strong></td>
  104. <td class="last a-right"><strong><?= $_order->formatPrice($_creditmemo->getTotalRefunded()) ?></strong></td>
  105. </tr>
  106. <?php endif; ?>
  107. <?php if ($this->getCanDisplayTotalDue()): ?>
  108. <tr>
  109. <td colspan="6" class="a-right"><strong><?= __('Total Due') ?></strong></td>
  110. <td class="last a-right"><strong><?= $_order->formatPrice($_creditmemo->getTotalDue()) ?></strong></td>
  111. </tr>
  112. <?php endif; ?>
  113. */
  114. return $this;
  115. }
  116. }