Totals.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Order\Creditmemo;
  7. use Magento\Sales\Model\Order\Creditmemo;
  8. /**
  9. * Adminhtml order creditmemo totals block
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class Totals extends \Magento\Sales\Block\Adminhtml\Totals
  16. {
  17. /**
  18. * Creditmemo
  19. *
  20. * @var Creditmemo|null
  21. */
  22. protected $_creditmemo;
  23. /**
  24. * Retrieve creditmemo model instance
  25. *
  26. * @return Creditmemo
  27. */
  28. public function getCreditmemo()
  29. {
  30. if ($this->_creditmemo === null) {
  31. if ($this->hasData('creditmemo')) {
  32. $this->_creditmemo = $this->_getData('creditmemo');
  33. } elseif ($this->_coreRegistry->registry('current_creditmemo')) {
  34. $this->_creditmemo = $this->_coreRegistry->registry('current_creditmemo');
  35. } elseif ($this->getParentBlock() && $this->getParentBlock()->getCreditmemo()) {
  36. $this->_creditmemo = $this->getParentBlock()->getCreditmemo();
  37. }
  38. }
  39. return $this->_creditmemo;
  40. }
  41. /**
  42. * Get source
  43. *
  44. * @return Creditmemo|null
  45. */
  46. public function getSource()
  47. {
  48. return $this->getCreditmemo();
  49. }
  50. /**
  51. * Initialize creditmemo totals array
  52. *
  53. * @return $this
  54. */
  55. protected function _initTotals()
  56. {
  57. parent::_initTotals();
  58. $this->addTotal(
  59. new \Magento\Framework\DataObject(
  60. [
  61. 'code' => 'adjustment_positive',
  62. 'value' => $this->getSource()->getAdjustmentPositive(),
  63. 'base_value' => $this->getSource()->getBaseAdjustmentPositive(),
  64. 'label' => __('Adjustment Refund'),
  65. ]
  66. )
  67. );
  68. $this->addTotal(
  69. new \Magento\Framework\DataObject(
  70. [
  71. 'code' => 'adjustment_negative',
  72. 'value' => $this->getSource()->getAdjustmentNegative(),
  73. 'base_value' => $this->getSource()->getBaseAdjustmentNegative(),
  74. 'label' => __('Adjustment Fee'),
  75. ]
  76. )
  77. );
  78. return $this;
  79. }
  80. }