Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CategorySetup.php
Go to the documentation of this file.
1 <?php
9 
13 use Magento\Catalog\Block\Adminhtml\Product\Helper\Form\BaseImage;
24 use Magento\Catalog\Model\CategoryFactory;
26 use Magento\Catalog\Model\Product\Attribute\Backend\Category as CategoryBackendAttribute;
42 use Magento\CatalogInventory\Model\Source\Stock as StockSourceModel;
48 use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory;
55 
59 class CategorySetup extends EavSetup
60 {
66  private $categoryFactory;
67 
72 
77 
87  public function __construct(
89  Context $context,
90  CacheInterface $cache,
91  CollectionFactory $attrGroupCollectionFactory,
92  CategoryFactory $categoryFactory
93  ) {
94  $this->categoryFactory = $categoryFactory;
95  parent::__construct($setup, $context, $cache, $attrGroupCollectionFactory);
96  }
97 
105  public function createCategory($data = [])
106  {
107  return $this->categoryFactory->create($data);
108  }
109 
116  public function getDefaultEntities()
117  {
118  return [
119  'catalog_category' => [
120  'entity_type_id' => self::CATEGORY_ENTITY_TYPE_ID,
121  'entity_model' => Category::class,
122  'attribute_model' => Attribute::class,
123  'table' => 'catalog_category_entity',
124  'additional_attribute_table' => 'catalog_eav_attribute',
125  'entity_attribute_collection' =>
126  Collection::class,
127  'attributes' => [
128  'name' => [
129  'type' => 'varchar',
130  'label' => 'Name',
131  'input' => 'text',
132  'sort_order' => 1,
134  'group' => 'General Information',
135  ],
136  'is_active' => [
137  'type' => 'int',
138  'label' => 'Is Active',
139  'input' => 'select',
140  'source' => Boolean::class,
141  'sort_order' => 2,
143  'group' => 'General Information',
144  ],
145  'description' => [
146  'type' => 'text',
147  'label' => 'Description',
148  'input' => 'textarea',
149  'required' => false,
150  'sort_order' => 4,
152  'wysiwyg_enabled' => true,
153  'is_html_allowed_on_front' => true,
154  'group' => 'General Information',
155  ],
156  'image' => [
157  'type' => 'varchar',
158  'label' => 'Image',
159  'input' => 'image',
160  'backend' => Image::class,
161  'required' => false,
162  'sort_order' => 5,
164  'group' => 'General Information',
165  ],
166  'meta_title' => [
167  'type' => 'varchar',
168  'label' => 'Page Title',
169  'input' => 'text',
170  'required' => false,
171  'sort_order' => 6,
173  'group' => 'General Information',
174  ],
175  'meta_keywords' => [
176  'type' => 'text',
177  'label' => 'Meta Keywords',
178  'input' => 'textarea',
179  'required' => false,
180  'sort_order' => 7,
182  'group' => 'General Information',
183  ],
184  'meta_description' => [
185  'type' => 'text',
186  'label' => 'Meta Description',
187  'input' => 'textarea',
188  'required' => false,
189  'sort_order' => 8,
191  'group' => 'General Information',
192  ],
193  'display_mode' => [
194  'type' => 'varchar',
195  'label' => 'Display Mode',
196  'input' => 'select',
197  'source' => Mode::class,
198  'required' => false,
199  'sort_order' => 10,
201  'group' => 'Display Settings',
202  ],
203  'landing_page' => [
204  'type' => 'int',
205  'label' => 'CMS Block',
206  'input' => 'select',
207  'source' => Page::class,
208  'required' => false,
209  'sort_order' => 20,
211  'group' => 'Display Settings',
212  ],
213  'is_anchor' => [
214  'type' => 'int',
215  'label' => 'Is Anchor',
216  'input' => 'select',
217  'source' => Boolean::class,
218  'required' => false,
219  'sort_order' => 30,
220  'group' => 'Display Settings',
221  ],
222  'path' => [
223  'type' => 'static',
224  'label' => 'Path',
225  'required' => false,
226  'sort_order' => 12,
227  'visible' => false,
228  'group' => 'General Information',
229  ],
230  'position' => [
231  'type' => 'static',
232  'label' => 'Position',
233  'required' => false,
234  'sort_order' => 13,
235  'visible' => false,
236  'group' => 'General Information',
237  ],
238  'all_children' => [
239  'type' => 'text',
240  'required' => false,
241  'sort_order' => 14,
242  'visible' => false,
243  'group' => 'General Information',
244  ],
245  'path_in_store' => [
246  'type' => 'text',
247  'required' => false,
248  'sort_order' => 15,
249  'visible' => false,
250  'group' => 'General Information',
251  ],
252  'children' => [
253  'type' => 'text',
254  'required' => false,
255  'sort_order' => 16,
256  'visible' => false,
257  'group' => 'General Information',
258  ],
259  'custom_design' => [
260  'type' => 'varchar',
261  'label' => 'Custom Design',
262  'input' => 'select',
263  'source' => Theme::class,
264  'required' => false,
265  'sort_order' => 10,
267  'group' => 'Custom Design',
268  ],
269  'custom_design_from' => [
270  'type' => 'datetime',
271  'label' => 'Active From',
272  'input' => 'date',
273  'backend' => Startdate::class,
274  'required' => false,
275  'sort_order' => 30,
277  'group' => 'Custom Design',
278  ],
279  'custom_design_to' => [
280  'type' => 'datetime',
281  'label' => 'Active To',
282  'input' => 'date',
283  'backend' => Datetime::class,
284  'required' => false,
285  'sort_order' => 40,
287  'group' => 'Custom Design',
288  ],
289  'page_layout' => [
290  'type' => 'varchar',
291  'label' => 'Page Layout',
292  'input' => 'select',
293  'source' => Layout::class,
294  'required' => false,
295  'sort_order' => 50,
297  'group' => 'Custom Design',
298  ],
299  'custom_layout_update' => [
300  'type' => 'text',
301  'label' => 'Custom Layout Update',
302  'input' => 'textarea',
303  'backend' => Customlayoutupdate::class,
304  'required' => false,
305  'sort_order' => 60,
307  'group' => 'Custom Design',
308  ],
309  'level' => [
310  'type' => 'static',
311  'label' => 'Level',
312  'required' => false,
313  'sort_order' => 24,
314  'visible' => false,
315  'group' => 'General Information',
316  ],
317  'children_count' => [
318  'type' => 'static',
319  'label' => 'Children Count',
320  'required' => false,
321  'sort_order' => 25,
322  'visible' => false,
323  'group' => 'General Information',
324  ],
325  'available_sort_by' => [
326  'type' => 'text',
327  'label' => 'Available Product Listing Sort By',
328  'input' => 'multiselect',
329  'source' => Sortby::class,
330  'backend' => SortbyBackendModel::class,
331  'sort_order' => 40,
332  'input_renderer' => Available::class,
334  'group' => 'Display Settings',
335  ],
336  'default_sort_by' => [
337  'type' => 'varchar',
338  'label' => 'Default Product Listing Sort By',
339  'input' => 'select',
340  'source' => Sortby::class,
341  'backend' => SortbyBackendModel::class,
342  'sort_order' => 50,
343  'input_renderer' =>
344  DefaultSortby::class,
346  'group' => 'Display Settings',
347  ],
348  'include_in_menu' => [
349  'type' => 'int',
350  'label' => 'Include in Navigation Menu',
351  'input' => 'select',
352  'source' => Boolean::class,
353  'default' => '1',
354  'sort_order' => 10,
356  'group' => 'General Information',
357  ],
358  'custom_use_parent_settings' => [
359  'type' => 'int',
360  'label' => 'Use Parent Category Settings',
361  'input' => 'select',
362  'source' => Boolean::class,
363  'required' => false,
364  'sort_order' => 5,
366  'group' => 'Custom Design',
367  ],
368  'custom_apply_to_products' => [
369  'type' => 'int',
370  'label' => 'Apply To Products',
371  'input' => 'select',
372  'source' => Boolean::class,
373  'required' => false,
374  'sort_order' => 6,
376  'group' => 'Custom Design',
377  ],
378  'filter_price_range' => [
379  'type' => 'decimal',
380  'label' => 'Layered Navigation Price Step',
381  'input' => 'text',
382  'required' => false,
383  'sort_order' => 51,
384  'input_renderer' => Pricestep::class,
386  'group' => 'Display Settings',
387  ],
388  ],
389  ],
390  'catalog_product' => [
391  'entity_type_id' => self::CATALOG_PRODUCT_ENTITY_TYPE_ID,
392  'entity_model' => Product::class,
393  'attribute_model' => Attribute::class,
394  'table' => 'catalog_product_entity',
395  'additional_attribute_table' => 'catalog_eav_attribute',
396  'entity_attribute_collection' =>
397  Product\Attribute\Collection::class,
398  'attributes' => [
399  'name' => [
400  'type' => 'varchar',
401  'label' => 'Name',
402  'input' => 'text',
403  'frontend_class' => 'validate-length maximum-length-255',
404  'sort_order' => 1,
406  'searchable' => true,
407  'visible_in_advanced_search' => true,
408  'used_in_product_listing' => true,
409  'used_for_sort_by' => true,
410  ],
411  'sku' => [
412  'type' => 'static',
413  'label' => 'SKU',
414  'input' => 'text',
415  'frontend_class' => 'validate-length maximum-length-64',
416  'backend' => Sku::class,
417  'unique' => true,
418  'sort_order' => 2,
419  'searchable' => true,
420  'comparable' => true,
421  'visible_in_advanced_search' => true,
422  ],
423  'description' => [
424  'type' => 'text',
425  'label' => 'Description',
426  'input' => 'textarea',
427  'sort_order' => 3,
429  'searchable' => true,
430  'comparable' => true,
431  'wysiwyg_enabled' => true,
432  'is_html_allowed_on_front' => true,
433  'visible_in_advanced_search' => true,
434  ],
435  'short_description' => [
436  'type' => 'text',
437  'label' => 'Short Description',
438  'input' => 'textarea',
439  'sort_order' => 4,
441  'searchable' => true,
442  'comparable' => true,
443  'wysiwyg_enabled' => true,
444  'is_html_allowed_on_front' => true,
445  'visible_in_advanced_search' => true,
446  'used_in_product_listing' => true,
447  'is_used_in_grid' => true,
448  'is_visible_in_grid' => false,
449  'is_filterable_in_grid' => false,
450  ],
451  'price' => [
452  'type' => 'decimal',
453  'label' => 'Price',
454  'input' => 'price',
455  'backend' => Price::class,
456  'sort_order' => 1,
458  'searchable' => true,
459  'filterable' => true,
460  'visible_in_advanced_search' => true,
461  'used_in_product_listing' => true,
462  'used_for_sort_by' => true,
463  'apply_to' => 'simple,virtual',
464  'group' => 'Prices',
465  ],
466  'special_price' => [
467  'type' => 'decimal',
468  'label' => 'Special Price',
469  'input' => 'price',
470  'backend' => Price::class,
471  'required' => false,
472  'sort_order' => 3,
474  'used_in_product_listing' => true,
475  'apply_to' => 'simple,virtual',
476  'group' => 'Prices',
477  'is_used_in_grid' => true,
478  'is_visible_in_grid' => false,
479  'is_filterable_in_grid' => true,
480  ],
481  'special_from_date' => [
482  'type' => 'datetime',
483  'label' => 'Special Price From Date',
484  'input' => 'date',
485  'backend' => Startdate::class,
486  'required' => false,
487  'sort_order' => 4,
489  'used_in_product_listing' => true,
490  'apply_to' => 'simple,virtual',
491  'group' => 'Prices',
492  'is_used_in_grid' => true,
493  'is_visible_in_grid' => false,
494  'is_filterable_in_grid' => false,
495  ],
496  'special_to_date' => [
497  'type' => 'datetime',
498  'label' => 'Special Price To Date',
499  'input' => 'date',
500  'backend' => Datetime::class,
501  'required' => false,
502  'sort_order' => 5,
504  'used_in_product_listing' => true,
505  'apply_to' => 'simple,virtual',
506  'group' => 'Prices',
507  'is_used_in_grid' => true,
508  'is_visible_in_grid' => false,
509  'is_filterable_in_grid' => false,
510  ],
511  'cost' => [
512  'type' => 'decimal',
513  'label' => 'Cost',
514  'input' => 'price',
515  'backend' => Price::class,
516  'required' => false,
517  'user_defined' => true,
518  'sort_order' => 6,
520  'apply_to' => 'simple,virtual',
521  'group' => 'Prices',
522  'is_used_in_grid' => true,
523  'is_visible_in_grid' => false,
524  'is_filterable_in_grid' => true,
525  ],
526  'weight' => [
527  'type' => 'decimal',
528  'label' => 'Weight',
529  'input' => 'weight',
530  'backend' => Weight::class,
531  'input_renderer' => WeightFormHelper::class,
532  'sort_order' => 5,
533  'apply_to' => 'simple,virtual',
534  'is_used_in_grid' => true,
535  'is_visible_in_grid' => false,
536  'is_filterable_in_grid' => true,
537  ],
538  'manufacturer' => [
539  'type' => 'int',
540  'label' => 'Manufacturer',
541  'input' => 'select',
542  'required' => false,
543  'user_defined' => true,
544  'searchable' => true,
545  'filterable' => true,
546  'comparable' => true,
547  'visible_in_advanced_search' => true,
548  'apply_to' => Type::TYPE_SIMPLE,
549  'is_used_in_grid' => true,
550  'is_visible_in_grid' => false,
551  'is_filterable_in_grid' => true,
552  ],
553  'meta_title' => [
554  'type' => 'varchar',
555  'label' => 'Meta Title',
556  'input' => 'text',
557  'required' => false,
558  'sort_order' => 20,
560  'group' => 'Meta Information',
561  'is_used_in_grid' => true,
562  'is_visible_in_grid' => false,
563  'is_filterable_in_grid' => true,
564  ],
565  'meta_keyword' => [
566  'type' => 'text',
567  'label' => 'Meta Keywords',
568  'input' => 'textarea',
569  'required' => false,
570  'sort_order' => 30,
572  'group' => 'Meta Information',
573  'is_used_in_grid' => true,
574  'is_visible_in_grid' => false,
575  'is_filterable_in_grid' => true,
576  ],
577  'meta_description' => [
578  'type' => 'varchar',
579  'label' => 'Meta Description',
580  'input' => 'textarea',
581  'required' => false,
582  'note' => 'Maximum 255 chars',
583  'class' => 'validate-length maximum-length-255',
584  'sort_order' => 40,
586  'group' => 'Meta Information',
587  'is_used_in_grid' => true,
588  'is_visible_in_grid' => false,
589  'is_filterable_in_grid' => true,
590  ],
591  'image' => [
592  'type' => 'varchar',
593  'label' => 'Base Image',
594  'input' => 'media_image',
595  'frontend' => ImageFrontendModel::class,
596  'input_renderer' => BaseImage::class,
597  'required' => false,
598  'sort_order' => 0,
600  'used_in_product_listing' => true,
601  'group' => 'General',
602  ],
603  'small_image' => [
604  'type' => 'varchar',
605  'label' => 'Small Image',
606  'input' => 'media_image',
607  'frontend' => ImageFrontendModel::class,
608  'required' => false,
609  'sort_order' => 2,
611  'used_in_product_listing' => true,
612  'group' => 'Images',
613  ],
614  'thumbnail' => [
615  'type' => 'varchar',
616  'label' => 'Thumbnail',
617  'input' => 'media_image',
618  'frontend' => ImageFrontendModel::class,
619  'required' => false,
620  'sort_order' => 3,
622  'used_in_product_listing' => true,
623  'group' => 'Images',
624  ],
625  'media_gallery' => [
626  'type' => 'varchar',
627  'label' => 'Media Gallery',
628  'input' => 'gallery',
629  'backend' => Media::class,
630  'required' => false,
631  'sort_order' => 4,
632  'group' => 'Images',
633  ],
634  'old_id' => ['type' => 'int', 'required' => false, 'sort_order' => 6, 'visible' => false],
635  'tier_price' => [
636  'type' => 'decimal',
637  'label' => 'Tier Price',
638  'input' => 'text',
639  'backend' => Tierprice::class,
640  'required' => false,
641  'sort_order' => 7,
643  'apply_to' => 'simple,virtual',
644  'group' => 'Prices',
645  ],
646  'color' => [
647  'type' => 'int',
648  'label' => 'Color',
649  'input' => 'select',
650  'required' => false,
651  'user_defined' => true,
652  'searchable' => true,
653  'filterable' => true,
654  'comparable' => true,
655  'visible_in_advanced_search' => true,
656  'apply_to' => implode(',', [Type::TYPE_SIMPLE, Type::TYPE_VIRTUAL]),
657  'is_used_in_grid' => true,
658  'is_visible_in_grid' => false,
659  'is_filterable_in_grid' => true,
660  ],
661  'news_from_date' => [
662  'type' => 'datetime',
663  'label' => 'Set Product as New from Date',
664  'input' => 'date',
665  'backend' => Startdate::class,
666  'required' => false,
667  'sort_order' => 7,
669  'used_in_product_listing' => true,
670  'is_used_in_grid' => true,
671  'is_visible_in_grid' => false,
672  'is_filterable_in_grid' => false,
673  ],
674  'news_to_date' => [
675  'type' => 'datetime',
676  'label' => 'Set Product as New to Date',
677  'input' => 'date',
678  'backend' => Datetime::class,
679  'required' => false,
680  'sort_order' => 8,
682  'used_in_product_listing' => true,
683  'is_used_in_grid' => true,
684  'is_visible_in_grid' => false,
685  'is_filterable_in_grid' => false,
686  ],
687  'gallery' => [
688  'type' => 'varchar',
689  'label' => 'Image Gallery',
690  'input' => 'gallery',
691  'required' => false,
692  'sort_order' => 5,
693  'group' => 'Images',
694  ],
695  'status' => [
696  'type' => 'int',
697  'label' => 'Status',
698  'input' => 'select',
699  'source' => Status::class,
700  'sort_order' => 9,
702  'searchable' => true,
703  'used_in_product_listing' => true,
704  ],
705  'minimal_price' => [
706  'type' => 'decimal',
707  'label' => 'Minimal Price',
708  'input' => 'price',
709  'required' => false,
710  'sort_order' => 8,
712  'visible' => false,
713  'apply_to' => 'simple,virtual',
714  'group' => 'Prices',
715  ],
716  'visibility' => [
717  'type' => 'int',
718  'label' => 'Visibility',
719  'input' => 'select',
720  'source' => Visibility::class,
721  'default' => '4',
722  'sort_order' => 12,
724  ],
725  'custom_design' => [
726  'type' => 'varchar',
727  'label' => 'Custom Design',
728  'input' => 'select',
729  'source' => Theme::class,
730  'required' => false,
731  'sort_order' => 1,
733  'group' => 'Design',
734  'is_used_in_grid' => true,
735  'is_visible_in_grid' => false,
736  'is_filterable_in_grid' => true,
737  ],
738  'custom_design_from' => [
739  'type' => 'datetime',
740  'label' => 'Active From',
741  'input' => 'date',
742  'backend' => Startdate::class,
743  'required' => false,
744  'sort_order' => 2,
746  'group' => 'Design',
747  'is_used_in_grid' => true,
748  'is_visible_in_grid' => false,
749  'is_filterable_in_grid' => false,
750  ],
751  'custom_design_to' => [
752  'type' => 'datetime',
753  'label' => 'Active To',
754  'input' => 'date',
755  'backend' => Datetime::class,
756  'required' => false,
757  'sort_order' => 3,
759  'group' => 'Design',
760  'is_used_in_grid' => true,
761  'is_visible_in_grid' => false,
762  'is_filterable_in_grid' => false,
763  ],
764  'custom_layout_update' => [
765  'type' => 'text',
766  'label' => 'Custom Layout Update',
767  'input' => 'textarea',
768  'backend' => Customlayoutupdate::class,
769  'required' => false,
770  'sort_order' => 4,
772  'group' => 'Design',
773  ],
774  'page_layout' => [
775  'type' => 'varchar',
776  'label' => 'Page Layout',
777  'input' => 'select',
778  'source' => LayoutModel::class,
779  'required' => false,
780  'sort_order' => 5,
782  'group' => 'Design',
783  'is_used_in_grid' => true,
784  'is_visible_in_grid' => false,
785  'is_filterable_in_grid' => false,
786  ],
787  'category_ids' => [
788  'type' => 'static',
789  'label' => 'Categories',
791  'backend' => CategoryBackendAttribute::class,
792  'input_renderer' => CategoryFormHelper::class,
793  'required' => false,
794  'sort_order' => 9,
795  'visible' => true,
796  'group' => 'General',
797  'is_used_in_grid' => false,
798  'is_visible_in_grid' => false,
799  'is_filterable_in_grid' => false,
800  ],
801  'options_container' => [
802  'type' => 'varchar',
803  'label' => 'Display Product Options In',
804  'input' => 'select',
805  'source' => Container::class,
806  'required' => false,
807  'default' => 'container2',
808  'sort_order' => 6,
810  'group' => 'Design',
811  ],
812  'required_options' => [
813  'type' => 'static',
814  'input' => 'text',
815  'required' => false,
816  'sort_order' => 14,
817  'visible' => false,
818  'used_in_product_listing' => true,
819  ],
820  'has_options' => [
821  'type' => 'static',
822  'input' => 'text',
823  'required' => false,
824  'sort_order' => 15,
825  'visible' => false,
826  ],
827  'image_label' => [
828  'type' => 'varchar',
829  'label' => 'Image Label',
830  'input' => 'text',
831  'required' => false,
832  'sort_order' => 16,
834  'visible' => false,
835  'used_in_product_listing' => true,
836  ],
837  'small_image_label' => [
838  'type' => 'varchar',
839  'label' => 'Small Image Label',
840  'input' => 'text',
841  'required' => false,
842  'sort_order' => 17,
844  'visible' => false,
845  'used_in_product_listing' => true,
846  ],
847  'thumbnail_label' => [
848  'type' => 'varchar',
849  'label' => 'Thumbnail Label',
850  'input' => 'text',
851  'required' => false,
852  'sort_order' => 18,
854  'visible' => false,
855  'used_in_product_listing' => true,
856  ],
857  'created_at' => [
858  'type' => 'static',
859  'input' => 'date',
860  'sort_order' => 19,
861  'visible' => false,
862  ],
863  'updated_at' => [
864  'type' => 'static',
865  'input' => 'date',
866  'sort_order' => 20,
867  'visible' => false,
868  ],
869  'country_of_manufacture' => [
870  'type' => 'varchar',
871  'label' => 'Country of Manufacture',
872  'input' => 'select',
873  'source' => Countryofmanufacture::class,
874  'required' => false,
876  'visible' => true,
877  'user_defined' => false,
878  'searchable' => false,
879  'filterable' => false,
880  'comparable' => false,
881  'visible_on_front' => false,
882  'unique' => false,
883  'apply_to' => 'simple,bundle',
884  'group' => 'General',
885  'is_used_in_grid' => true,
886  'is_visible_in_grid' => false,
887  'is_filterable_in_grid' => true,
888  ],
889  'quantity_and_stock_status' => [
890  'group' => 'General',
891  'type' => 'int',
892  'backend' => Stock::class,
893  'label' => 'Quantity',
894  'input' => 'select',
895  'input_renderer' => StockField::class,
896  'source' => StockSourceModel::class,
898  'default' => StockModel::STOCK_IN_STOCK,
899  'user_defined' => false,
900  'visible' => true,
901  'required' => false,
902  'searchable' => false,
903  'filterable' => false,
904  'comparable' => false,
905  'unique' => false,
906  ],
907  ],
908  ]
909  ];
910  }
911 }
__construct(ModuleDataSetupInterface $setup, Context $context, CacheInterface $cache, CollectionFactory $attrGroupCollectionFactory, CategoryFactory $categoryFactory)
$setup
Definition: trigger.php:12