1

I have created my own custom module for "Critic Expert" feature. I want to assign a critic expert with each product so I have to add my custom dropdown with each product.

How would I can show the dropdown with my custom module values and save it along with product in admin section.

Please find attached screenshot for more details.

enter image description here

2
  • @Neeraj Sharma, I have create small module for this you can download from below link. download link. You just need to share your selected option data to product data-provider.
    – kunj
    Mar 27, 2018 at 13:52
  • I had same requirement and created one module for it. Is it fine to create Critics List attribute and assign it with product by pragmatically ? Mar 27, 2018 at 14:16

1 Answer 1

2

I have created Small module. It will help you.

Create module files which are listed below.

app/code/Kunj/Critic/etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Kunj_Critic" setup_version="2.0.0"></module>
</config>

app/code/Kunj/Critic/Model/Critic/Options.php

<?php

namespace Kunj\Critic\Model\Critic;


class Options implements \Magento\Framework\Option\ArrayInterface
{
    public function toOptionArray()
    {
        return [
            [
                'value'=>1,
                'label'=>"My Option"
            ],
            [
                'value'=>2,
                'label'=>"My Option 2"
            ],
            [
                'value'=>3,
                'label'=>"My Option 3"
            ],
            [
                'value'=>4,
                'label'=>"My Option 4"
            ],
            [
                'value'=>5,
                'label'=>"My Option 5"
            ]
        ];
    }
}

app/code/Kunj/Critic/view/adminhtml/ui_component/product_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="product-details">
        <field name="critic_lists" sortOrder="300" formElement="select">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Kunj\Critic\Model\Critic\Options</item>
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">block</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <dataType>select</dataType>
                <label translate="true">Critic Lists</label>
                <dataScope>critic_lists</dataScope>
            </settings>
        </field>
    </fieldset>
</form>

app/code/Kunj/Critic/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Kunj_Critic',
    __DIR__
);

After create module run :

php bin/magento setup:upgrade
2
  • How I save these option in database Oct 9, 2018 at 10:56
  • this code for save those data in you custom table.
    – kunj
    Oct 11, 2018 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.