Weee.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Weee\Model\Sales\Pdf;
  7. /**
  8. * Sales order total for PDF, taking into account WEEE tax
  9. */
  10. class Weee extends \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal
  11. {
  12. /**
  13. * @var \Magento\Weee\Helper\Data
  14. */
  15. protected $_weeeData;
  16. /**
  17. * @param \Magento\Tax\Helper\Data $taxHelper
  18. * @param \Magento\Tax\Model\Calculation $taxCalculation
  19. * @param \Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory $ordersFactory
  20. * @param \Magento\Weee\Helper\Data $_weeeData
  21. * @param array $data
  22. */
  23. public function __construct(
  24. \Magento\Tax\Helper\Data $taxHelper,
  25. \Magento\Tax\Model\Calculation $taxCalculation,
  26. \Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory $ordersFactory,
  27. \Magento\Weee\Helper\Data $_weeeData,
  28. array $data = []
  29. ) {
  30. $this->_weeeData = $_weeeData;
  31. parent::__construct($taxHelper, $taxCalculation, $ordersFactory, $data);
  32. }
  33. /**
  34. * Check if weee total amount should be included
  35. *
  36. * Example:
  37. * array(
  38. * $index => array(
  39. * 'amount' => $amount,
  40. * 'label' => $label,
  41. * 'font_size'=> $font_size
  42. * )
  43. * )
  44. *
  45. * @return array
  46. */
  47. public function getTotalsForDisplay()
  48. {
  49. /** @var $items \Magento\Sales\Model\Order\Item[] */
  50. $items = $this->getSource()->getAllItems();
  51. $store = $this->getSource()->getStore();
  52. $weeeTotal = $this->_weeeData->getTotalAmounts($items, $store);
  53. // If we have no Weee, check if we still need to display it
  54. if (!$weeeTotal && !filter_var($this->getDisplayZero(), FILTER_VALIDATE_BOOLEAN)) {
  55. return [];
  56. }
  57. // Display the Weee total amount
  58. $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
  59. $totals = [
  60. [
  61. 'amount' => $this->getOrder()->formatPriceTxt($weeeTotal),
  62. 'label' => __($this->getTitle()) . ':',
  63. 'font_size' => $fontSize,
  64. ],
  65. ];
  66. return $totals;
  67. }
  68. /**
  69. * Check if we can display Weee total information in PDF
  70. *
  71. * @return bool
  72. */
  73. public function canDisplay()
  74. {
  75. $items = $this->getSource()->getAllItems();
  76. $store = $this->getSource()->getStore();
  77. $amount = $this->_weeeData->getTotalAmounts($items, $store);
  78. return $this->getDisplayZero() === 'true' || $amount != 0;
  79. }
  80. }