/app/code/core/Mage/Shipping/Helper/Data.php

https://github.com/gryzz/crystal_magento · PHP · 152 lines · 63 code · 9 blank · 80 comment · 9 complexity · 972055021822c5cbd33a46d46da780ad MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Shipping
  23. * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Shipping data helper
  28. */
  29. class Mage_Shipping_Helper_Data extends Mage_Core_Helper_Abstract
  30. {
  31. /**
  32. * Allowed hash keys
  33. *
  34. * @var array
  35. */
  36. protected $_allowedHashKeys = array('ship_id', 'order_id', 'track_id');
  37. /**
  38. * Decode url hash
  39. *
  40. * @param string $hash
  41. * @return array
  42. */
  43. public function decodeTrackingHash($hash)
  44. {
  45. $hash = explode(':', Mage::helper('core')->urlDecode($hash));
  46. if (count($hash) === 3 && in_array($hash[0], $this->_allowedHashKeys)) {
  47. return array('key' => $hash[0], 'id' => (int)$hash[1], 'hash' => $hash[2]);
  48. }
  49. return array();
  50. }
  51. /**
  52. * Retrieve tracking url with params
  53. *
  54. * @deprecated the non-model usage
  55. *
  56. * @param string $key
  57. * @param integer|Mage_Sales_Model_Order|Mage_Sales_Model_Order_Shipment|Mage_Sales_Model_Order_Shipment_Track $model
  58. * @param string $method - option
  59. * @return string
  60. */
  61. protected function _getTrackingUrl($key, $model, $method = 'getId')
  62. {
  63. if (empty($model)) {
  64. $param = array($key => ''); // @deprecated after 1.4.0.0-alpha3
  65. } else if (!is_object($model)) {
  66. $param = array($key => $model); // @deprecated after 1.4.0.0-alpha3
  67. } else {
  68. $param = array(
  69. 'hash' => Mage::helper('core')->urlEncode("{$key}:{$model->$method()}:{$model->getProtectCode()}")
  70. );
  71. }
  72. $storeModel = Mage::app()->getStore($model->getStoreId());
  73. return $storeModel->getUrl('shipping/tracking/popup', $param);
  74. }
  75. /**
  76. * @deprecated after 1.4.0.0-alpha3
  77. * Retrieve tracking pop up url by order id or object
  78. *
  79. * @param int|Mage_Sales_Model_Order $order
  80. * @return string
  81. */
  82. public function getTrackingPopUpUrlByOrderId($order = '')
  83. {
  84. return $this->_getTrackingUrl('order_id', $order);
  85. }
  86. /**
  87. * @deprecated after 1.4.0.0-alpha3
  88. * Retrieve tracking pop up url by track id or object
  89. *
  90. * @param int|Mage_Sales_Model_Order_Shipment_Track $track
  91. * @return string
  92. */
  93. public function getTrackingPopUpUrlByTrackId($track = '')
  94. {
  95. return $this->_getTrackingUrl('track_id', $track, 'getEntityId');
  96. }
  97. /**
  98. * @deprecated after 1.4.0.0-alpha3
  99. * Retrieve tracking pop up url by ship id or object
  100. *
  101. * @param int|Mage_Sales_Model_Order_Shipment $track
  102. * @return string
  103. */
  104. public function getTrackingPopUpUrlByShipId($ship = '')
  105. {
  106. return $this->_getTrackingUrl('ship_id', $ship);
  107. }
  108. /**
  109. * Shipping tracking popup URL getter
  110. *
  111. * @param Mage_Sales_Model_Abstract $model
  112. * @return string
  113. */
  114. public function getTrackingPopupUrlBySalesModel($model)
  115. {
  116. if ($model instanceof Mage_Sales_Model_Order) {
  117. return $this->_getTrackingUrl('order_id', $model);
  118. } elseif ($model instanceof Mage_Sales_Model_Order_Shipment) {
  119. return $this->_getTrackingUrl('ship_id', $model);
  120. } elseif ($model instanceof Mage_Sales_Model_Order_Shipment_Track) {
  121. return $this->_getTrackingUrl('track_id', $model, 'getEntityId');
  122. }
  123. return '';
  124. }
  125. /**
  126. * Retrieve tracking ajax url
  127. *
  128. * @return string
  129. */
  130. public function getTrackingAjaxUrl()
  131. {
  132. return $this->_getUrl('shipping/tracking/ajax');
  133. }
  134. public function isFreeMethod($method, $storeId = null)
  135. {
  136. $arr = explode('_', $method, 2);
  137. if (!isset($arr[1])) {
  138. return false;
  139. }
  140. $freeMethod = Mage::getStoreConfig('carriers/' . $arr[0] . '/free_method', $storeId);
  141. return $freeMethod == $arr[1];
  142. }
  143. }