PageRenderTime 99ms CodeModel.GetById 25ms RepoModel.GetById 2ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php

https://github.com/gryzz/crystal_magento
PHP | 206 lines | 91 code | 22 blank | 93 comment | 13 complexity | 2fe579c931d72c5b35c1cd29a64126d1 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_Adminhtml
  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. * Adminhtml sales order item renderer
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. */
  32. class Mage_Adminhtml_Block_Sales_Order_View_Items_Renderer_Default extends Mage_Adminhtml_Block_Sales_Items_Abstract
  33. {
  34. public function getItem()
  35. {
  36. return $this->_getData('item');
  37. }
  38. /**
  39. * Giftmessage object
  40. *
  41. * @var Mage_GiftMessage_Model_Message
  42. */
  43. protected $_giftMessage = array();
  44. /**
  45. * Retrive default value for giftmessage sender
  46. *
  47. * @return string
  48. */
  49. public function getDefaultSender()
  50. {
  51. if(!$this->getItem()) {
  52. return '';
  53. }
  54. if($this->getItem()->getOrder()) {
  55. return $this->getItem()->getOrder()->getBillingAddress()->getName();
  56. }
  57. return $this->getItem()->getBillingAddress()->getName();
  58. }
  59. /**
  60. * Retrive default value for giftmessage recipient
  61. *
  62. * @return string
  63. */
  64. public function getDefaultRecipient()
  65. {
  66. if(!$this->getItem()) {
  67. return '';
  68. }
  69. if($this->getItem()->getOrder()) {
  70. if ($this->getItem()->getOrder()->getShippingAddress()) {
  71. return $this->getItem()->getOrder()->getShippingAddress()->getName();
  72. } else if ($this->getItem()->getOrder()->getBillingAddress()) {
  73. return $this->getItem()->getOrder()->getBillingAddress()->getName();
  74. }
  75. }
  76. if ($this->getItem()->getShippingAddress()) {
  77. return $this->getItem()->getShippingAddress()->getName();
  78. } else if ($this->getItem()->getBillingAddress()) {
  79. return $this->getItem()->getBillingAddress()->getName();
  80. }
  81. return '';
  82. }
  83. /**
  84. * Retrive real name for field
  85. *
  86. * @param string $name
  87. * @return string
  88. */
  89. public function getFieldName($name)
  90. {
  91. return 'giftmessage[' . $this->getItem()->getId() . '][' . $name . ']';
  92. }
  93. /**
  94. * Retrive real html id for field
  95. *
  96. * @param string $name
  97. * @return string
  98. */
  99. public function getFieldId($id)
  100. {
  101. return $this->getFieldIdPrefix() . $id;
  102. }
  103. /**
  104. * Retrive field html id prefix
  105. *
  106. * @return string
  107. */
  108. public function getFieldIdPrefix()
  109. {
  110. return 'giftmessage_item_' . $this->getItem()->getId() . '_';
  111. }
  112. /**
  113. * Initialize gift message for entity
  114. *
  115. * @return Mage_Adminhtml_Block_Sales_Order_Edit_Items_Grid_Renderer_Name_Giftmessage
  116. */
  117. protected function _initMessage()
  118. {
  119. $this->_giftMessage[$this->getItem()->getGiftMessageId()] =
  120. $this->helper('giftmessage/message')->getGiftMessage($this->getItem()->getGiftMessageId());
  121. // init default values for giftmessage form
  122. if(!$this->getMessage()->getSender()) {
  123. $this->getMessage()->setSender($this->getDefaultSender());
  124. }
  125. if(!$this->getMessage()->getRecipient()) {
  126. $this->getMessage()->setRecipient($this->getDefaultRecipient());
  127. }
  128. return $this;
  129. }
  130. /**
  131. * Retrive gift message for entity
  132. *
  133. * @return Mage_GiftMessage_Model_Message
  134. */
  135. public function getMessage()
  136. {
  137. if(!isset($this->_giftMessage[$this->getItem()->getGiftMessageId()])) {
  138. $this->_initMessage();
  139. }
  140. return $this->_giftMessage[$this->getItem()->getGiftMessageId()];
  141. }
  142. /**
  143. * Retrieve save url
  144. *
  145. * @return array
  146. */
  147. public function getSaveUrl()
  148. {
  149. return $this->getUrl('*/sales_order_view_giftmessage/save', array(
  150. 'entity' => $this->getItem()->getId(),
  151. 'type' => 'order_item',
  152. 'reload' => true
  153. ));
  154. }
  155. /**
  156. * Retrive block html id
  157. *
  158. * @return string
  159. */
  160. public function getHtmlId()
  161. {
  162. return substr($this->getFieldIdPrefix(), 0, -1);
  163. }
  164. /**
  165. * Indicate that block can display container
  166. *
  167. * @return boolean
  168. */
  169. public function canDisplayContainer()
  170. {
  171. return $this->getRequest()->getParam('reload')!=1;
  172. }
  173. /**
  174. * Indicates that block can display giftmessages form
  175. *
  176. * @return boolean
  177. */
  178. public function canDisplayGiftmessage()
  179. {
  180. return $this->helper('giftmessage/message')->getIsMessagesAvailable(
  181. 'order_item', $this->getItem(), $this->getItem()->getOrder()->getStoreId()
  182. );
  183. }
  184. }