Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
option.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
10 ?>
11 <script id="bundle-option-template" type="text/x-magento-template">
12  <div id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_<%- data.index %>" class="option-box">
13  <div class="fieldset-wrapper admin__collapsible-block-wrapper opened" id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_<%- data.index %>-wrapper">
14  <div class="fieldset-wrapper-title">
15  <strong class="admin__collapsible-title" data-toggle="collapse" data-target="#<?= /* @escapeNotVerified */ $block->getFieldId() ?>_<%- data.index %>-content">
16  <span><%- data.default_title %></span>
17  </strong>
18  <div class="actions">
19  <?= $block->getOptionDeleteButtonHtml() ?>
20  </div>
21  <div data-role="draggable-handle" class="draggable-handle"></div>
22  </div>
23  <div class="fieldset-wrapper-content in collapse" id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_<%- data.index %>-content">
24  <fieldset class="fieldset">
25  <fieldset class="fieldset-alt">
26  <div class="field field-option-title required">
27  <label class="label" for="id_<?= /* @escapeNotVerified */ $block->getFieldName() ?>_<%- data.index %>_title">
28  <?= /* @escapeNotVerified */ __('Option Title') ?>
29  </label>
30  <div class="control">
31  <?php if ($block->isDefaultStore()): ?>
32  <input class="input-text required-entry"
33  type="text"
34  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.index %>][title]"
35  id="id_<?= /* @escapeNotVerified */ $block->getFieldName() ?>_<%- data.index %>_title"
36  value="<%- data.title %>"
37  data-original-value="<%- data.title %>" />
38  <?php else: ?>
39  <input class="input-text required-entry"
40  type="text"
41  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.index %>][default_title]"
42  id="id_<?= /* @escapeNotVerified */ $block->getFieldName() ?>_<%- data.index %>_default_title"
43  value="<%- data.default_title %>"
44  data-original-value="<%- data.default_title %>" />
45  <?php endif; ?>
46  <input type="hidden"
47  id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_id_<%- data.index %>"
48  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.index %>][option_id]"
49  value="<%- data.option_id %>" />
50  <input type="hidden"
51  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.index %>][delete]"
52  value=""
53  data-state="deleted" />
54  </div>
55  </div>
56  <?php if (!$block->isDefaultStore()): ?>
57  <div class="field field-option-store-view required">
58  <label class="label" for="id_<?= /* @escapeNotVerified */ $block->getFieldName() ?>_<%- data.index %>_title_store">
59  <?= /* @escapeNotVerified */ __('Store View Title') ?>
60  </label>
61  <div class="control">
62  <input class="input-text required-entry" type="text"
63  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.index %>][title]"
64  id="id_<?= /* @escapeNotVerified */ $block->getFieldName() ?>_<%- data.index %>_title_store"
65  value="<%- data.title %>" />
66  </div>
67  </div>
68  <?php endif; ?>
69  <div class="field field-option-input-type required">
70  <label class="label" for="<?= /* @escapeNotVerified */ $block->getFieldId() . '_<%- data.index %>_type' ?>">
71  <?= /* @escapeNotVerified */ __('Input Type') ?>
72  </label>
73  <div class="control">
74  <?= $block->getTypeSelectHtml() ?>
75  </div>
76  </div>
77  <div class="field field-option-req">
78  <div class="control">
79  <input type="checkbox"
80  class="is-required"
81  checked="checked"
82  id="field-option-req" />
83  <label for="field-option-req">
84  <?= /* @escapeNotVerified */ __('Required') ?>
85  </label>
86  <span style="display:none"><?= $block->getRequireSelectHtml() ?></span>
87  </div>
88  </div>
89  <div class="field field-option-position no-display">
90  <label class="label" for="field-option-position">
91  <?= /* @escapeNotVerified */ __('Position') ?>
92  </label>
93  <div class="control">
94  <input class="input-text validate-zero-or-greater"
95  type="text"
96  name="<?= /* @escapeNotVerified */ $block->getFieldName() ?>[<%- data.index %>][position]"
97  value="<%- data.position %>"
98  id="field-option-position" />
99  </div>
100  </div>
101  </fieldset>
102 
103  <div class="no-products-message">
104  <?= /* @escapeNotVerified */ __('There are no products in this option.') ?>
105  </div>
106  <?= $block->getAddSelectionButtonHtml() ?>
107  </fieldset>
108  </div>
109  </div>
110  <div id="<?= /* @escapeNotVerified */ $block->getFieldId() ?>_search_<%- data.index %>" class="selection-search"></div>
111  </div>
112 </script>
113 
114 <?= $block->getSelectionHtml() ?>
115 
116 <script>
117 require([
118  'jquery',
119  'mage/template',
120  'jquery/jquery.tabs',
121  'collapsable',
122  'Magento_Bundle/js/bundle-product',
123  'prototype',
124  'mage/adminhtml/form'
125 ], function(jQuery, mageTemplate){
126 
127  var optionTemplate = jQuery('#bundle-option-template').html();
128 
129 function changeInputType(oldObject, oType) {
130  var newObject = document.createElement('input');
131  newObject.type = oType;
132  if(oldObject.size) newObject.size = oldObject.size;
133  if(oldObject.value) newObject.value = oldObject.value;
134  if(oldObject.name) newObject.name = oldObject.name;
135  if(oldObject.id) newObject.id = oldObject.id;
136  if(oldObject.onclick) newObject.onclick = oldObject.onclick;
137  if(oldObject.className) newObject.className = oldObject.className;
138  oldObject.parentNode.replaceChild(newObject,oldObject);
139  return newObject;
140 }
141 
142 Bundle.Option = Class.create();
143 Bundle.Option.prototype = {
144  idLabel : '<?= /* @escapeNotVerified */ $block->getFieldId() ?>',
145  templateText : '',
146  itemsCount : 0,
147  initialize : function(template) {
148  this.templateText = template;
149  },
150 
151  add : function(data) {
152  if (!data) {
153  data = <?= /* @escapeNotVerified */ $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode(['default_title' => __('New Option')]) ?>;
154  } else {
155  data.title = data.title.replace(/</g, "&lt;");
156  data.title = data.title.replace(/"/g, "&quot;");
157  data.default_title = data.title;
158  }
159  data.index = this.itemsCount++;
160 
161  this.template = mageTemplate(this.templateText);
162 
163  jQuery('#product_bundle_container')
164  .append(this.template({
165  data: data
166  }));
167 
168  jQuery('.collapse', jQuery('#product_bundle_container')).collapsable();
169 
170  //set selected type
171  if (data.type) {
172  $A($(this.idLabel + '_'+data.index+'_type').options).each(function(option){
173  if (option.value==data.type) option.selected = true;
174  });
175  }
176 
177  //set selected is_require
178  if (data.required) {
179  $A($(this.idLabel + '_'+data.index+'_required').options).each(function(option){
180  if (option.value==data.required) option.selected = true;
181  });
182  }
183  // rebind change notifications
184  varienWindowOnload(true);
185 
186  if (jQuery && jQuery('#bundle_product_container').data('bundleProduct')) {
187  jQuery('#bundle_product_container').bundleProduct('refreshSortableElements');
188  }
189 
190  return data.index;
191  },
192 
193  remove : function(event){
194  var element = Event.findElement(event, 'div').up('.option-box');
195  if (element) {
196  var idInput = Element.select(element, '[name$="[option_id]"]')[0];
197  if (idInput.value == '') {
198  element.remove();
199  } else {
200  Element.select(element, '[data-state="deleted"]').each(function (elem) {
201  elem.value = '1';
202  });
203 
204  Element.select(element, ['input', 'select']).each(function (elem) {
205  elem.hide();
206  elem.className = '';
207  });
208 
209  Element.hide(element);
210  }
211  }
212  },
213 
214  changeType : function(event) {
215  var element = Event.element(event);
216  parts = element.id.split('_');
217  i = parts[2];
218  if (element.value == 'multi' || element.value == 'checkbox') {
219  inputs = $A($$('#' + bSelection.idLabel + '_box_' + i + ' tr.selection input.default'));
220  inputs.each(
221  function(elem){
222  //elem.type = "checkbox";
223  changeInputType(elem, 'checkbox');
224  }
225  );
229  inputs = $A($$('#' + bSelection.idLabel + '_box_' + i + ' .qty-box'));
230  inputs.each(
231  function(elem){
232  elem.hide();
233  }
234  );
235 
236  } else {
237  inputs = $A($$('#' + bSelection.idLabel + '_box_' + i + ' tr.selection input.default'));
238  have = false;
239  for (j=0; j< inputs.length; j++) {
240  //inputs[j].type = "radio";
241  changeInputType(inputs[j], 'radio');
242  if (inputs[j].checked && have) {
243  inputs[j].checked = false;
244  } else {
245  have = true;
246  }
247  }
248 
252  inputs = $A($$('#' + bSelection.idLabel + '_box_' + i + ' .qty-box'));
253  inputs.each(
254  function(elem){
255  elem.show();
256  }
257  );
258  }
259  },
260 
261  priceTypeFixed : function() {
262  inputs = $A($$('.price-type-box'));
263  inputs.each(
264  function(elem){
265  elem.show();
266  }
267  );
268  },
269 
270  priceTypeDynamic : function() {
271  inputs = $A($$('.price-type-box'));
272  inputs.each(
273  function(elem){
274  elem.hide();
275  }
276  );
277  }
278 };
279 
280 var optionIndex = 0;
281 bOption = new Bundle.Option(optionTemplate);
282 <?php
283  foreach ($block->getOptions() as $_option) {
285  /* @escapeNotVerified */ echo 'optionIndex = bOption.add(', $_option->toJson(), ');', PHP_EOL;
286  if ($_option->getSelections()) {
287  foreach ($_option->getSelections() as $_selection) {
289  $_selection->setName($block->escapeHtml($_selection->getName()));
290  /* @escapeNotVerified */ echo 'bSelection.addRow(optionIndex,', $_selection->toJson(), ');', PHP_EOL;
291  }
292  }
293  }
294 ?>
295 function togglePriceType() {
296  bOption['priceType' + ($('price_type').value == '1' ? 'Fixed' : 'Dynamic')]();
297 }
298 
299 jQuery('#bundle_product_container').bundleProduct();
300 jQuery('#product_bundle_container .collapse').collapse('hide');
301 
302 jQuery(window).on('load', function() {
303  togglePriceType();
304  Event.observe('price_type', 'change', togglePriceType);
305 });
306 
307 });
308 </script>
309 <script type="text/x-magento-init">
310  {
311  "*": {
312  "Magento_Bundle/js/bundle-type-handler": {}
313  }
314  }
315 </script>
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
__()
Definition: __.php:13
$block
Definition: block.php:8
if( $block->isDefaultStore())() ?>[<%- data.index %>][title]" id endif
Definition: option.phtml:42
jquery extjs ext tree checkbox
Definition: tree.phtml:41
jQuery('.store-switcher .dropdown-menu li a').each(function()
Definition: switcher.phtml:203