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