Created
August 16, 2018 08:30
-
-
Save mikhailovv/ddc8a9b9c67f70d0e367226a4ebdc49c to your computer and use it in GitHub Desktop.
Magento 2 category attributes boolean\text\select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0"?> | |
| <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> | |
| <fieldset name="content"> | |
| <field name="have_engine"> | |
| <argument name="data" xsi:type="array"> | |
| <item name="config" xsi:type="array"> | |
| <item name="dataType" xsi:type="string">boolean</item> | |
| <item name="formElement" xsi:type="string">checkbox</item> | |
| <item name="label" xsi:type="string" translate="true">Have engine</item> | |
| <item name="prefer" xsi:type="string">toggle</item> | |
| <item name="valueMap" xsi:type="array"> | |
| <item name="true" xsi:type="string">1</item> | |
| <item name="false" xsi:type="string">0</item> | |
| </item> | |
| <item name="default" xsi:type="number">0</item> | |
| <item name="sortOrder" xsi:type="number">50</item> | |
| </item> | |
| </argument> | |
| </field> | |
| <field name="engine_volume"> | |
| <argument name="data" xsi:type="array"> | |
| <item name="config" xsi:type="array"> | |
| <item name="required" xsi:type="boolean">false</item> | |
| <item name="validation" xsi:type="array"> | |
| <item name="required-entry" xsi:type="boolean">false</item> | |
| </item> | |
| <item name="sortOrder" xsi:type="number">60</item> | |
| <item name="dataType" xsi:type="string">string</item> | |
| <item name="formElement" xsi:type="string">input</item> | |
| <item name="label" translate="true" xsi:type="string">Engine volume</item> | |
| </item> | |
| </argument> | |
| </field> | |
| <field name="engine_type"> | |
| <argument name="data" xsi:type="array"> | |
| <item name="options" xsi:type="object">CCXX\CategoryAddAttribute\Model\EngineTypeList</item> | |
| <item name="config" xsi:type="array"> | |
| <item name="sortOrder" xsi:type="number">70</item> | |
| <item name="dataType" xsi:type="string">string</item> | |
| <item name="formElement" xsi:type="string">select</item> | |
| <item name="label" xsi:type="string" translate="true">Engine type</item> | |
| </item> | |
| </argument> | |
| </field> | |
| </fieldset> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); | |
| /** Boolean attribute */ | |
| $eavSetup->addAttribute(Category::ENTITY, 'have_engine', | |
| [ | |
| 'type' => 'int', | |
| 'label' => 'Have engine', | |
| 'input' => 'boolean', | |
| 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean', | |
| 'visible' => true, | |
| 'default' => '0', | |
| 'sort_order'=> 100, | |
| 'required' => false, | |
| 'global' => ScopedAttributeInterface::SCOPE_STORE, | |
| 'group' => 'Content', | |
| ] | |
| ); | |
| /** Text attribute */ | |
| $eavSetup->addAttribute(Category::ENTITY,'engine_volume', | |
| [ | |
| 'type' => 'varchar', | |
| 'label' => 'Custom attribute', | |
| 'input' => 'text', | |
| 'required' => false, | |
| 'visible' => true, | |
| 'sort_order' => 105, | |
| 'global' => ScopedAttributeInterface::SCOPE_STORE, | |
| 'group' => 'Content', | |
| ] | |
| ); | |
| /** Select attribute */ | |
| $eavSetup->addAttribute(Category::ENTITY, 'engine_type', | |
| [ | |
| 'type' => 'int', | |
| 'label' => 'Engine type', | |
| 'input' => 'select', | |
| 'source' => 'Magento\Catalog\Model\Category\Attribute\Source\Page', | |
| 'required' => false, | |
| 'sort_order' => 110, | |
| 'global' => ScopedAttributeInterface::SCOPE_STORE, | |
| 'group' => 'Content', | |
| ] | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment