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_Sales
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: * Order item render block
29: *
30: * @category Mage
31: * @package Mage_Sales
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Sales_Block_Order_Item_Renderer_Default extends Mage_Core_Block_Template
35: {
36: public function setItem(Varien_Object $item)
37: {
38: $this->setData('item', $item);
39: return $this;
40: }
41:
42: public function getItem()
43: {
44: return $this->_getData('item');
45: }
46:
47: /**
48: * Retrieve current order model instance
49: *
50: * @return Mage_Sales_Model_Order
51: */
52: public function getOrder()
53: {
54: return $this->getOrderItem()->getOrder();
55: }
56:
57:
58: public function getOrderItem()
59: {
60: if ($this->getItem() instanceof Mage_Sales_Model_Order_Item) {
61: return $this->getItem();
62: } else {
63: return $this->getItem()->getOrderItem();
64: }
65: }
66:
67: public function getItemOptions()
68: {
69: $result = array();
70: if ($options = $this->getOrderItem()->getProductOptions()) {
71: if (isset($options['options'])) {
72: $result = array_merge($result, $options['options']);
73: }
74: if (isset($options['additional_options'])) {
75: $result = array_merge($result, $options['additional_options']);
76: }
77: if (isset($options['attributes_info'])) {
78: $result = array_merge($result, $options['attributes_info']);
79: }
80: }
81: return $result;
82: }
83:
84: /**
85: * Accept option value and return its formatted view
86: *
87: * @param mixed $optionValue
88: * Method works well with these $optionValue format:
89: * 1. String
90: * 2. Indexed array e.g. array(val1, val2, ...)
91: * 3. Associative array, containing additional option info, including option value, e.g.
92: * array
93: * (
94: * [label] => ...,
95: * [value] => ...,
96: * [print_value] => ...,
97: * [option_id] => ...,
98: * [option_type] => ...,
99: * [custom_view] =>...,
100: * )
101: *
102: * @return array
103: */
104: public function getFormatedOptionValue($optionValue)
105: {
106: $optionInfo = array();
107:
108: // define input data format
109: if (is_array($optionValue)) {
110: if (isset($optionValue['option_id'])) {
111: $optionInfo = $optionValue;
112: if (isset($optionInfo['value'])) {
113: $optionValue = $optionInfo['value'];
114: }
115: } elseif (isset($optionValue['value'])) {
116: $optionValue = $optionValue['value'];
117: }
118: }
119:
120: // render customized option view
121: if (isset($optionInfo['custom_view']) && $optionInfo['custom_view']) {
122: $_default = array('value' => $optionValue);
123: if (isset($optionInfo['option_type'])) {
124: try {
125: $group = Mage::getModel('catalog/product_option')->groupFactory($optionInfo['option_type']);
126: return array('value' => $group->getCustomizedView($optionInfo));
127: } catch (Exception $e) {
128: return $_default;
129: }
130: }
131: return $_default;
132: }
133:
134: // truncate standard view
135: $result = array();
136: if (is_array($optionValue)) {
137: $_truncatedValue = implode("\n", $optionValue);
138: $_truncatedValue = nl2br($_truncatedValue);
139: return array('value' => $_truncatedValue);
140: } else {
141: $_truncatedValue = Mage::helper('core/string')->truncate($optionValue, 55, '');
142: $_truncatedValue = nl2br($_truncatedValue);
143: }
144:
145: $result = array('value' => $_truncatedValue);
146:
147: if (Mage::helper('core/string')->strlen($optionValue) > 55) {
148: $result['value'] = $result['value'] . ' <a href="#" class="dots" onclick="return false">...</a>';
149: $optionValue = nl2br($optionValue);
150: $result = array_merge($result, array('full_view' => $optionValue));
151: }
152:
153: return $result;
154: }
155:
156: /**
157: * Return sku of order item.
158: *
159: * @return string
160: */
161: public function getSku()
162: {
163: /*if ($this->getOrderItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
164: return $this->getOrderItem()->getProductOptionByCode('simple_sku');
165: }*/
166: return $this->getItem()->getSku();
167: }
168:
169: /**
170: * Return product additional information block
171: *
172: * @return Mage_Core_Block_Abstract
173: */
174: public function getProductAdditionalInformationBlock()
175: {
176: return $this->getLayout()->getBlock('additional.product.info');
177: }
178: }
179: