Now, I've got empty dropdown.
Here is my code (InstallData.php):
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'width',
[
'type' => 'int',
'label' => 'Width',
'input' => 'select',
'source' => 'Magento\Catalog\Model\Category\Attribute\Source\Page',
'required' => false,
'sort_order' => 4,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'is_html_allowed_on_front' => true,
'group' => 'General Information',
]
);
$setup->endSetup();
}
And category_form.xml:
<?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="display_settings">
<field name="width">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="formElement" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Width</item>
<item name="options" xsi:type="array">
<item name="33" xsi:type="string">33</item>
<item name="50" xsi:type="string">50</item>
</item>
<item name="default" xsi:type="number">50</item>
</item>
</argument>
</field>
</fieldset>
</form>
asked Sep 12, 2017 at 13:43
Kyrylo Romantsov
7312 gold badges14 silver badges35 bronze badges
1 Answer 1
Add following line
<item name="options" xsi:type="object">Magento\Catalog\Model\Category\Attribute\Source\Page</item>
So your xml looks like
<?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="display_settings">
<field name="width">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Magento\Catalog\Model\Category\Attribute\Source\Page</item>
<item name="config" xsi:type="array">
<item name="formElement" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Width</item>
<item name="options" xsi:type="array">
<item name="33" xsi:type="string">33</item>
<item name="50" xsi:type="string">50</item>
</item>
<item name="default" xsi:type="number">50</item>
</item>
</argument>
</field>
</fieldset>
</form>
Clear cache.
answered Sep 12, 2017 at 14:24
Sohel Rana
36.2k3 gold badges74 silver badges94 bronze badges
-
Hi @Sohel Rana sir, is there any solution for this implementation. magento.stackexchange.com/questions/245983/… please help me sirRadha Krishna– Radha Krishna2018年10月12日 10:36:12 +00:00Commented Oct 12, 2018 at 10:36
Explore related questions
See similar questions with these tags.
default