3

i have file etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="productquestion" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Productquestion Configuration</label>
            <tab>general</tab>
            <resource>Mageaddons_Productquestion::config_module</resource>
            <group id="productquestion_admin" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>General</label>
                <field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable Product Question</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="guest_question" translate="label" type="select" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Allow Guest Ask Question</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="guest_answer" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Allow Guest Answer Question</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
            </group>
            <group id="productquestion_frontend" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Frontend Setting</label>
                <field id="product_question_per_page" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Product Question per Page to display</label>
                </field>
                <field id="sort_by" translate="label" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Default questions sort by</label>
                    <source_model>Mageaddons\Productquestion\Model\Config\Source\Sortby</source_model>
                </field>
                <field id="sort_dierction" translate="label" type="select" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Default questions sort direction</label>
                    <source_model>Mageaddons\Productquestion\Model\Config\Source\Sortdirection</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

and etc/config.xml

`<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <productquestion>
            <productquestion_admin>
                <enabled>1</enabled>
                <guest_question>1</guest_question>
                <guest_answer>1</guest_answer>
            </productquestion_admin>
        </productquestion>      
    </default>
</config>`

it not set default value.

what wrong for file config.xml? thanks

3
  • ect should be etc. Is this a typo? or that's how your folder is named?
    – Marius
    Dec 14, 2015 at 15:30
  • yes it must be etc. i editted question.
    – xanka
    Dec 15, 2015 at 1:43
  • are the backticks in config.xml actually there or is a mistake from posting the code here?
    – scrowler
    Dec 15, 2015 at 3:13

1 Answer 1

2

Based on the PHP error

Warning: DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding ! Bytes: 0xA9 0x20 0x32 0x30 in Entity, line: 4

It sounds like one of your files has an encoding error. Step one will be identifying which file this is. Removing config.xml and system.xml one by one, clearing cache, and then re-adding each back (again,clearing the cache between each step) should reveal which file is the problem file. Once you've got that identified you can investigate why your text editor's encoding is set incorrectly.

Update

It looks like your config.xml is incorrect. The following

<default>
    <productquestion>
        <productquestion>
            <enabled>1</enabled>
            <guest_question>1</guest_question>
            <guest_answer>1</guest_answer>
        </productquestion>
    </productquestion>      
</default>

will set the default for configuration paths of

productquestion/productquestion/enabled
productquestion/productquestion/guest_question
productquestion/productquestion/guest_answer

However, your system.xml sets up a configuration section named productquestion, two groups named productquestion_admin and productquestion_frontend, meaning your final field paths are

productquestion/productquestion_frontend/enabled
productquestion/productquestion_frontend/guest_question
productquestion/productquestion_frontend/guest_answer

productquestion/productquestion_admin/product_question_per_page
productquestion/productquestion_admin/sort_by
productquestion/productquestion_admin/sort_dierction

So, if you wanted to setup a config.xml file that set a default value for productquestion/productquestion_frontend/enabled, you'd do

<default>
    <productquestion>
        <productquestion_frontend>
            <enabled>1</enabled>
        </productquestion_frontend>
    </productquestion>      
</default>

Also, don't forget to check if core_config_data has values already. Even if you don't explicitly change a configuration value, saving a group will save the defaults into the database, and further changes to config.xml fill have no effect.

3
  • i made it and get error same. when i remove config.xml it work. after re-adding config.xml get error. what wrong for file config.xml?
    – xanka
    Dec 15, 2015 at 2:13
  • i removed <?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> and re-run it run but not set default value. You Can help?
    – xanka
    Dec 15, 2015 at 2:33
  • @xanka question updated. Don't forget to vote on answers that help you -- a good voting/accepting ratio can help get your answers in the future. Dec 15, 2015 at 2:41

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.