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_GiftMessage
23: * @copyright Copyright (c) 2012 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: /**
28: * Gift message adminhtml sales order view items
29: *
30: * @category Mage
31: * @package Mage_GiftMessage
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_GiftMessage_Block_Adminhtml_Sales_Order_View_Items extends Mage_Adminhtml_Block_Template
35: {
36: /**
37: * Gift message array
38: *
39: * @var array
40: */
41: protected $_giftMessage = array();
42:
43: /**
44: * Get Order Item
45: *
46: * @return Mage_Sales_Model_Order_Item
47: */
48: public function getItem()
49: {
50: return $this->getParentBlock()->getItem();
51: }
52:
53: /**
54: * Retrive default value for giftmessage sender
55: *
56: * @return string
57: */
58: public function getDefaultSender()
59: {
60: if(!$this->getItem()) {
61: return '';
62: }
63:
64: if($this->getItem()->getOrder()) {
65: return $this->getItem()->getOrder()->getBillingAddress()->getName();
66: }
67:
68: return $this->getItem()->getBillingAddress()->getName();
69: }
70:
71: /**
72: * Retrive default value for giftmessage recipient
73: *
74: * @return string
75: */
76: public function getDefaultRecipient()
77: {
78: if(!$this->getItem()) {
79: return '';
80: }
81:
82: if($this->getItem()->getOrder()) {
83: if ($this->getItem()->getOrder()->getShippingAddress()) {
84: return $this->getItem()->getOrder()->getShippingAddress()->getName();
85: } else if ($this->getItem()->getOrder()->getBillingAddress()) {
86: return $this->getItem()->getOrder()->getBillingAddress()->getName();
87: }
88: }
89:
90: if ($this->getItem()->getShippingAddress()) {
91: return $this->getItem()->getShippingAddress()->getName();
92: } else if ($this->getItem()->getBillingAddress()) {
93: return $this->getItem()->getBillingAddress()->getName();
94: }
95:
96: return '';
97: }
98:
99: /**
100: * Retrive real name for field
101: *
102: * @param string $name
103: * @return string
104: */
105: public function getFieldName($name)
106: {
107: return 'giftmessage[' . $this->getItem()->getId() . '][' . $name . ']';
108: }
109:
110: /**
111: * Retrive real html id for field
112: *
113: * @param string $name
114: * @return string
115: */
116: public function getFieldId($id)
117: {
118: return $this->getFieldIdPrefix() . $id;
119: }
120:
121: /**
122: * Retrive field html id prefix
123: *
124: * @return string
125: */
126: public function getFieldIdPrefix()
127: {
128: return 'giftmessage_' . $this->getItem()->getId() . '_';
129: }
130:
131: /**
132: * Initialize gift message for entity
133: *
134: * @return Mage_Adminhtml_Block_Sales_Order_Edit_Items_Grid_Renderer_Name_Giftmessage
135: */
136: protected function _initMessage()
137: {
138: $this->_giftMessage[$this->getItem()->getGiftMessageId()] =
139: $this->helper('giftmessage/message')->getGiftMessage($this->getItem()->getGiftMessageId());
140:
141: // init default values for giftmessage form
142: if(!$this->getMessage()->getSender()) {
143: $this->getMessage()->setSender($this->getDefaultSender());
144: }
145: if(!$this->getMessage()->getRecipient()) {
146: $this->getMessage()->setRecipient($this->getDefaultRecipient());
147: }
148:
149: return $this;
150: }
151:
152: /**
153: * Retrive gift message for entity
154: *
155: * @return Mage_GiftMessage_Model_Message
156: */
157: public function getMessage()
158: {
159: if(!isset($this->_giftMessage[$this->getItem()->getGiftMessageId()])) {
160: $this->_initMessage();
161: }
162:
163: return $this->_giftMessage[$this->getItem()->getGiftMessageId()];
164: }
165:
166: /**
167: * Retrieve save url
168: *
169: * @return array
170: */
171: public function getSaveUrl()
172: {
173: return $this->getUrl('*/sales_order_view_giftmessage/save', array(
174: 'entity' => $this->getItem()->getId(),
175: 'type' => 'order_item',
176: 'reload' => true
177: ));
178: }
179:
180: /**
181: * Retrive block html id
182: *
183: * @return string
184: */
185: public function getHtmlId()
186: {
187: return substr($this->getFieldIdPrefix(), 0, -1);
188: }
189:
190: /**
191: * Indicates that block can display giftmessages form
192: *
193: * @return boolean
194: */
195: public function canDisplayGiftmessage()
196: {
197: return $this->getItem()->getGiftMessageId();
198: }
199:
200: /**
201: * Retrieve gift message sender
202: *
203: * @return string
204: */
205: public function getSender()
206: {
207: return $this->htmlEscape($this->getMessage()->getSender());
208: }
209:
210: /**
211: * Retrieve gift message recipient
212: *
213: * @return string
214: */
215: public function getRecipient()
216: {
217: return $this->htmlEscape($this->getMessage()->getRecipient());
218: }
219:
220: /**
221: * Retrieve gift message text
222: *
223: * @return string
224: */
225: public function getMessageText()
226: {
227: return $this->htmlEscape($this->getMessage()->getMessage());
228: }
229: }
230: