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_Bundle
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: * Bundle selection renderer
29: *
30: * @category Mage
31: * @package Mage_Bundle
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option_Selection extends Mage_Adminhtml_Block_Widget
35: {
36: /**
37: * Initialize bundle option selection block
38: */
39: public function __construct()
40: {
41: $this->setTemplate('bundle/product/edit/bundle/option/selection.phtml');
42: $this->setCanReadPrice(true);
43: $this->setCanEditPrice(true);
44: }
45:
46: /**
47: * Return field id
48: *
49: * @return string
50: */
51: public function getFieldId()
52: {
53: return 'bundle_selection';
54: }
55:
56: /**
57: * Return field name
58: *
59: * @return string
60: */
61: public function getFieldName()
62: {
63: return 'bundle_selections';
64: }
65:
66: /**
67: * Prepare block layout
68: *
69: * @return Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option_Selection
70: */
71: protected function _prepareLayout()
72: {
73: $this->setChild('selection_delete_button',
74: $this->getLayout()->createBlock('adminhtml/widget_button')
75: ->setData(array(
76: 'label' => Mage::helper('catalog')->__('Delete'),
77: 'class' => 'delete icon-btn',
78: 'on_click' => 'bSelection.remove(event)'
79: ))
80: );
81: return parent::_prepareLayout();
82: }
83:
84: /**
85: * Retrieve delete button html
86: *
87: * @return string
88: */
89: public function getSelectionDeleteButtonHtml()
90: {
91: return $this->getChildHtml('selection_delete_button');
92: }
93:
94: /**
95: * Retrieve price type select html
96: *
97: * @return string
98: */
99: public function getPriceTypeSelectHtml()
100: {
101: $select = $this->getLayout()->createBlock('adminhtml/html_select')
102: ->setData(array(
103: 'id' => $this->getFieldId() . '_{{index}}_price_type',
104: 'class' => 'select select-product-option-type required-option-select'
105: ))
106: ->setName($this->getFieldName() . '[{{parentIndex}}][{{index}}][selection_price_type]')
107: ->setOptions(Mage::getSingleton('bundle/source_option_selection_price_type')->toOptionArray());
108: if ($this->getCanEditPrice() === false) {
109: $select->setExtraParams('disabled="disabled"');
110: }
111: return $select->getHtml();
112: }
113:
114: /**
115: * Retrieve qty type select html
116: *
117: * @return string
118: */
119: public function getQtyTypeSelectHtml()
120: {
121: $select = $this->getLayout()->createBlock('adminhtml/html_select')
122: ->setData(array(
123: 'id' => $this->getFieldId().'_{{index}}_can_change_qty',
124: 'class' => 'select'
125: ))
126: ->setName($this->getFieldName().'[{{parentIndex}}][{{index}}][selection_can_change_qty]')
127: ->setOptions(Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray());
128:
129: return $select->getHtml();
130: }
131:
132: /**
133: * Return search url
134: *
135: * @return string
136: */
137: public function getSelectionSearchUrl()
138: {
139: return $this->getUrl('*/bundle_selection/search');
140: }
141:
142: /**
143: * Check if used website scope price
144: *
145: * @return string
146: */
147: public function isUsedWebsitePrice()
148: {
149: return !Mage::helper('catalog')->isPriceGlobal() && Mage::registry('product')->getStoreId();
150: }
151:
152: /**
153: * Retrieve price scope checkbox html
154: *
155: * @return string
156: */
157: public function getCheckboxScopeHtml()
158: {
159: $checkboxHtml = '';
160: if ($this->isUsedWebsitePrice()) {
161: $id = $this->getFieldId() . '_{{index}}_price_scope';
162: $name = $this->getFieldName() . '[{{parentIndex}}][{{index}}][default_price_scope]';
163: $class = 'bundle-option-price-scope-checkbox';
164: $label = Mage::helper('bundle')->__('Use Default Value');
165: $disabled = ($this->getCanEditPrice() === false) ? ' disabled="disabled"' : '';
166: $checkboxHtml = '<input type="checkbox" id="' . $id . '" class="' . $class . '" name="' . $name
167: . '"' . $disabled . ' value="1" />';
168: $checkboxHtml .= '<label class="normal" for="' . $id . '">' . $label . '</label>';
169: }
170: return $checkboxHtml;
171: }
172: }
173: