1

I am add a Multiselect into the custom section product insertion area.Please show below screenshot:

enter image description here

I add this multiselect into the

F:\xampp-7.2.14\htdocs\magento230\app\Code\Vendor\module\view\adminhtml\ui_component\product_form.xml

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="cs_product_custom_option">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">cs Product Custom Option</item>
                <item name="dataScope" xsi:type="string"/>
                <item name="sortOrder" xsi:type="number">10</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="opened" xsi:type="boolean">true</item>
            </item>
        </argument>
        <field name="cs_custom_option">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">cs\Customproduct\Model\Source\CustomoptionValues</item>
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="label" translate="true" xsi:type="string">Select the options</item>
                    <item name="formElement" xsi:type="string">multiselect</item>
                </item>
            </argument>
    </field>

    </fieldset>

How to save its value into the database with products ?

Thanks in a Advance

  • Add a product attribute to achieve this, that's more efficient way and simple enough too. If you need any information, please let me know. – G Prathap Feb 12 at 11:11
  • Hello @G Prathap it's all value is dynamic and come into the database. so attribute is not working – Hardik Makwana Feb 12 at 11:12
  • Any another solution ? – Hardik Makwana Feb 12 at 11:14
  • Did you create this attribute in Setup? – Serhii Havrylchuk Feb 12 at 11:49
  • Yes please update the question with more information exactly what you require. – G Prathap Feb 12 at 11:52
1

You should create

cs\Customproduct\Setup\InstallData.php

  <?php
    namespace cs\Customproduct\Setup;

    use Magento\Eav\Setup\EavSetup;
    use Magento\Eav\Setup\EavSetupFactory;
    use Magento\Framework\Setup\InstallDataInterface;
    use Magento\Framework\Setup\ModuleContextInterface;
    use Magento\Framework\Setup\ModuleDataSetupInterface;

    class InstallData implements InstallDataInterface
    {
        private $eavSetupFactory;

        public function __construct(EavSetupFactory $eavSetupFactory)
        {
            $this->eavSetupFactory = $eavSetupFactory;
        }

        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'cs_custom_option',
                [
                    'type' => 'text',
                    'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
                    'frontend' => '',
                    'label' => 'Select the options',
                    'input' => 'multiselect',
                    'class' => '',                  
                    'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'source' => 'cs\Customproduct\Model\Source\CustomoptionValues',
                    'visible' => true,
                    'required' => true,
                    'user_defined' => false,
                    'default' => '',
                    'searchable' => false,
                    'filterable' => false,
                    'comparable' => false,
                    'visible_on_front' => false,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'apply_to' => ''
                ]
            );
        }
    }
  • when i delete the record into the database then into attribute also delete this value ? – Hardik Makwana Feb 12 at 12:07
  • which record do you want to delete? – Serhii Havrylchuk Feb 12 at 12:08
  • In a database id 1 with "abc" I create the attribute with using your code then i delete the id 1 record then attribute have a "abc" value . i also want to delete this – Hardik Makwana Feb 12 at 12:10
  • Yes it will be deleted – Serhii Havrylchuk Feb 12 at 12:11
  • ohk i will try it – Hardik Makwana Feb 12 at 12:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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