Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigurablePanel.php
Go to the documentation of this file.
1 <?php
7 
16 
22 {
23  const GROUP_CONFIGURABLE = 'configurable';
24  const ASSOCIATED_PRODUCT_MODAL = 'configurable_associated_product_modal';
25  const ASSOCIATED_PRODUCT_LISTING = 'configurable_associated_product_listing';
26  const CONFIGURABLE_MATRIX = 'configurable-matrix';
27 
31  private static $groupContent = 'content';
32 
36  private static $sortOrder = 30;
37 
41  private $urlBuilder;
42 
46  private $formName;
47 
51  private $dataScopeName;
52 
56  private $dataSourceName;
57 
61  private $associatedListingPrefix;
62 
66  private $locator;
67 
76  public function __construct(
77  LocatorInterface $locator,
78  UrlInterface $urlBuilder,
79  $formName,
80  $dataScopeName,
81  $dataSourceName,
82  $associatedListingPrefix = ''
83  ) {
84  $this->locator = $locator;
85  $this->urlBuilder = $urlBuilder;
86  $this->formName = $formName;
87  $this->dataScopeName = $dataScopeName;
88  $this->dataSourceName = $dataSourceName;
89  $this->associatedListingPrefix = $associatedListingPrefix;
90  }
91 
95  public function modifyData(array $data)
96  {
97  return $data;
98  }
99 
104  public function modifyMeta(array $meta)
105  {
106  $meta = array_merge_recursive(
107  $meta,
108  [
109  static::GROUP_CONFIGURABLE => [
110  'arguments' => [
111  'data' => [
112  'config' => [
113  'label' => __('Configurations'),
114  'collapsible' => true,
115  'opened' => true,
116  'componentType' => Form\Fieldset::NAME,
117  'sortOrder' => $this->getNextGroupSortOrder(
118  $meta,
119  self::$groupContent,
120  self::$sortOrder
121  ),
122  ],
123  ],
124  ],
125  'children' => $this->getPanelChildren(),
126  ],
127  static::ASSOCIATED_PRODUCT_MODAL => [
128  'arguments' => [
129  'data' => [
130  'config' => [
131  'componentType' => Modal::NAME,
132  'dataScope' => '',
133  'provider' => $this->dataSourceName,
134  'options' => [
135  'title' => __('Select Associated Product'),
136  'buttons' => [
137  [
138  'text' => __('Done'),
139  'class' => 'action-primary',
140  'actions' => [
141  [
142  'targetName' => 'ns= ' . $this->associatedListingPrefix
143  . static::ASSOCIATED_PRODUCT_LISTING
144  . ', index=' . static::ASSOCIATED_PRODUCT_LISTING,
145  'actionName' => 'save'
146  ],
147  'closeModal'
148  ],
149  ],
150  ],
151  ],
152  ],
153  ],
154  ],
155  'children' => [
156  'information-block1' => [
157  'arguments' => [
158  'data' => [
159  'config' => [
160  'componentType' => Container::NAME,
161  'component' => 'Magento_Ui/js/form/components/html',
162  'additionalClasses' => 'message message-notice',
163  'content' => __(
164  'Choose a new product to delete and replace'
165  . ' the current product configuration.'
166  ),
167  'imports' => [
168  'visible' => '!ns = ${ $.ns }, index = '
170  ],
171  ],
172  ],
173  ],
174  ],
175  'information-block2' => [
176  'arguments' => [
177  'data' => [
178  'config' => [
179  'componentType' => Container::NAME,
180  'component' => 'Magento_Ui/js/form/components/html',
181  'additionalClasses' => 'message message-notice',
182  'content' => __(
183  'For better results, add attributes and attribute values to your products.'
184  ),
185  'imports' => [
186  'visible' => 'ns = ${ $.ns }, index = '
188  ],
189  ],
190  ],
191  ],
192  ],
193  static::ASSOCIATED_PRODUCT_LISTING => [
194  'arguments' => [
195  'data' => [
196  'config' => [
197  'autoRender' => false,
198  'componentType' => 'insertListing',
199  'component' => 'Magento_ConfigurableProduct/js'
200  .'/components/associated-product-insert-listing',
201  'dataScope' => $this->associatedListingPrefix
202  . static::ASSOCIATED_PRODUCT_LISTING,
203  'externalProvider' => $this->associatedListingPrefix
204  . static::ASSOCIATED_PRODUCT_LISTING . '.data_source',
205  'selectionsProvider' => $this->associatedListingPrefix
206  . static::ASSOCIATED_PRODUCT_LISTING . '.'
207  . $this->associatedListingPrefix
208  . static::ASSOCIATED_PRODUCT_LISTING . '.product_columns.ids',
209  'ns' => $this->associatedListingPrefix . static::ASSOCIATED_PRODUCT_LISTING,
210  'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
211  'realTimeLink' => true,
212  'behaviourType' => 'simple',
213  'externalFilterMode' => false,
214  'currentProductId' => $this->locator->getProduct()->getId(),
215  'dataLinks' => [
216  'imports' => false,
217  'exports' => true
218  ],
219  'changeProductProvider' => 'change_product',
220  'productsProvider' => $this->associatedListingPrefix
221  . 'configurable_associated_product_listing.data_source',
222  'productsColumns' => $this->associatedListingPrefix
223  . 'configurable_associated_product_listing'
224  . '.' . $this->associatedListingPrefix
225  . 'configurable_associated_product_listing.product_columns',
226  'productsMassAction' => $this->associatedListingPrefix
227  . 'configurable_associated_product_listing'
228  . '.' . $this->associatedListingPrefix
229  . 'configurable_associated_product_listing.product_columns.ids',
230  'modalWithGrid' => 'ns=' . $this->formName . ', index='
231  . static::ASSOCIATED_PRODUCT_MODAL,
232  'productsFilters' => $this->associatedListingPrefix
233  . 'configurable_associated_product_listing'
234  . '.' . $this->associatedListingPrefix
235  . 'configurable_associated_product_listing.listing_top.listing_filters',
236  ],
237  ],
238  ],
239  ],
240  ],
241  ],
242  ]
243  );
244 
245  return $meta;
246  }
247 
253  protected function getPanelChildren()
254  {
255  return [
256  'configurable_products_button_set' => $this->getButtonSet(),
257  'configurable-matrix' => $this->getGrid(),
258  ];
259  }
260 
266  protected function getButtonSet()
267  {
268  return [
269  'arguments' => [
270  'data' => [
271  'config' => [
272  'component' => 'Magento_ConfigurableProduct/js/components/container-configurable-handler',
273  'formElement' => 'container',
274  'componentType' => 'container',
275  'label' => false,
276  'content1' => __(
277  'Configurable products allow customers to choose options '
278  . '(Ex: shirt color). You need to create a simple product for each '
279  . 'configuration (Ex: a product for each color).'
280  ),
281  'content2' => __(
282  'Configurations cannot be created for a standard product with downloadable files. '
283  . 'To create configurations, first remove all downloadable files.'
284  ),
285  'template' => 'ui/form/components/complex',
286  'createConfigurableButton' => 'ns = ${ $.ns }, index = create_configurable_products_button',
287  ],
288  ],
289  ],
290  'children' => [
291  'add_products_manually_button' => [
292  'arguments' => [
293  'data' => [
294  'config' => [
295  'formElement' => 'container',
296  'componentType' => 'container',
297  'component' => 'Magento_Ui/js/form/components/button',
298  'displayAsLink' => true,
299  'actions' => [
300  [
301  'targetName' => 'ns=' . $this->formName . ', index='
302  . static::ASSOCIATED_PRODUCT_MODAL,
303  'actionName' => 'openModal',
304  ],
305  [
306  'targetName' => 'ns=' . $this->associatedListingPrefix
307  . static::ASSOCIATED_PRODUCT_LISTING
308  . ', index=' . static::ASSOCIATED_PRODUCT_LISTING,
309  'actionName' => 'showGridAssignProduct',
310  ],
311  ],
312  'title' => __('Add Products Manually'),
313  'sortOrder' => 10,
314  'imports' => [
315  'visible' => 'ns = ${ $.ns }, index = '
316  . ConfigurablePanel::CONFIGURABLE_MATRIX . ':isShowAddProductButton',
317  ],
318  ],
319  ],
320  ],
321  ],
322  'create_configurable_products_button' => [
323  'arguments' => [
324  'data' => [
325  'config' => [
326  'formElement' => 'container',
327  'componentType' => 'container',
328  'component' => 'Magento_Ui/js/form/components/button',
329  'actions' => [
330  [
331  'targetName' =>
332  $this->dataScopeName . '.configurableModal',
333  'actionName' => 'trigger',
334  'params' => ['active', true],
335  ],
336  [
337  'targetName' =>
338  $this->dataScopeName . '.configurableModal',
339  'actionName' => 'openModal',
340  ],
341  ],
342  'title' => __('Create Configurations'),
343  'sortOrder' => 20,
344  ],
345  ],
346  ],
347  ],
348  ],
349  ];
350  }
351 
357  protected function getGrid()
358  {
359  return [
360  'arguments' => [
361  'data' => [
362  'config' => [
363  'additionalClasses' => 'admin__field-wide',
364  'componentType' => DynamicRows::NAME,
365  'dndConfig' => [
366  'enabled' => false,
367  ],
368  'label' => __('Current Variations'),
369  'renderDefaultRecord' => false,
370  'template' => 'ui/dynamic-rows/templates/grid',
371  'component' => 'Magento_ConfigurableProduct/js/components/dynamic-rows-configurable',
372  'addButton' => false,
373  'isEmpty' => true,
374  'itemTemplate' => 'record',
375  'dataScope' => 'data',
376  'dataProviderFromGrid' => $this->associatedListingPrefix . static::ASSOCIATED_PRODUCT_LISTING,
377  'dataProviderChangeFromGrid' => 'change_product',
378  'dataProviderFromWizard' => 'variations',
379  'map' => [
380  'id' => 'entity_id',
381  'product_link' => 'product_link',
382  'name' => 'name',
383  'sku' => 'sku',
384  'price' => 'price_number',
385  'price_string' => 'price',
386  'price_currency' => 'price_currency',
387  'qty' => 'qty',
388  'weight' => 'weight',
389  'thumbnail_image' => 'thumbnail_src',
390  'status' => 'status',
391  'attributes' => 'attributes',
392  ],
393  'links' => [
394  'insertDataFromGrid' => '${$.provider}:${$.dataProviderFromGrid}',
395  'insertDataFromWizard' => '${$.provider}:${$.dataProviderFromWizard}',
396  'changeDataFromGrid' => '${$.provider}:${$.dataProviderChangeFromGrid}',
397  ],
398  'sortOrder' => 20,
399  'columnsHeader' => false,
400  'columnsHeaderAfterRender' => true,
401  'modalWithGrid' => 'ns=' . $this->formName . ', index='
402  . static::ASSOCIATED_PRODUCT_MODAL,
403  'gridWithProducts' => 'ns=' . $this->associatedListingPrefix
404  . static::ASSOCIATED_PRODUCT_LISTING
405  . ', index=' . static::ASSOCIATED_PRODUCT_LISTING,
406  ],
407  ],
408  ],
409  'children' => $this->getRows(),
410  ];
411  }
412 
419  protected function getRows()
420  {
421  return [
422  'record' => [
423  'arguments' => [
424  'data' => [
425  'config' => [
426  'componentType' => Container::NAME,
427  'isTemplate' => true,
428  'is_collection' => true,
429  'component' => 'Magento_Ui/js/dynamic-rows/record',
430  'dataScope' => '',
431  ],
432  ],
433  ],
434  'children' => [
435  'thumbnail_image_container' => $this->getColumn(
436  'thumbnail_image',
437  __('Image'),
438  [
439  'fit' => true,
440  'formElement' => 'fileUploader',
441  'componentType' => 'fileUploader',
442  'component' => 'Magento_ConfigurableProduct/js/components/file-uploader',
443  'elementTmpl' => 'Magento_ConfigurableProduct/components/file-uploader',
444  'fileInputName' => 'image',
445  'isMultipleFiles' => false,
446  'links' => [
447  'thumbnailUrl' => '${$.provider}:${$.parentScope}.thumbnail_image',
448  'thumbnail' => '${$.provider}:${$.parentScope}.thumbnail',
449  'smallImage' => '${$.provider}:${$.parentScope}.small_image',
450  ],
451  'uploaderConfig' => [
452  'url' => $this->urlBuilder->addSessionParam()->getUrl(
453  'catalog/product_gallery/upload'
454  ),
455  ],
456  'dataScope' => 'image',
457  ],
458  [
459  'elementTmpl' => 'ui/dynamic-rows/cells/thumbnail',
460  'fit' => true,
461  'sortOrder' => 0
462  ]
463  ),
464  'name_container' => $this->getColumn(
465  'name',
466  __('Name'),
467  [],
468  ['dataScope' => 'product_link']
469  ),
470  'sku_container' => $this->getColumn(
471  'sku',
472  __('SKU'),
473  [
474  'validation' =>
475  [
476  'required-entry' => true,
477  'max_text_length' => Sku::SKU_MAX_LENGTH,
478  ],
479  ],
480  [
481  'elementTmpl' => 'Magento_ConfigurableProduct/components/cell-sku',
482  ]
483  ),
484  'price_container' => $this->getColumn(
485  'price',
486  __('Price'),
487  [
488  'imports' => ['addbefore' => '${$.provider}:${$.parentScope}.price_currency'],
489  'validation' => ['validate-zero-or-greater' => true]
490  ],
491  ['dataScope' => 'price_string']
492  ),
493  'quantity_container' => $this->getColumn(
494  'quantity',
495  __('Quantity'),
496  ['dataScope' => 'qty'],
497  ['dataScope' => 'qty']
498  ),
499  'price_weight' => $this->getColumn('weight', __('Weight')),
500  'status' => [
501  'arguments' => [
502  'data' => [
503  'config' => [
504  'componentType' => 'text',
505  'component' => 'Magento_Ui/js/form/element/abstract',
506  'template' => 'Magento_ConfigurableProduct/components/cell-status',
507  'label' => __('Status'),
508  'dataScope' => 'status',
509  ],
510  ],
511  ],
512  ],
513  'attributes' => [
514  'arguments' => [
515  'data' => [
516  'config' => [
517  'componentType' => Form\Field::NAME,
518  'formElement' => Form\Element\Input::NAME,
519  'component' => 'Magento_Ui/js/form/element/text',
520  'elementTmpl' => 'ui/dynamic-rows/cells/text',
521  'dataType' => Form\Element\DataType\Text::NAME,
522  'label' => __('Attributes'),
523  ],
524  ],
525  ],
526  ],
527  'actionsList' => [
528  'arguments' => [
529  'data' => [
530  'config' => [
531  'additionalClasses' => 'data-grid-actions-cell',
532  'componentType' => 'text',
533  'component' => 'Magento_Ui/js/form/element/abstract',
534  'template' => 'Magento_ConfigurableProduct/components/actions-list',
535  'label' => __('Actions'),
536  'fit' => true,
537  'dataScope' => 'status',
538  ],
539  ],
540  ],
541  ],
542  ],
543  ],
544  ];
545  }
546 
556  protected function getColumn(
557  $name,
558  \Magento\Framework\Phrase $label,
559  $editConfig = [],
560  $textConfig = []
561  ) {
562  $fieldEdit['arguments']['data']['config'] = [
563  'dataType' => Form\Element\DataType\Number::NAME,
564  'formElement' => Form\Element\Input::NAME,
565  'componentType' => Form\Field::NAME,
566  'dataScope' => $name,
567  'fit' => true,
568  'visibleIfCanEdit' => true,
569  'imports' => [
570  'visible' => '${$.provider}:${$.parentScope}.canEdit'
571  ],
572  ];
573  $fieldText['arguments']['data']['config'] = [
574  'componentType' => Form\Field::NAME,
575  'formElement' => Form\Element\Input::NAME,
576  'elementTmpl' => 'Magento_ConfigurableProduct/components/cell-html',
577  'dataType' => Form\Element\DataType\Text::NAME,
578  'dataScope' => $name,
579  'visibleIfCanEdit' => false,
580  'imports' => [
581  'visible' => '!${$.provider}:${$.parentScope}.canEdit'
582  ],
583  ];
584  $fieldEdit['arguments']['data']['config'] = array_replace_recursive(
585  $fieldEdit['arguments']['data']['config'],
586  $editConfig
587  );
588  $fieldText['arguments']['data']['config'] = array_replace_recursive(
589  $fieldText['arguments']['data']['config'],
590  $textConfig
591  );
592  $container['arguments']['data']['config'] = [
593  'componentType' => Container::NAME,
594  'formElement' => Container::NAME,
595  'component' => 'Magento_Ui/js/form/components/group',
596  'label' => $label,
597  'dataScope' => '',
598  ];
599  $container['children'] = [
600  $name . '_edit' => $fieldEdit,
601  $name . '_text' => $fieldText,
602  ];
603 
604  return $container;
605  }
606 }
getColumn( $name, \Magento\Framework\Phrase $label, $editConfig=[], $textConfig=[])
__construct(LocatorInterface $locator, UrlInterface $urlBuilder, $formName, $dataScopeName, $dataSourceName, $associatedListingPrefix='')
getNextGroupSortOrder(array $meta, $groupCodes, $defaultSortOrder, $iteration=1)
__()
Definition: __.php:13
$label
Definition: details.phtml:21
if(!isset($_GET['name'])) $name
Definition: log.php:14