CreateUrlAttributes.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogUrlRewrite\Setup\Patch\Data;
  7. use Magento\Eav\Setup\EavSetup;
  8. use Magento\Eav\Setup\EavSetupFactory;
  9. use Magento\Framework\App\ResourceConnection;
  10. use Magento\Framework\Setup\ModuleDataSetupInterface;
  11. use Magento\Framework\Setup\Patch\DataPatchInterface;
  12. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  13. /**
  14. * Class CreateUrlAttributes
  15. * @package Magento\CatalogUrlRewrite\Setup\Patch
  16. */
  17. class CreateUrlAttributes implements DataPatchInterface, PatchVersionInterface
  18. {
  19. /**
  20. * @var ModuleDataSetupInterface
  21. */
  22. private $moduleDataSetup;
  23. /**
  24. * @var EavSetupFactory
  25. */
  26. private $eavSetupFactory;
  27. /**
  28. * CreateUrlAttributes constructor.
  29. * @param ModuleDataSetupInterface $moduleDataSetup
  30. * @param EavSetupFactory $eavSetupFactory
  31. */
  32. public function __construct(
  33. ModuleDataSetupInterface $moduleDataSetup,
  34. EavSetupFactory $eavSetupFactory
  35. ) {
  36. $this->moduleDataSetup = $moduleDataSetup;
  37. $this->eavSetupFactory = $eavSetupFactory;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function apply()
  43. {
  44. /** @var EavSetup $eavSetup */
  45. $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
  46. $eavSetup->addAttribute(
  47. \Magento\Catalog\Model\Category::ENTITY,
  48. 'url_key',
  49. [
  50. 'type' => 'varchar',
  51. 'label' => 'URL Key',
  52. 'input' => 'text',
  53. 'required' => false,
  54. 'sort_order' => 3,
  55. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  56. 'group' => 'General Information',
  57. ]
  58. );
  59. $eavSetup->addAttribute(
  60. \Magento\Catalog\Model\Category::ENTITY,
  61. 'url_path',
  62. [
  63. 'type' => 'varchar',
  64. 'required' => false,
  65. 'sort_order' => 17,
  66. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  67. 'visible' => false,
  68. 'group' => 'General Information',
  69. ]
  70. );
  71. $eavSetup->addAttribute(
  72. \Magento\Catalog\Model\Product::ENTITY,
  73. 'url_key',
  74. [
  75. 'type' => 'varchar',
  76. 'label' => 'URL Key',
  77. 'input' => 'text',
  78. 'required' => false,
  79. 'sort_order' => 10,
  80. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  81. 'used_in_product_listing' => true,
  82. 'group' => 'Search Engine Optimization',
  83. 'is_used_in_grid' => true,
  84. 'is_visible_in_grid' => false,
  85. 'is_filterable_in_grid' => true,
  86. ]
  87. );
  88. $eavSetup->addAttribute(
  89. \Magento\Catalog\Model\Product::ENTITY,
  90. 'url_path',
  91. [
  92. 'type' => 'varchar',
  93. 'required' => false,
  94. 'sort_order' => 11,
  95. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
  96. 'visible' => false,
  97. ]
  98. );
  99. }
  100. /**
  101. * {@inheritdoc}
  102. */
  103. public static function getDependencies()
  104. {
  105. return [];
  106. }
  107. /**
  108. * {@inheritdoc}
  109. */
  110. public static function getVersion()
  111. {
  112. return '2.0.0';
  113. }
  114. /**
  115. * {@inheritdoc}
  116. */
  117. public function getAliases()
  118. {
  119. return [];
  120. }
  121. }