UpgradeData.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\UpgradeDataInterface;
  8. use Magento\Framework\Setup\ModuleContextInterface;
  9. use Magento\Framework\Setup\ModuleDataSetupInterface;
  10. use Magento\Catalog\Setup\CategorySetupFactory;
  11. /**
  12. * @codeCoverageIgnore
  13. */
  14. class UpgradeData implements UpgradeDataInterface
  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 upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  36. {
  37. $installer = $setup;
  38. $installer->startSetup();
  39. if (version_compare($context->getVersion(), '2.1.0') < 0) {
  40. // set new resource model paths
  41. /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
  42. $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
  43. $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Category::ENTITY);
  44. $attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
  45. $menu_attributes = [
  46. 'sw_ocat_hide_this_item' => [
  47. 'type' => 'int',
  48. 'label' => 'Hide This Category',
  49. 'input' => 'select',
  50. 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
  51. 'required' => false,
  52. 'sort_order' => 10,
  53. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  54. 'group' => 'Onepage Category'
  55. ],
  56. 'sw_ocat_category_icon_image' => [
  57. 'type' => 'varchar',
  58. 'label' => 'Icon Image',
  59. 'input' => 'image',
  60. 'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
  61. 'required' => false,
  62. 'sort_order' => 20,
  63. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  64. 'group' => 'Onepage Category'
  65. ],
  66. 'sw_ocat_category_font_icon' => [
  67. 'type' => 'varchar',
  68. 'label' => 'Font Icon Class',
  69. 'input' => 'text',
  70. 'required' => false,
  71. 'sort_order' => 30,
  72. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  73. 'group' => 'Onepage Category',
  74. 'note' => 'If this category has no "Icon Image", font icon will be shown. example to input: icon-dollar'
  75. ],
  76. 'sw_ocat_category_hoverbgcolor' => [
  77. 'type' => 'varchar',
  78. 'label' => 'Category Hover Background Color',
  79. 'input' => 'text',
  80. 'required' => false,
  81. 'sort_order' => 40,
  82. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  83. 'group' => 'Onepage Category',
  84. 'note' => 'eg: #00d59d'
  85. ],
  86. 'sw_ocat_additional_content' => [
  87. 'type' => 'text',
  88. 'label' => 'Additional Content',
  89. 'input' => 'textarea',
  90. 'required' => false,
  91. 'sort_order' => 50,
  92. 'wysiwyg_enabled' => true,
  93. 'is_html_allowed_on_front' => true,
  94. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  95. 'group' => 'Onepage Category'
  96. ]
  97. ];
  98. foreach($menu_attributes as $item => $data) {
  99. $categorySetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, $item, $data);
  100. }
  101. $idg = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, 'Onepage Category');
  102. foreach($menu_attributes as $item => $data) {
  103. $categorySetup->addAttributeToGroup(
  104. $entityTypeId,
  105. $attributeSetId,
  106. $idg,
  107. $item,
  108. $data['sort_order']
  109. );
  110. }
  111. }
  112. $setup->endSetup();
  113. }
  114. }