0

I am new to Magento 2.1 and still working out most things about it.

I've created a custom module to add an attribute to admin add/edit product page. It's a very simple set up of a title and text area. I've managed to setup:upgrade & setup:di:compile the module with no issues. It's showing within the admin add/edit product page. What's it not doing is saving any value I enter into textarea and save. This is where my knowledge starts to fall short.

here is my code

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
  <preference for="Magento\Catalog\Model\Category" type="Fellowship\PorductPriceMeassage\Model\Category" />
</config>

module.xml

<?xml version="1.0"?>
<!-- file: app/code/Fellowship/CategoryAttribute/etc/module.xml -->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Fellowship_PorductPriceMeassage" setup_version="1.0.2" >
        <sequence>
                <module name="Magento_Catalog"/>
            </sequence>
        </module>
</config>

ui_component > product_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- file: app/code/Fellowship/PorductPriceMeassage/view/adminhtml/ui_component/category_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="product-details">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Price Message</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">100</item>
            </item>
        </argument>
        <field name="price_meassage">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">15</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">textarea</item>
                    <item name="label" xsi:type="string" translate="true">Price Message</item>
                    <item name="required" xsi:type="boolean">false</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

I am not 100% sure, but I suspect that, it's the code used in di & module xml which is stopping the value from being saved.

I will be very grateful if anyone could point out that where I am going wrong.

1
  • Have you created Model? – P_U Oct 13 '17 at 12:00
0

Why do not add these fields with the admin interface? https://www.mageplaza.com/kb/how-to-create-product-attribute-magento-2.html

If you really want to do it with a script, you need to add these new fields in the databse with setup or upgrade class: http://inchoo.net/magento-2/setup-scripts-magento-2/

1
  • Hi Mathieu. Thank you for a quick response. I've looked at using admin attribute controller before but you can't embed additional fields within 'product-details' panel on add/edit product page. – A.Lewis Oct 13 '17 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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