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: * Adminhtml customers wishlist grid item renderer for name/options cell
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Customer_Edit_Tab_View_Grid_Renderer_Item extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
35: {
36: /**
37: * Constructor to set default template
38: *
39: * @return Mage_Adminhtml_Block_Customer_Edit_Tab_View_Grid_Renderer_Item
40: */
41: protected function _construct()
42: {
43: parent::_construct();
44: $this->setTemplate('customer/edit/tab/view/grid/item.phtml');
45: return $this;
46: }
47:
48: /**
49: * Returns helper for product type
50: *
51: * @param Mage_Catalog_Model_Product $product
52: * @return Mage_Catalog_Helper_Product_Configuration_Interface
53: */
54: protected function _getProductHelper($product)
55: {
56: // Retrieve whole array of renderers
57: $productHelpers = $this->getProductHelpers();
58: if (!is_array($productHelpers)) {
59: $column = $this->getColumn();
60: if ($column) {
61: $grid = $column->getGrid();
62: if ($grid) {
63: $productHelpers = $grid->getProductConfigurationHelpers();
64: $this->setProductHelpers($productHelpers ? $productHelpers : array());
65: }
66: }
67: }
68:
69: // Check whether we have helper for our product
70: $productType = $product->getTypeId();
71: if (isset($productHelpers[$productType])) {
72: $helperName = $productHelpers[$productType];
73: } else if (isset($productHelpers['default'])) {
74: $helperName = $productHelpers['default'];
75: } else {
76: $helperName = 'catalog/product_configuration';
77: }
78:
79: $helper = Mage::helper($helperName);
80: if (!($helper instanceof Mage_Catalog_Helper_Product_Configuration_Interface)) {
81: Mage::throwException($this->__("Helper for options rendering doesn't implement required interface."));
82: }
83:
84: return $helper;
85: }
86:
87: /*
88: * Returns product associated with this block
89: *
90: * @param Mage_Catalog_Model_Product $product
91: * @return string
92: */
93: public function getProduct()
94: {
95: return $this->getItem()->getProduct();
96: }
97:
98: /**
99: * Returns list of options and their values for product configuration
100: *
101: * @return array
102: */
103: protected function getOptionList()
104: {
105: $item = $this->getItem();
106: $product = $item->getProduct();
107: $helper = $this->_getProductHelper($product);
108: return $helper->getOptions($item);
109: }
110:
111: /**
112: * Returns formatted option value for an item
113: *
114: * @param Mage_Wishlist_Item_Option
115: * @return array
116: */
117: protected function getFormattedOptionValue($option)
118: {
119: $params = array(
120: 'max_length' => 55
121: );
122: return Mage::helper('catalog/product_configuration')->getFormattedOptionValue($option, $params);
123: }
124:
125: /*
126: * Renders item product name and its configuration
127: *
128: * @param Mage_Catalog_Model_Product_Configuration_Item_Interface $item
129: * @return string
130: */
131: public function render(Varien_Object $item)
132: {
133: $this->setItem($item);
134: return $this->toHtml();
135: }
136: }
137: