Unitofmeasure.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Dhl\Block\Adminhtml;
  7. use Magento\Dhl\Model;
  8. use Magento\Shipping\Helper;
  9. use Magento\Backend\Block\Template\Context;
  10. use Magento\Config\Block\System\Config\Form\Field;
  11. use Magento\Framework\Data\Form\Element\AbstractElement;
  12. /**
  13. * Frontend model for DHL shipping methods for documentation
  14. */
  15. class Unitofmeasure extends Field
  16. {
  17. /**
  18. * Carrier helper
  19. *
  20. * @var Helper\Carrier
  21. */
  22. protected $carrierHelper;
  23. /**
  24. * @var Model\Carrier
  25. */
  26. protected $carrierDhl;
  27. /**
  28. * @param Context $context
  29. * @param Model\Carrier $carrierDhl
  30. * @param Helper\Carrier $carrierHelper
  31. * @param array $data
  32. */
  33. public function __construct(
  34. Context $context,
  35. Model\Carrier $carrierDhl,
  36. Helper\Carrier $carrierHelper,
  37. array $data = []
  38. ) {
  39. $this->carrierDhl = $carrierDhl;
  40. $this->carrierHelper = $carrierHelper;
  41. parent::__construct($context, $data);
  42. }
  43. /**
  44. * Define params and variables
  45. *
  46. * @return void
  47. */
  48. public function _construct()
  49. {
  50. parent::_construct();
  51. $this->setInch($this->carrierDhl->getCode('unit_of_dimension_cut', 'I'));
  52. $this->setCm($this->carrierDhl->getCode('unit_of_dimension_cut', 'C'));
  53. $this->setHeight($this->carrierDhl->getCode('dimensions', 'height'));
  54. $this->setDepth($this->carrierDhl->getCode('dimensions', 'depth'));
  55. $this->setWidth($this->carrierDhl->getCode('dimensions', 'width'));
  56. $kgWeight = 70;
  57. $this->setDivideOrderWeightNoteKg(
  58. __(
  59. 'Select this to allow DHL to optimize shipping charges by splitting the order if it exceeds %1 %2.',
  60. $kgWeight,
  61. 'kg'
  62. )
  63. );
  64. $convertedWeight = $this->carrierHelper->convertMeasureWeight(
  65. $kgWeight,
  66. \Zend_Measure_Weight::KILOGRAM,
  67. \Zend_Measure_Weight::POUND
  68. );
  69. $weight = sprintf('%.3f', $convertedWeight);
  70. $this->setDivideOrderWeightNoteLbp(
  71. __(
  72. 'Select this to allow DHL to optimize shipping charges by splitting the order if it exceeds %1 %2.',
  73. $weight,
  74. 'pounds'
  75. )
  76. );
  77. $this->setTemplate('Magento_Dhl::unitofmeasure.phtml');
  78. }
  79. /**
  80. * Retrieve Element HTML fragment
  81. *
  82. * @param AbstractElement $element
  83. * @return string
  84. */
  85. protected function _getElementHtml(AbstractElement $element)
  86. {
  87. return parent::_getElementHtml($element) . $this->_toHtml();
  88. }
  89. }