1

I tried to add new custom source_model (select). My config.xml:

<config>
    <modules>
        <Pixels_UniversalPixel>
            <version>1.0.0</version>
        </Pixels_UniversalPixel>
    </modules>

    <global>
      <models>
         <universal_pixel>
            <class>Pixels_UniversalPixel_Model</class>
         </universal_pixel>
      </models>
    </global>

</config>

My widget.xml:

<widgets>
    <universal_pixel type="universal_pixel/pixel">
        <name>Universal Pixel</name>
        <description type="desc">Adds a universal pixel</description>
        <parameters>
            <require_consent>
                <label>Require consent</label>
                <type>select</type>
                <required>1</required>
                <visible>1</visible>
                <value>1</value>
                <source_model>universal_pixel/system_config_source_gdpr_states</source_model>
            </require_consent>
        </parameters>
    </universal_pixel>
</widgets>

And my model src/app/code/local/Pixels/UniversalPixel/Model/System/Config/Source/GDPR/States.php :

<?php

class Pixels_UniversalPixel_Model_System_Config_Source_GDPR_States
{
    public function toOptionArray()
    {
        return array(
            array(
                'value' => 0,
                'label' => 'No consent',
            ),
            array(
                'value' => 1,
                'label' => 'Require consent',
            ),
            array(
                'value' => 2,
                'label' => 'Require consent in EU only',
            ),
        );
    }
}

But it doesn't work. Where is my mistake. Thanks in advance.

1

Everything is right except the directory name you are using:

Change the directory name from GDPR to Gdpr and also change the class name from:

class Pixels_UniversalPixel_Model_System_Config_Source_GDPR_States

to

class Pixels_UniversalPixel_Model_System_Config_Source_Gdpr_States

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.