Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
10 namespace Magento\Shipping\Helper;
11 
15 
17 {
23  protected $_allowedHashKeys = ['ship_id', 'order_id', 'track_id'];
24 
28  protected $_storeManager;
29 
33  private $url;
34 
40  public function __construct(
41  \Magento\Framework\App\Helper\Context $context,
43  UrlInterface $url = null
44  ) {
45  $this->_storeManager = $storeManager;
46  $this->url = $url ?: ObjectManager::getInstance()->get(UrlInterface::class);
47 
48  parent::__construct($context);
49  }
50 
57  public function decodeTrackingHash($hash)
58  {
59  $hash = explode(':', $this->urlDecoder->decode($hash));
60  if (count($hash) === 3 && in_array($hash[0], $this->_allowedHashKeys)) {
61  return ['key' => $hash[0], 'id' => (int)$hash[1], 'hash' => $hash[2]];
62  }
63  return [];
64  }
65 
75  protected function _getTrackingUrl($key, $model, $method = 'getId')
76  {
77  $urlPart = "{$key}:{$model->{$method}()}:{$model->getProtectCode()}";
78  $params = [
79  '_scope' => $model->getStoreId(),
80  '_nosid' => true,
81  '_direct' => 'shipping/tracking/popup',
82  '_query' => ['hash' => $this->urlEncoder->encode($urlPart)]
83  ];
84 
85  return $this->url->getUrl('', $params);
86  }
87 
95  {
96  if ($model instanceof \Magento\Sales\Model\Order) {
97  return $this->_getTrackingUrl('order_id', $model);
98  } elseif ($model instanceof \Magento\Sales\Model\Order\Shipment) {
99  return $this->_getTrackingUrl('ship_id', $model);
100  } elseif ($model instanceof \Magento\Sales\Model\Order\Shipment\Track) {
101  return $this->_getTrackingUrl('track_id', $model, 'getEntityId');
102  }
103  return '';
104  }
105 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$storeManager
getTrackingPopupUrlBySalesModel($model)
Definition: Data.php:94
__construct(\Magento\Framework\App\Helper\Context $context, StoreManagerInterface $storeManager, UrlInterface $url=null)
Definition: Data.php:40
_getTrackingUrl($key, $model, $method='getId')
Definition: Data.php:75
$method
Definition: info.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18