Totals.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Weee\Block\Sales\Order;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class Totals extends \Magento\Framework\View\Element\Template
  12. {
  13. /**
  14. * @var \Magento\Weee\Helper\Data
  15. */
  16. protected $weeeData;
  17. /**
  18. * @param \Magento\Framework\View\Element\Template\Context $context
  19. * @param \Magento\Weee\Helper\Data $weeeData
  20. * @param array $data
  21. */
  22. public function __construct(
  23. \Magento\Framework\View\Element\Template\Context $context,
  24. \Magento\Weee\Helper\Data $weeeData,
  25. array $data = []
  26. ) {
  27. $this->weeeData = $weeeData;
  28. parent::__construct($context, $data);
  29. }
  30. /**
  31. * Get totals source object
  32. *
  33. * @return \Magento\Sales\Model\Order
  34. */
  35. public function getSource()
  36. {
  37. return $this->getParentBlock()->getSource();
  38. }
  39. /**
  40. * Create the weee ("FPT") totals summary
  41. *
  42. * @return $this
  43. */
  44. public function initTotals()
  45. {
  46. /** @var $items \Magento\Sales\Model\Order\Item[] */
  47. $items = $this->getSource()->getAllItems();
  48. $store = $this->getSource()->getStore();
  49. $weeeTotal = $this->weeeData->getTotalAmounts($items, $store);
  50. $weeeBaseTotal = $this->weeeData->getBaseTotalAmounts($items, $store);
  51. if ($weeeTotal) {
  52. // Add our total information to the set of other totals
  53. $total = new \Magento\Framework\DataObject(
  54. [
  55. 'code' => $this->getNameInLayout(),
  56. 'label' => __('FPT'),
  57. 'value' => $weeeTotal,
  58. 'base_value' => $weeeBaseTotal
  59. ]
  60. );
  61. if ($this->getBeforeCondition()) {
  62. $this->getParentBlock()->addTotalBefore($total, $this->getBeforeCondition());
  63. } else {
  64. $this->getParentBlock()->addTotal($total, $this->getAfterCondition());
  65. }
  66. }
  67. return $this;
  68. }
  69. }