Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomOptions.php
Go to the documentation of this file.
1 <?php
7 
26 
36 {
40  const GROUP_CUSTOM_OPTIONS_NAME = 'custom_options';
41  const GROUP_CUSTOM_OPTIONS_SCOPE = 'data.product';
42  const GROUP_CUSTOM_OPTIONS_PREVIOUS_NAME = 'search-engine-optimization';
49  const BUTTON_ADD = 'button_add';
50  const BUTTON_IMPORT = 'button_import';
56  const CONTAINER_HEADER_NAME = 'container_header';
57  const CONTAINER_OPTION = 'container_option';
58  const CONTAINER_COMMON_NAME = 'container_common';
59  const CONTAINER_TYPE_STATIC_NAME = 'container_type_static';
65  const GRID_OPTIONS_NAME = 'options';
66  const GRID_TYPE_SELECT_NAME = 'values';
72  const FIELD_ENABLE = 'affect_product_custom_options';
73  const FIELD_OPTION_ID = 'option_id';
74  const FIELD_TITLE_NAME = 'title';
75  const FIELD_STORE_TITLE_NAME = 'store_title';
76  const FIELD_TYPE_NAME = 'type';
77  const FIELD_IS_REQUIRE_NAME = 'is_require';
78  const FIELD_SORT_ORDER_NAME = 'sort_order';
79  const FIELD_PRICE_NAME = 'price';
80  const FIELD_PRICE_TYPE_NAME = 'price_type';
81  const FIELD_SKU_NAME = 'sku';
82  const FIELD_MAX_CHARACTERS_NAME = 'max_characters';
83  const FIELD_FILE_EXTENSION_NAME = 'file_extension';
84  const FIELD_IMAGE_SIZE_X_NAME = 'image_size_x';
85  const FIELD_IMAGE_SIZE_Y_NAME = 'image_size_y';
86  const FIELD_IS_DELETE = 'is_delete';
87  const FIELD_IS_USE_DEFAULT = 'is_use_default';
93  const IMPORT_OPTIONS_MODAL = 'import_options_modal';
94  const CUSTOM_OPTIONS_LISTING = 'product_custom_options_listing';
101  protected $locator;
102 
107  protected $storeManager;
108 
114 
120 
125  protected $urlBuilder;
126 
131  protected $arrayManager;
132 
137  protected $meta = [];
138 
142  private $localeCurrency;
143 
152  public function __construct(
156  ProductOptionsPrice $productOptionsPrice,
159  ) {
160  $this->locator = $locator;
161  $this->storeManager = $storeManager;
162  $this->productOptionsConfig = $productOptionsConfig;
163  $this->productOptionsPrice = $productOptionsPrice;
164  $this->urlBuilder = $urlBuilder;
165  $this->arrayManager = $arrayManager;
166  }
167 
172  public function modifyData(array $data)
173  {
174  $options = [];
175  $productOptions = $this->locator->getProduct()->getOptions() ?: [];
176 
178  foreach ($productOptions as $index => $option) {
179  $optionData = $option->getData();
180  $optionData[static::FIELD_IS_USE_DEFAULT] = !$option->getData(static::FIELD_STORE_TITLE_NAME);
181  $options[$index] = $this->formatPriceByPath(static::FIELD_PRICE_NAME, $optionData);
182  $values = $option->getValues() ?: [];
183 
184  foreach ($values as $value) {
185  $value->setData(static::FIELD_IS_USE_DEFAULT, !$value->getData(static::FIELD_STORE_TITLE_NAME));
186  }
188  foreach ($values as $value) {
189  $options[$index][static::GRID_TYPE_SELECT_NAME][] = $this->formatPriceByPath(
190  static::FIELD_PRICE_NAME,
191  $value->getData()
192  );
193  }
194  }
195 
196  return array_replace_recursive(
197  $data,
198  [
199  $this->locator->getProduct()->getId() => [
200  static::DATA_SOURCE_DEFAULT => [
201  static::FIELD_ENABLE => 1,
202  static::GRID_OPTIONS_NAME => $options
203  ]
204  ]
205  ]
206  );
207  }
208 
217  protected function formatPriceByPath($path, array $data)
218  {
219  $value = $this->arrayManager->get($path, $data);
220 
221  if (is_numeric($value)) {
222  $data = $this->arrayManager->replace($path, $data, $this->formatPrice($value));
223  }
224 
225  return $data;
226  }
227 
232  public function modifyMeta(array $meta)
233  {
234  $this->meta = $meta;
235 
236  $this->createCustomOptionsPanel();
237 
238  return $this->meta;
239  }
240 
247  protected function createCustomOptionsPanel()
248  {
249  $this->meta = array_replace_recursive(
250  $this->meta,
251  [
252  static::GROUP_CUSTOM_OPTIONS_NAME => [
253  'arguments' => [
254  'data' => [
255  'config' => [
256  'label' => __('Customizable Options'),
257  'componentType' => Fieldset::NAME,
258  'dataScope' => static::GROUP_CUSTOM_OPTIONS_SCOPE,
259  'collapsible' => true,
260  'sortOrder' => $this->getNextGroupSortOrder(
261  $this->meta,
262  static::GROUP_CUSTOM_OPTIONS_PREVIOUS_NAME,
263  static::GROUP_CUSTOM_OPTIONS_DEFAULT_SORT_ORDER
264  ),
265  ],
266  ],
267  ],
268  'children' => [
269  static::CONTAINER_HEADER_NAME => $this->getHeaderContainerConfig(10),
270  static::FIELD_ENABLE => $this->getEnableFieldConfig(20),
271  static::GRID_OPTIONS_NAME => $this->getOptionsGridConfig(30)
272  ]
273  ]
274  ]
275  );
276 
277  $this->meta = array_merge_recursive(
278  $this->meta,
279  [
280  static::IMPORT_OPTIONS_MODAL => $this->getImportOptionsModalConfig()
281  ]
282  );
283 
284  return $this;
285  }
286 
294  protected function getHeaderContainerConfig($sortOrder)
295  {
296  return [
297  'arguments' => [
298  'data' => [
299  'config' => [
300  'label' => null,
301  'formElement' => Container::NAME,
302  'componentType' => Container::NAME,
303  'template' => 'ui/form/components/complex',
304  'sortOrder' => $sortOrder,
305  'content' => __('Custom options let customers choose the product variations they want.'),
306  ],
307  ],
308  ],
309  'children' => [
310  static::BUTTON_IMPORT => [
311  'arguments' => [
312  'data' => [
313  'config' => [
314  'title' => __('Import Options'),
315  'formElement' => Container::NAME,
316  'componentType' => Container::NAME,
317  'component' => 'Magento_Ui/js/form/components/button',
318  'actions' => [
319  [
320  'targetName' => 'ns=' . static::FORM_NAME . ', index=options',
321  'actionName' => 'clearDataProvider'
322  ],
323  [
324  'targetName' => 'ns=' . static::FORM_NAME . ', index='
325  . static::IMPORT_OPTIONS_MODAL,
326  'actionName' => 'openModal',
327  ],
328  [
329  'targetName' => 'ns=' . static::CUSTOM_OPTIONS_LISTING
330  . ', index=' . static::CUSTOM_OPTIONS_LISTING,
331  'actionName' => 'render',
332  ],
333  ],
334  'displayAsLink' => true,
335  'sortOrder' => 10,
336  ],
337  ],
338  ],
339  ],
340  static::BUTTON_ADD => [
341  'arguments' => [
342  'data' => [
343  'config' => [
344  'title' => __('Add Option'),
345  'formElement' => Container::NAME,
346  'componentType' => Container::NAME,
347  'component' => 'Magento_Ui/js/form/components/button',
348  'sortOrder' => 20,
349  'actions' => [
350  [
351  'targetName' => '${ $.ns }.${ $.ns }.' . static::GROUP_CUSTOM_OPTIONS_NAME
352  . '.' . static::GRID_OPTIONS_NAME,
353  'actionName' => 'processingAddChild',
354  ]
355  ]
356  ]
357  ],
358  ],
359  ],
360  ],
361  ];
362  }
363 
371  protected function getOptionsGridConfig($sortOrder)
372  {
373  return [
374  'arguments' => [
375  'data' => [
376  'config' => [
377  'addButtonLabel' => __('Add Option'),
378  'componentType' => DynamicRows::NAME,
379  'component' => 'Magento_Catalog/js/components/dynamic-rows-import-custom-options',
380  'template' => 'ui/dynamic-rows/templates/collapsible',
381  'additionalClasses' => 'admin__field-wide',
382  'deleteProperty' => static::FIELD_IS_DELETE,
383  'deleteValue' => '1',
384  'addButton' => false,
385  'renderDefaultRecord' => false,
386  'columnsHeader' => false,
387  'collapsibleHeader' => true,
388  'sortOrder' => $sortOrder,
389  'dataProvider' => static::CUSTOM_OPTIONS_LISTING,
390  'imports' => ['insertData' => '${ $.provider }:${ $.dataProvider }'],
391  ],
392  ],
393  ],
394  'children' => [
395  'record' => [
396  'arguments' => [
397  'data' => [
398  'config' => [
399  'headerLabel' => __('New Option'),
400  'componentType' => Container::NAME,
401  'component' => 'Magento_Ui/js/dynamic-rows/record',
402  'positionProvider' => static::CONTAINER_OPTION . '.' . static::FIELD_SORT_ORDER_NAME,
403  'isTemplate' => true,
404  'is_collection' => true,
405  ],
406  ],
407  ],
408  'children' => [
409  static::CONTAINER_OPTION => [
410  'arguments' => [
411  'data' => [
412  'config' => [
413  'componentType' => Fieldset::NAME,
414  'collapsible' => true,
415  'label' => null,
416  'sortOrder' => 10,
417  'opened' => true,
418  ],
419  ],
420  ],
421  'children' => [
422  static::FIELD_SORT_ORDER_NAME => $this->getPositionFieldConfig(40),
423  static::CONTAINER_COMMON_NAME => $this->getCommonContainerConfig(10),
424  static::CONTAINER_TYPE_STATIC_NAME => $this->getStaticTypeContainerConfig(20),
425  static::GRID_TYPE_SELECT_NAME => $this->getSelectTypeGridConfig(30)
426  ]
427  ],
428  ]
429  ]
430  ]
431  ];
432  }
433 
441  protected function getEnableFieldConfig($sortOrder)
442  {
443  return [
444  'arguments' => [
445  'data' => [
446  'config' => [
447  'formElement' => Field::NAME,
448  'componentType' => Input::NAME,
449  'dataScope' => static::FIELD_ENABLE,
450  'dataType' => Number::NAME,
451  'visible' => false,
452  'sortOrder' => $sortOrder,
453  ],
454  ],
455  ],
456  ];
457  }
458 
465  protected function getImportOptionsModalConfig()
466  {
467  return [
468  'arguments' => [
469  'data' => [
470  'config' => [
471  'componentType' => Modal::NAME,
472  'dataScope' => '',
473  'provider' => static::FORM_NAME . '.product_form_data_source',
474  'options' => [
475  'title' => __('Select Product'),
476  'buttons' => [
477  [
478  'text' => __('Import'),
479  'class' => 'action-primary',
480  'actions' => [
481  [
482  'targetName' => 'index = ' . static::CUSTOM_OPTIONS_LISTING,
483  'actionName' => 'save'
484  ],
485  'closeModal'
486  ],
487  ],
488  ],
489  ],
490  ],
491  ],
492  ],
493  'children' => [
494  static::CUSTOM_OPTIONS_LISTING => [
495  'arguments' => [
496  'data' => [
497  'config' => [
498  'autoRender' => false,
499  'componentType' => 'insertListing',
500  'dataScope' => static::CUSTOM_OPTIONS_LISTING,
501  'externalProvider' => static::CUSTOM_OPTIONS_LISTING . '.'
502  . static::CUSTOM_OPTIONS_LISTING . '_data_source',
503  'selectionsProvider' => static::CUSTOM_OPTIONS_LISTING . '.'
504  . static::CUSTOM_OPTIONS_LISTING . '.product_columns.ids',
505  'ns' => static::CUSTOM_OPTIONS_LISTING,
506  'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
507  'realTimeLink' => true,
508  'externalFilterMode' => false,
509  'currentProductId' => $this->locator->getProduct()->getId(),
510  'dataLinks' => [
511  'imports' => false,
512  'exports' => true
513  ],
514  'exports' => [
515  'currentProductId' => '${ $.externalProvider }:params.current_product_id'
516  ]
517  ],
518  ],
519  ],
520  ],
521  ],
522  ];
523  }
524 
532  protected function getCommonContainerConfig($sortOrder)
533  {
534  $commonContainer = [
535  'arguments' => [
536  'data' => [
537  'config' => [
538  'componentType' => Container::NAME,
539  'formElement' => Container::NAME,
540  'component' => 'Magento_Ui/js/form/components/group',
541  'breakLine' => false,
542  'showLabel' => false,
543  'additionalClasses' => 'admin__field-group-columns admin__control-group-equal',
544  'sortOrder' => $sortOrder,
545  ],
546  ],
547  ],
548  'children' => [
549  static::FIELD_OPTION_ID => $this->getOptionIdFieldConfig(10),
550  static::FIELD_TITLE_NAME => $this->getTitleFieldConfig(
551  20,
552  [
553  'arguments' => [
554  'data' => [
555  'config' => [
556  'label' => __('Option Title'),
557  'component' => 'Magento_Catalog/component/static-type-input',
558  'valueUpdate' => 'input',
559  'imports' => [
560  'optionId' => '${ $.provider }:${ $.parentScope }.option_id',
561  'isUseDefault' => '${ $.provider }:${ $.parentScope }.is_use_default'
562  ]
563  ],
564  ],
565  ],
566  ]
567  ),
568  static::FIELD_TYPE_NAME => $this->getTypeFieldConfig(30),
569  static::FIELD_IS_REQUIRE_NAME => $this->getIsRequireFieldConfig(40)
570  ]
571  ];
572 
573  if ($this->locator->getProduct()->getStoreId()) {
574  $useDefaultConfig = [
575  'service' => [
576  'template' => 'Magento_Catalog/form/element/helper/custom-option-service',
577  ]
578  ];
579  $titlePath = $this->arrayManager->findPath(static::FIELD_TITLE_NAME, $commonContainer, null)
580  . static::META_CONFIG_PATH;
581  $commonContainer = $this->arrayManager->merge($titlePath, $commonContainer, $useDefaultConfig);
582  }
583 
584  return $commonContainer;
585  }
586 
594  protected function getStaticTypeContainerConfig($sortOrder)
595  {
596  return [
597  'arguments' => [
598  'data' => [
599  'config' => [
600  'componentType' => Container::NAME,
601  'formElement' => Container::NAME,
602  'component' => 'Magento_Ui/js/form/components/group',
603  'breakLine' => false,
604  'showLabel' => false,
605  'additionalClasses' => 'admin__field-group-columns admin__control-group-equal',
606  'sortOrder' => $sortOrder,
607  'fieldTemplate' => 'Magento_Catalog/form/field',
608  'visible' => false,
609  ],
610  ],
611  ],
612  'children' => [
613  static::FIELD_PRICE_NAME => $this->getPriceFieldConfig(10),
614  static::FIELD_PRICE_TYPE_NAME => $this->getPriceTypeFieldConfig(20),
615  static::FIELD_SKU_NAME => $this->getSkuFieldConfig(30),
616  static::FIELD_MAX_CHARACTERS_NAME => $this->getMaxCharactersFieldConfig(40),
617  static::FIELD_FILE_EXTENSION_NAME => $this->getFileExtensionFieldConfig(50),
618  static::FIELD_IMAGE_SIZE_X_NAME => $this->getImageSizeXFieldConfig(60),
619  static::FIELD_IMAGE_SIZE_Y_NAME => $this->getImageSizeYFieldConfig(70)
620  ]
621  ];
622  }
623 
631  protected function getSelectTypeGridConfig($sortOrder)
632  {
633  $options = [
634  'arguments' => [
635  'data' => [
636  'config' => [
637  'imports' => [
638  'optionId' => '${ $.provider }:${ $.parentScope }.option_id',
639  'optionTypeId' => '${ $.provider }:${ $.parentScope }.option_type_id',
640  'isUseDefault' => '${ $.provider }:${ $.parentScope }.is_use_default'
641  ],
642  'service' => [
643  'template' => 'Magento_Catalog/form/element/helper/custom-option-type-service',
644  ],
645  ],
646  ],
647  ],
648  ];
649 
650  return [
651  'arguments' => [
652  'data' => [
653  'config' => [
654  'addButtonLabel' => __('Add Value'),
655  'componentType' => DynamicRows::NAME,
656  'component' => 'Magento_Ui/js/dynamic-rows/dynamic-rows',
657  'additionalClasses' => 'admin__field-wide',
658  'deleteProperty' => static::FIELD_IS_DELETE,
659  'deleteValue' => '1',
660  'renderDefaultRecord' => false,
661  'sortOrder' => $sortOrder,
662  ],
663  ],
664  ],
665  'children' => [
666  'record' => [
667  'arguments' => [
668  'data' => [
669  'config' => [
670  'componentType' => Container::NAME,
671  'component' => 'Magento_Ui/js/dynamic-rows/record',
672  'positionProvider' => static::FIELD_SORT_ORDER_NAME,
673  'isTemplate' => true,
674  'is_collection' => true,
675  ],
676  ],
677  ],
678  'children' => [
679  static::FIELD_TITLE_NAME => $this->getTitleFieldConfig(
680  10,
681  $this->locator->getProduct()->getStoreId() ? $options : []
682  ),
683  static::FIELD_PRICE_NAME => $this->getPriceFieldConfigForSelectType(20),
684  static::FIELD_PRICE_TYPE_NAME => $this->getPriceTypeFieldConfig(30, ['fit' => true]),
685  static::FIELD_SKU_NAME => $this->getSkuFieldConfig(40),
686  static::FIELD_SORT_ORDER_NAME => $this->getPositionFieldConfig(50),
687  static::FIELD_IS_DELETE => $this->getIsDeleteFieldConfig(60)
688  ]
689  ]
690  ]
691  ];
692  }
693 
701  protected function getOptionIdFieldConfig($sortOrder)
702  {
703  return [
704  'arguments' => [
705  'data' => [
706  'config' => [
707  'formElement' => Input::NAME,
708  'componentType' => Field::NAME,
709  'dataScope' => static::FIELD_OPTION_ID,
710  'sortOrder' => $sortOrder,
711  'visible' => false,
712  ],
713  ],
714  ],
715  ];
716  }
717 
726  protected function getTitleFieldConfig($sortOrder, array $options = [])
727  {
728  return array_replace_recursive(
729  [
730  'arguments' => [
731  'data' => [
732  'config' => [
733  'label' => __('Title'),
734  'componentType' => Field::NAME,
735  'formElement' => Input::NAME,
736  'dataScope' => static::FIELD_TITLE_NAME,
737  'dataType' => Text::NAME,
738  'sortOrder' => $sortOrder,
739  'validation' => [
740  'required-entry' => true
741  ],
742  ],
743  ],
744  ],
745  ],
746  $options
747  );
748  }
749 
757  protected function getTypeFieldConfig($sortOrder)
758  {
759  return [
760  'arguments' => [
761  'data' => [
762  'config' => [
763  'label' => __('Option Type'),
764  'componentType' => Field::NAME,
765  'formElement' => Select::NAME,
766  'component' => 'Magento_Catalog/js/custom-options-type',
767  'elementTmpl' => 'ui/grid/filters/elements/ui-select',
768  'selectType' => 'optgroup',
769  'dataScope' => static::FIELD_TYPE_NAME,
770  'dataType' => Text::NAME,
771  'sortOrder' => $sortOrder,
772  'options' => $this->getProductOptionTypes(),
773  'disableLabel' => true,
774  'multiple' => false,
775  'selectedPlaceholders' => [
776  'defaultPlaceholder' => __('-- Please select --'),
777  ],
778  'validation' => [
779  'required-entry' => true
780  ],
781  'groupsConfig' => [
782  'text' => [
783  'values' => ['field', 'area'],
784  'indexes' => [
785  static::CONTAINER_TYPE_STATIC_NAME,
786  static::FIELD_PRICE_NAME,
787  static::FIELD_PRICE_TYPE_NAME,
788  static::FIELD_SKU_NAME,
789  static::FIELD_MAX_CHARACTERS_NAME
790  ]
791  ],
792  'file' => [
793  'values' => ['file'],
794  'indexes' => [
795  static::CONTAINER_TYPE_STATIC_NAME,
796  static::FIELD_PRICE_NAME,
797  static::FIELD_PRICE_TYPE_NAME,
798  static::FIELD_SKU_NAME,
799  static::FIELD_FILE_EXTENSION_NAME,
800  static::FIELD_IMAGE_SIZE_X_NAME,
801  static::FIELD_IMAGE_SIZE_Y_NAME
802  ]
803  ],
804  'select' => [
805  'values' => ['drop_down', 'radio', 'checkbox', 'multiple'],
806  'indexes' => [
807  static::GRID_TYPE_SELECT_NAME
808  ]
809  ],
810  'data' => [
811  'values' => ['date', 'date_time', 'time'],
812  'indexes' => [
813  static::CONTAINER_TYPE_STATIC_NAME,
814  static::FIELD_PRICE_NAME,
815  static::FIELD_PRICE_TYPE_NAME,
816  static::FIELD_SKU_NAME
817  ]
818  ]
819  ],
820  ],
821  ],
822  ],
823  ];
824  }
825 
833  protected function getIsRequireFieldConfig($sortOrder)
834  {
835  return [
836  'arguments' => [
837  'data' => [
838  'config' => [
839  'label' => __('Required'),
840  'componentType' => Field::NAME,
841  'formElement' => Checkbox::NAME,
842  'dataScope' => static::FIELD_IS_REQUIRE_NAME,
843  'dataType' => Text::NAME,
844  'sortOrder' => $sortOrder,
845  'value' => '1',
846  'valueMap' => [
847  'true' => '1',
848  'false' => '0'
849  ],
850  ],
851  ],
852  ],
853  ];
854  }
855 
863  protected function getPositionFieldConfig($sortOrder)
864  {
865  return [
866  'arguments' => [
867  'data' => [
868  'config' => [
869  'componentType' => Field::NAME,
870  'formElement' => Input::NAME,
871  'dataScope' => static::FIELD_SORT_ORDER_NAME,
872  'dataType' => Number::NAME,
873  'visible' => false,
874  'sortOrder' => $sortOrder,
875  ],
876  ],
877  ],
878  ];
879  }
880 
888  protected function getIsDeleteFieldConfig($sortOrder)
889  {
890  return [
891  'arguments' => [
892  'data' => [
893  'config' => [
894  'componentType' => ActionDelete::NAME,
895  'fit' => true,
896  'sortOrder' => $sortOrder
897  ],
898  ],
899  ],
900  ];
901  }
902 
910  protected function getPriceFieldConfig($sortOrder)
911  {
912  return [
913  'arguments' => [
914  'data' => [
915  'config' => [
916  'label' => __('Price'),
917  'componentType' => Field::NAME,
918  'component' => 'Magento_Catalog/js/components/custom-options-component',
919  'formElement' => Input::NAME,
920  'dataScope' => static::FIELD_PRICE_NAME,
921  'dataType' => Number::NAME,
922  'addbefore' => $this->getCurrencySymbol(),
923  'addbeforePool' => $this->productOptionsPrice->prefixesToOptionArray(),
924  'sortOrder' => $sortOrder,
925  'validation' => [
926  'validate-number' => true
927  ],
928  ],
929  ],
930  ],
931  ];
932  }
933 
940  private function getPriceFieldConfigForSelectType(int $sortOrder)
941  {
942  $priceFieldConfig = $this->getPriceFieldConfig($sortOrder);
943  $priceFieldConfig['arguments']['data']['config']['template'] = 'Magento_Catalog/form/field';
944 
945  return $priceFieldConfig;
946  }
947 
956  protected function getPriceTypeFieldConfig($sortOrder, array $config = [])
957  {
958  return array_replace_recursive(
959  [
960  'arguments' => [
961  'data' => [
962  'config' => [
963  'label' => __('Price Type'),
964  'component' => 'Magento_Catalog/js/components/custom-options-price-type',
965  'componentType' => Field::NAME,
966  'formElement' => Select::NAME,
967  'dataScope' => static::FIELD_PRICE_TYPE_NAME,
968  'dataType' => Text::NAME,
969  'sortOrder' => $sortOrder,
970  'options' => $this->productOptionsPrice->toOptionArray(),
971  'imports' => [
972  'priceIndex' => self::FIELD_PRICE_NAME,
973  ],
974  ],
975  ],
976  ],
977  ],
978  $config
979  );
980  }
981 
989  protected function getSkuFieldConfig($sortOrder)
990  {
991  return [
992  'arguments' => [
993  'data' => [
994  'config' => [
995  'label' => __('SKU'),
996  'componentType' => Field::NAME,
997  'formElement' => Input::NAME,
998  'dataScope' => static::FIELD_SKU_NAME,
999  'dataType' => Text::NAME,
1000  'sortOrder' => $sortOrder,
1001  ],
1002  ],
1003  ],
1004  ];
1005  }
1006 
1014  protected function getMaxCharactersFieldConfig($sortOrder)
1015  {
1016  return [
1017  'arguments' => [
1018  'data' => [
1019  'config' => [
1020  'label' => __('Max Characters'),
1021  'componentType' => Field::NAME,
1022  'formElement' => Input::NAME,
1023  'dataScope' => static::FIELD_MAX_CHARACTERS_NAME,
1024  'dataType' => Number::NAME,
1025  'sortOrder' => $sortOrder,
1026  'validation' => [
1027  'validate-zero-or-greater' => true
1028  ],
1029  ],
1030  ],
1031  ],
1032  ];
1033  }
1034 
1042  protected function getFileExtensionFieldConfig($sortOrder)
1043  {
1044  return [
1045  'arguments' => [
1046  'data' => [
1047  'config' => [
1048  'label' => __('Compatible File Extensions'),
1049  'notice' => __('Enter separated extensions, like: png, jpg, gif.'),
1050  'componentType' => Field::NAME,
1051  'formElement' => Input::NAME,
1052  'dataScope' => static::FIELD_FILE_EXTENSION_NAME,
1053  'dataType' => Text::NAME,
1054  'sortOrder' => $sortOrder,
1055  'validation' => [
1056  'required-entry' => true,
1057  ],
1058  ],
1059  ],
1060  ],
1061  ];
1062  }
1063 
1071  protected function getImageSizeXFieldConfig($sortOrder)
1072  {
1073  return [
1074  'arguments' => [
1075  'data' => [
1076  'config' => [
1077  'label' => __('Maximum Image Size'),
1078  'notice' => __('Please leave blank if it is not an image.'),
1079  'addafter' => __('px.'),
1080  'component' => 'Magento_Catalog/js/components/custom-options-component',
1081  'componentType' => Field::NAME,
1082  'formElement' => Input::NAME,
1083  'dataScope' => static::FIELD_IMAGE_SIZE_X_NAME,
1084  'dataType' => Number::NAME,
1085  'sortOrder' => $sortOrder,
1086  'validation' => [
1087  'validate-zero-or-greater' => true
1088  ],
1089  ],
1090  ],
1091  ],
1092  ];
1093  }
1094 
1102  protected function getImageSizeYFieldConfig($sortOrder)
1103  {
1104  return [
1105  'arguments' => [
1106  'data' => [
1107  'config' => [
1108  'label' => ' ',
1109  'addafter' => __('px.'),
1110  'component' => 'Magento_Catalog/js/components/custom-options-component',
1111  'componentType' => Field::NAME,
1112  'formElement' => Input::NAME,
1113  'dataScope' => static::FIELD_IMAGE_SIZE_Y_NAME,
1114  'dataType' => Number::NAME,
1115  'sortOrder' => $sortOrder,
1116  'validation' => [
1117  'validate-zero-or-greater' => true
1118  ],
1119  ],
1120  ],
1121  ],
1122  ];
1123  }
1124 
1131  protected function getProductOptionTypes()
1132  {
1133  $options = [];
1134  $groupIndex = 0;
1135 
1136  foreach ($this->productOptionsConfig->getAll() as $option) {
1137  $group = [
1138  'value' => $groupIndex,
1139  //TODO: Wrap label with __() or remove this TODO after MAGETWO-49771 is closed
1140  'label' => $option['label'],
1141  'optgroup' => []
1142  ];
1143 
1144  foreach ($option['types'] as $type) {
1145  if ($type['disabled']) {
1146  continue;
1147  }
1148 
1149  //TODO: Wrap label with __() or remove this TODO after MAGETWO-49771 is closed
1150  $group['optgroup'][] = ['label' => $type['label'], 'value' => $type['name']];
1151  }
1152 
1153  if (count($group['optgroup'])) {
1154  $options[] = $group;
1155  $groupIndex += 1;
1156  }
1157  }
1158 
1159  return $options;
1160  }
1161 
1168  protected function getCurrencySymbol()
1169  {
1170  return $this->storeManager->getStore()->getBaseCurrency()->getCurrencySymbol();
1171  }
1172 
1180  private function getLocaleCurrency()
1181  {
1182  if ($this->localeCurrency === null) {
1183  $this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
1184  }
1185  return $this->localeCurrency;
1186  }
1187 
1195  protected function formatPrice($value)
1196  {
1197  if (!is_numeric($value)) {
1198  return null;
1199  }
1200 
1201  $store = $this->storeManager->getStore();
1202  $currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
1203  $value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
1204 
1205  return $value;
1206  }
1207 }
$optionData
$config
Definition: fraud_order.php:17
getNextGroupSortOrder(array $meta, $groupCodes, $defaultSortOrder, $iteration=1)
$group
Definition: sections.phtml:16
$values
Definition: options.phtml:88
__()
Definition: __.php:13
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
__construct(LocatorInterface $locator, StoreManagerInterface $storeManager, ConfigInterface $productOptionsConfig, ProductOptionsPrice $productOptionsPrice, UrlInterface $urlBuilder, ArrayManager $arrayManager)
$index
Definition: list.phtml:44