/app/code/core/Enterprise/Rma/Block/Adminhtml/Rma/Edit/Tab/General/Shipping/Packaging.php

https://bitbucket.org/kdms/sh-magento · PHP · 289 lines · 167 code · 26 blank · 96 comment · 24 complexity · a240d7ca8b9bdfe25fb9f4859939560a MD5 · raw file

  1. <?php
  2. /**
  3. * Magento Enterprise Edition
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Magento Enterprise Edition License
  8. * that is bundled with this package in the file LICENSE_EE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.magentocommerce.com/license/enterprise-edition
  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 Enterprise
  22. * @package Enterprise_Rma
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://www.magentocommerce.com/license/enterprise-edition
  25. */
  26. /**
  27. * Shipment packaging
  28. *
  29. * @category Enterprise
  30. * @package Enterprise_RMA
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Enterprise_Rma_Block_Adminhtml_Rma_Edit_Tab_General_Shipping_Packaging extends Mage_Adminhtml_Block_Template
  34. {
  35. /**
  36. * Variable to store RMA instance
  37. *
  38. * @var null|Enterprise_Rma_Model_Rma
  39. */
  40. protected $_rma = null;
  41. /**
  42. * Declare rma instance
  43. *
  44. * @return Enterprise_Rma_Model_Item
  45. */
  46. public function getRma()
  47. {
  48. if (is_null($this->_rma)) {
  49. $this->_rma = Mage::registry('current_rma');
  50. }
  51. return $this->_rma;
  52. }
  53. /**
  54. * Retrieve carrier
  55. *
  56. * @return string
  57. */
  58. public function getCarrier()
  59. {
  60. return Mage::helper('enterprise_rma')->getCarrier(
  61. $this->getRequest()->getParam('method'),
  62. $this->getRma()->getStoreId()
  63. );
  64. }
  65. /**
  66. * Retrieve carrier method
  67. *
  68. * @return null|string
  69. */
  70. public function getCarrierMethod()
  71. {
  72. $code = explode('_', $this->getRequest()->getParam('method'), 2);
  73. if (is_array($code) && isset($code[1])) {
  74. return $code[1];
  75. } else {
  76. return null;
  77. }
  78. }
  79. /**
  80. * Return container types of carrier
  81. *
  82. * @return array
  83. */
  84. public function getContainers()
  85. {
  86. $order = $this->getRma()->getOrder();
  87. $storeId = $this->getRma()->getStoreId();
  88. $address = $order->getShippingAddress();
  89. $carrier = $this->getCarrier();
  90. $countryRecipient = Mage::helper('enterprise_rma')->getReturnAddressModel($storeId)->getCountryId();
  91. if ($carrier) {
  92. $params = new Varien_Object(array(
  93. 'method' => $this->getCarrierMethod(),
  94. 'country_shipper' => $address->getCountryId(),
  95. 'country_recipient' => $countryRecipient,
  96. ));
  97. return $carrier->getContainerTypes($params);
  98. }
  99. return array();
  100. }
  101. /**
  102. * Can display customs value
  103. *
  104. * @return bool
  105. */
  106. public function displayCustomsValue()
  107. {
  108. $storeId = $this->getRma()->getStoreId();
  109. $order = $this->getRma()->getOrder();
  110. $address = $order->getShippingAddress();
  111. $shipperAddressCountryCode = $address->getCountryId();
  112. $recipientAddressCountryCode = Mage::helper('enterprise_rma')
  113. ->getReturnAddressModel($storeId)->getCountryId();
  114. if ($shipperAddressCountryCode != $recipientAddressCountryCode) {
  115. return true;
  116. } else {
  117. return false;
  118. }
  119. }
  120. /**
  121. * Return delivery confirmation types of current carrier
  122. *
  123. * @return array
  124. */
  125. public function getDeliveryConfirmationTypes()
  126. {
  127. $storeId = $this->getRma()->getStoreId();
  128. $code = $this->getRequest()->getParam('method');
  129. if (!empty($code)) {
  130. list($carrierCode, $methodCode) = explode('_', $code, 2);
  131. $carrier = Mage::helper('enterprise_rma')->getCarrier($carrierCode, $storeId);
  132. $countryId = Mage::helper('enterprise_rma')->getReturnAddressModel($storeId)->getCountryId();
  133. $params = new Varien_Object(array('country_recipient' => $countryId));
  134. if ($carrier && is_array($carrier->getDeliveryConfirmationTypes($params))) {
  135. return $carrier->getDeliveryConfirmationTypes($params);
  136. }
  137. }
  138. return array();
  139. }
  140. /**
  141. * Check whether girth is allowed for current carrier
  142. *
  143. * @return bool
  144. */
  145. public function isGirthAllowed()
  146. {
  147. $storeId = $this->getRma()->getStoreId();
  148. $code = $this->getRequest()->getParam('method');
  149. $girth = false;
  150. if (!empty($code)) {
  151. list($carrierCode, $methodCode) = explode('_', $code, 2);
  152. $carrier = Mage::helper('enterprise_rma')->getCarrier($carrierCode, $storeId);
  153. $countryId = Mage::helper('enterprise_rma')->getReturnAddressModel($storeId)->getCountryId();
  154. $girth = $carrier->isGirthAllowed($countryId);
  155. }
  156. return $girth;
  157. }
  158. /**
  159. * Return girth status
  160. *
  161. * @return bool
  162. */
  163. public function isGirthEnabled()
  164. {
  165. $code = $this->getRequest()->getParam('method');
  166. $girth = false;
  167. if (!empty($code)) {
  168. $girth = (Mage::helper('usa')->displayGirthValue($code) && $this->isGirthAllowed()) ? 1 : 0;
  169. }
  170. return $girth;
  171. }
  172. /**
  173. * Return content types of package
  174. *
  175. * @return array
  176. */
  177. public function getContentTypes()
  178. {
  179. $storeId = $this->getRma()->getStoreId();
  180. $code = $this->getRequest()->getParam('method');
  181. if (!empty($code)) {
  182. list($carrierCode, $methodCode) = explode('_', $code, 2);
  183. $carrier = Mage::helper('enterprise_rma')->getCarrier($carrierCode, $storeId);
  184. $countryId = Mage::helper('enterprise_rma')->getReturnAddressModel($storeId)->getCountryId();
  185. $order = Mage::getModel('sales/order')->load($this->getRma()->getOrderId());
  186. $shipperAddress = $order->getShippingAddress();
  187. if ($carrier) {
  188. $params = new Varien_Object(array(
  189. 'method' => $methodCode,
  190. 'country_shipper' => $shipperAddress->getCountryId(),
  191. 'country_recipient' => $countryId,
  192. ));
  193. return $carrier->getContentTypes($params);
  194. }
  195. }
  196. return array();
  197. }
  198. /**
  199. * Return customizable containers status
  200. *
  201. * @return bool
  202. */
  203. public function getCustomizableContainersStatus()
  204. {
  205. $storeId = $this->getRma()->getStoreId();
  206. $code = $this->getRequest()->getParam('method');
  207. $carrier = Mage::helper('enterprise_rma')->getCarrier($code, $storeId);
  208. if ($carrier) {
  209. $getCustomizableContainers = $carrier->getCustomizableContainerTypes();
  210. if (in_array(key($this->getContainers()),$getCustomizableContainers)) {
  211. return true;
  212. }
  213. }
  214. return false;
  215. }
  216. /**
  217. * Return shipping carrier usps source sizes
  218. *
  219. * @return array
  220. */
  221. public function getShippingCarrierUspsSourceSize()
  222. {
  223. return Mage::getModel('usa/shipping_carrier_usps_source_size')->toOptionArray();
  224. }
  225. /**
  226. * Check size and girth parameter
  227. *
  228. * @return array
  229. */
  230. public function checkSizeAndGirthParameter()
  231. {
  232. $storeId = $this->getRma()->getStoreId();
  233. $code = $this->getRequest()->getParam('method');
  234. $carrier = Mage::helper('enterprise_rma')->getCarrier($code, $storeId);
  235. $girthEnabled = false;
  236. $sizeEnabled = false;
  237. $regular = $this->getShippingCarrierUspsSourceSize();
  238. if ($carrier && isset($regular[0]['value'])) {
  239. if ($regular[0]['value'] == Mage_Usa_Model_Shipping_Carrier_Usps::SIZE_LARGE
  240. && in_array(
  241. key($this->getContainers()),
  242. array(
  243. Mage_Usa_Model_Shipping_Carrier_Usps::CONTAINER_NONRECTANGULAR,
  244. Mage_Usa_Model_Shipping_Carrier_Usps::CONTAINER_VARIABLE,
  245. )
  246. )
  247. ) {
  248. $girthEnabled = true;
  249. }
  250. if (in_array(
  251. key($this->getContainers()),
  252. array(
  253. Mage_Usa_Model_Shipping_Carrier_Usps::CONTAINER_NONRECTANGULAR,
  254. Mage_Usa_Model_Shipping_Carrier_Usps::CONTAINER_RECTANGULAR,
  255. Mage_Usa_Model_Shipping_Carrier_Usps::CONTAINER_VARIABLE,
  256. )
  257. )) {
  258. $sizeEnabled = true;
  259. }
  260. }
  261. return array($girthEnabled, $sizeEnabled);
  262. }
  263. }