Popup.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Block\Tracking;
  7. use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
  8. /**
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Popup extends \Magento\Framework\View\Element\Template
  13. {
  14. /**
  15. * Core registry
  16. *
  17. * @var \Magento\Framework\Registry
  18. */
  19. protected $_registry;
  20. /**
  21. * @var DateTimeFormatterInterface
  22. */
  23. protected $dateTimeFormatter;
  24. /**
  25. * @param \Magento\Framework\View\Element\Template\Context $context
  26. * @param \Magento\Framework\Registry $registry
  27. * @param DateTimeFormatterInterface $dateTimeFormatter
  28. * @param array $data
  29. */
  30. public function __construct(
  31. \Magento\Framework\View\Element\Template\Context $context,
  32. \Magento\Framework\Registry $registry,
  33. DateTimeFormatterInterface $dateTimeFormatter,
  34. array $data = []
  35. ) {
  36. $this->_registry = $registry;
  37. parent::__construct($context, $data);
  38. $this->dateTimeFormatter = $dateTimeFormatter;
  39. }
  40. /**
  41. * Retrieve array of tracking info
  42. *
  43. * @return array
  44. */
  45. public function getTrackingInfo()
  46. {
  47. /* @var $info \Magento\Shipping\Model\Info */
  48. $info = $this->_registry->registry('current_shipping_info');
  49. return $info->getTrackingInfo();
  50. }
  51. /**
  52. * Format given date and time in current locale without changing timezone
  53. *
  54. * @param string $date
  55. * @param string $time
  56. * @return string
  57. */
  58. public function formatDeliveryDateTime($date, $time)
  59. {
  60. return $this->formatDeliveryDate($date) . ' ' . $this->formatDeliveryTime($time);
  61. }
  62. /**
  63. * Format given date in current locale without changing timezone
  64. *
  65. * @param string $date
  66. * @return string
  67. */
  68. public function formatDeliveryDate($date)
  69. {
  70. $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::MEDIUM);
  71. return $this->dateTimeFormatter->formatObject($this->_localeDate->date(new \DateTime($date)), $format);
  72. }
  73. /**
  74. * Format given time [+ date] in current locale without changing timezone
  75. *
  76. * @param string $time
  77. * @param string $date
  78. * @return string
  79. */
  80. public function formatDeliveryTime($time, $date = null)
  81. {
  82. if (!empty($date)) {
  83. $time = $date . ' ' . $time;
  84. }
  85. $format = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
  86. return $this->dateTimeFormatter->formatObject($this->_localeDate->date(new \DateTime($time)), $format);
  87. }
  88. /**
  89. * Is 'contact us' option enabled?
  90. *
  91. * @return boolean
  92. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  93. */
  94. public function getContactUsEnabled()
  95. {
  96. return (bool)$this->_scopeConfig->getValue(
  97. 'contacts/contacts/enabled',
  98. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  99. );
  100. }
  101. /**
  102. * @return string
  103. */
  104. public function getStoreSupportEmail()
  105. {
  106. return $this->_scopeConfig->getValue(
  107. 'trans_email/ident_support/email',
  108. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  109. );
  110. }
  111. /**
  112. * @return string
  113. */
  114. public function getContactUs()
  115. {
  116. return $this->getUrl('contact');
  117. }
  118. }