Question

I'm developing a module for Magento 2.3 and can't get default config values to show up in the admin. To the best of my knowledge, I've followed all the documentation I can find. It's kind of driving me crazy :)

A link to my full project can be found here: https://github.com/crankycyclops/DiscountCodeUrl

And here are the contents of the two relevant files:

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="promo">

            <group id="discounturl" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">

                <label>Discount URL Settings</label>

                <field id="enabled" translate="label comment" type="select" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enabled</label>
                    <comment>If the discount URL module is enabled, you'll be able to apply discount codes automatically via URL. Disable this if you have other modules running that implement similar behavior or that might conflict.</comment>
                    <validate>required-entry</validate>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>

                <field id="url_param" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>URL Parameter</label>
                    <comment>This is the GET parameter that will contain a coupon code in the URL. For example, if this value is "coupon", then https://store.url?coupon=CODE will set the coupon code to "CODE." If this value isn't set, we'll use the hardcoded default specified by Helper\Cookie::DEFAULT_URL_PARAMETER.</comment>
                </field>

                <field id="cookie_lifetime" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Cookie Lifetime</label>
                    <comment>When a coupon code comes in through a URL, we set it in a cookie so that we can remember it for the entire session. This value determines how long that cookie should stay set before it expires (in seconds.) Value must be 0 or greater (0 means the cookie will remain alive until the browser window or tab remains open.) If this value isn't set, we'll use the hardcoded default specified by Helper\Cookie::COOKIE_LIFETIME.</comment>
                    <validate>validate-zero-or-greater</validate>
                </field>

            </group>

        </section>

    </system>

</config>

etc/config.xml:

<?xml version="1.0" ?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">

    <default>

        <promo>

            <discounturl>

                <enabled>0</enabled>
                <url_param>coupon</url_param>
                <cookie_lifetime>0</cookie_lifetime>

            </discounturl>

        </promo>

    </default>

</config>
Was it helpful?

Solution

Looks like this is working for others and there's just something strange going on with my own instance of Magento.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top