InstallData.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /**
  3. * Copyright © 2018 Porto. All rights reserved.
  4. */
  5. namespace Smartwave\Megamenu\Setup;
  6. use Magento\Framework\Module\Setup\Migration;
  7. use Magento\Framework\Setup\InstallDataInterface;
  8. use Magento\Framework\Setup\ModuleContextInterface;
  9. use Magento\Framework\Setup\ModuleDataSetupInterface;
  10. use Magento\Catalog\Setup\CategorySetupFactory;
  11. /**
  12. * @codeCoverageIgnore
  13. */
  14. class InstallData implements InstallDataInterface
  15. {
  16. /**
  17. * Category setup factory
  18. *
  19. * @var CategorySetupFactory
  20. */
  21. private $categorySetupFactory;
  22. /**
  23. * Init
  24. *
  25. * @param CategorySetupFactory $categorySetupFactory
  26. */
  27. public function __construct(CategorySetupFactory $categorySetupFactory)
  28. {
  29. $this->categorySetupFactory = $categorySetupFactory;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  34. */
  35. public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  36. {
  37. $installer = $setup;
  38. $installer->startSetup();
  39. $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
  40. $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Category::ENTITY);
  41. $attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
  42. $menu_attributes = [
  43. 'sw_menu_hide_item' => [
  44. 'type' => 'int',
  45. 'label' => 'Hide This Menu Item',
  46. 'input' => 'select',
  47. 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
  48. 'required' => false,
  49. 'sort_order' => 10,
  50. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  51. 'group' => 'SW Menu'
  52. ],
  53. 'sw_menu_type' => [
  54. 'type' => 'varchar',
  55. 'label' => 'Menu Type',
  56. 'input' => 'select',
  57. 'source' => 'Smartwave\Megamenu\Model\Attribute\Menutype',
  58. 'required' => false,
  59. 'sort_order' => 20,
  60. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  61. 'group' => 'SW Menu'
  62. ],
  63. 'sw_menu_static_width' => [
  64. 'type' => 'varchar',
  65. 'label' => 'Static Width',
  66. 'input' => 'text',
  67. 'required' => false,
  68. 'sort_order' => 30,
  69. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  70. 'group' => 'SW Menu'
  71. ],
  72. 'sw_menu_cat_columns' => [
  73. 'type' => 'varchar',
  74. 'label' => 'Sub Category Columns',
  75. 'input' => 'select',
  76. 'source' => 'Smartwave\Megamenu\Model\Attribute\Subcatcolumns',
  77. 'required' => false,
  78. 'sort_order' => 40,
  79. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  80. 'group' => 'SW Menu'
  81. ],
  82. 'sw_menu_float_type' => [
  83. 'type' => 'varchar',
  84. 'label' => 'Float',
  85. 'input' => 'select',
  86. 'source' => 'Smartwave\Megamenu\Model\Attribute\Floattype',
  87. 'required' => false,
  88. 'sort_order' => 50,
  89. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  90. 'group' => 'SW Menu'
  91. ],
  92. 'sw_menu_cat_label' => [
  93. 'type' => 'varchar',
  94. 'label' => 'Category Label',
  95. 'input' => 'select',
  96. 'source' => 'Smartwave\Megamenu\Model\Attribute\Categorylabel',
  97. 'required' => false,
  98. 'sort_order' => 60,
  99. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  100. 'group' => 'SW Menu'
  101. ],
  102. 'sw_menu_icon_img' => [
  103. 'type' => 'varchar',
  104. 'label' => 'Icon Image',
  105. 'input' => 'image',
  106. 'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
  107. 'required' => false,
  108. 'sort_order' => 70,
  109. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  110. 'group' => 'SW Menu'
  111. ],
  112. 'sw_menu_font_icon' => [
  113. 'type' => 'varchar',
  114. 'label' => 'Font Icon Class',
  115. 'input' => 'text',
  116. 'required' => false,
  117. 'sort_order' => 80,
  118. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  119. 'group' => 'SW Menu'
  120. ],
  121. 'sw_menu_block_top_content' => [
  122. 'type' => 'text',
  123. 'label' => 'Top Block',
  124. 'input' => 'textarea',
  125. 'required' => false,
  126. 'sort_order' => 90,
  127. 'wysiwyg_enabled' => true,
  128. 'is_html_allowed_on_front' => true,
  129. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  130. 'group' => 'SW Menu'
  131. ],
  132. 'sw_menu_block_left_width' => [
  133. 'type' => 'varchar',
  134. 'label' => 'Left Block Width',
  135. 'input' => 'select',
  136. 'source' => 'Smartwave\Megamenu\Model\Attribute\Width',
  137. 'required' => false,
  138. 'sort_order' => 100,
  139. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  140. 'group' => 'SW Menu'
  141. ],
  142. 'sw_menu_block_left_content' => [
  143. 'type' => 'text',
  144. 'label' => 'Left Block',
  145. 'input' => 'textarea',
  146. 'required' => false,
  147. 'sort_order' => 110,
  148. 'wysiwyg_enabled' => true,
  149. 'is_html_allowed_on_front' => true,
  150. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  151. 'group' => 'SW Menu'
  152. ],
  153. 'sw_menu_block_right_width' => [
  154. 'type' => 'varchar',
  155. 'label' => 'Right Block Width',
  156. 'input' => 'select',
  157. 'source' => 'Smartwave\Megamenu\Model\Attribute\Width',
  158. 'required' => false,
  159. 'sort_order' => 120,
  160. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  161. 'group' => 'SW Menu'
  162. ],
  163. 'sw_menu_block_right_content' => [
  164. 'type' => 'text',
  165. 'label' => 'Right Block',
  166. 'input' => 'textarea',
  167. 'required' => false,
  168. 'sort_order' => 130,
  169. 'wysiwyg_enabled' => true,
  170. 'is_html_allowed_on_front' => true,
  171. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  172. 'group' => 'SW Menu'
  173. ],
  174. 'sw_menu_block_bottom_content' => [
  175. 'type' => 'text',
  176. 'label' => 'Bottom Block',
  177. 'input' => 'textarea',
  178. 'required' => false,
  179. 'sort_order' => 140,
  180. 'wysiwyg_enabled' => true,
  181. 'is_html_allowed_on_front' => true,
  182. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  183. 'group' => 'SW Menu'
  184. ]
  185. ];
  186. foreach($menu_attributes as $item => $data) {
  187. $categorySetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, $item, $data);
  188. }
  189. $idg = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, 'SW Menu');
  190. foreach($menu_attributes as $item => $data) {
  191. $categorySetup->addAttributeToGroup(
  192. $entityTypeId,
  193. $attributeSetId,
  194. $idg,
  195. $item,
  196. $data['sort_order']
  197. );
  198. }
  199. $installer->endSetup();
  200. }
  201. }