1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option extends Mage_Adminhtml_Block_Widget
35: {
36: 37: 38: 39: 40:
41: protected $_element = null;
42:
43: 44: 45: 46: 47: 48:
49: protected $_customerGroups = null;
50:
51: 52: 53: 54: 55: 56:
57: protected $_websites = null;
58:
59: 60: 61: 62: 63:
64: protected $_options = null;
65:
66: 67: 68: 69: 70:
71: public function __construct()
72: {
73: $this->setTemplate('bundle/product/edit/bundle/option.phtml');
74: $this->setCanReadPrice(true);
75: $this->setCanEditPrice(true);
76: }
77:
78: public function getFieldId()
79: {
80: return 'bundle_option';
81: }
82:
83: public function getFieldName()
84: {
85: return 'bundle_options';
86: }
87:
88: 89: 90: 91: 92:
93: public function getProduct()
94: {
95: if (!$this->getData('product')) {
96: $this->setData('product', Mage::registry('product'));
97: }
98: return $this->getData('product');
99: }
100:
101: public function render(Varien_Data_Form_Element_Abstract $element)
102: {
103: $this->setElement($element);
104: return $this->toHtml();
105: }
106:
107: public function setElement(Varien_Data_Form_Element_Abstract $element)
108: {
109: $this->_element = $element;
110: return $this;
111: }
112:
113: public function getElement()
114: {
115: return $this->_element;
116: }
117:
118: public function isMultiWebsites()
119: {
120: return !Mage::app()->isSingleStoreMode();
121: }
122:
123: protected function _prepareLayout()
124: {
125: $this->setChild('add_selection_button',
126: $this->getLayout()->createBlock('adminhtml/widget_button')
127: ->setData(array(
128: 'id' => $this->getFieldId().'_{{index}}_add_button',
129: 'label' => Mage::helper('bundle')->__('Add Selection'),
130: 'on_click' => 'bSelection.showSearch(event)',
131: 'class' => 'add'
132: )));
133:
134: $this->setChild('close_search_button',
135: $this->getLayout()->createBlock('adminhtml/widget_button')
136: ->setData(array(
137: 'id' => $this->getFieldId().'_{{index}}_close_button',
138: 'label' => Mage::helper('bundle')->__('Close'),
139: 'on_click' => 'bSelection.closeSearch(event)',
140: 'class' => 'back no-display'
141: )));
142:
143: $this->setChild('option_delete_button',
144: $this->getLayout()->createBlock('adminhtml/widget_button')
145: ->setData(array(
146: 'label' => Mage::helper('catalog')->__('Delete Option'),
147: 'class' => 'delete delete-product-option',
148: 'on_click' => 'bOption.remove(event)'
149: ))
150: );
151:
152: $this->setChild('selection_template',
153: $this->getLayout()->createBlock('bundle/adminhtml_catalog_product_edit_tab_bundle_option_selection')
154: );
155:
156: return parent::_prepareLayout();
157: }
158:
159: public function getAddButtonHtml()
160: {
161: return $this->getChildHtml('add_button');
162: }
163:
164: public function getCloseSearchButtonHtml()
165: {
166: return $this->getChildHtml('close_search_button');
167: }
168:
169: public function getAddSelectionButtonHtml()
170: {
171: return $this->getChildHtml('add_selection_button');
172: }
173:
174: 175: 176: 177: 178:
179: public function getOptions()
180: {
181: if (!$this->_options) {
182: $this->getProduct()->getTypeInstance(true)->setStoreFilter($this->getProduct()->getStoreId(),
183: $this->getProduct());
184:
185: $optionCollection = $this->getProduct()->getTypeInstance(true)->getOptionsCollection($this->getProduct());
186:
187: $selectionCollection = $this->getProduct()->getTypeInstance(true)->getSelectionsCollection(
188: $this->getProduct()->getTypeInstance(true)->getOptionsIds($this->getProduct()),
189: $this->getProduct()
190: );
191:
192: $this->_options = $optionCollection->appendSelections($selectionCollection);
193: if ($this->getCanReadPrice() === false) {
194: foreach ($this->_options as $option) {
195: if ($option->getSelections()) {
196: foreach ($option->getSelections() as $selection) {
197: $selection->setCanReadPrice($this->getCanReadPrice());
198: $selection->setCanEditPrice($this->getCanEditPrice());
199: }
200: }
201: }
202: }
203: }
204: return $this->_options;
205: }
206:
207: public function getAddButtonId()
208: {
209: $buttonId = $this->getLayout()
210: ->getBlock('admin.product.bundle.items')
211: ->getChild('add_button')->getId();
212: return $buttonId;
213: }
214:
215: public function getOptionDeleteButtonHtml()
216: {
217: return $this->getChildHtml('option_delete_button');
218: }
219:
220: public function getSelectionHtml()
221: {
222: return $this->getChildHtml('selection_template');
223: }
224:
225: public function getTypeSelectHtml()
226: {
227: $select = $this->getLayout()->createBlock('adminhtml/html_select')
228: ->setData(array(
229: 'id' => $this->getFieldId().'_{{index}}_type',
230: 'class' => 'select select-product-option-type required-option-select',
231: 'extra_params' => 'onchange="bOption.changeType(event)"'
232: ))
233: ->setName($this->getFieldName().'[{{index}}][type]')
234: ->setOptions(Mage::getSingleton('bundle/source_option_type')->toOptionArray());
235:
236: return $select->getHtml();
237: }
238:
239: public function getRequireSelectHtml()
240: {
241: $select = $this->getLayout()->createBlock('adminhtml/html_select')
242: ->setData(array(
243: 'id' => $this->getFieldId().'_{{index}}_required',
244: 'class' => 'select'
245: ))
246: ->setName($this->getFieldName().'[{{index}}][required]')
247: ->setOptions(Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray());
248:
249: return $select->getHtml();
250: }
251:
252: public function isDefaultStore()
253: {
254: return ($this->getProduct()->getStoreId() == '0');
255: }
256: }
257: