4

I'm getting a little desperate here with my custom Magento Backend Models.

Here is the situation: I have 2 multiselect (locales_served, countries_served) fields with custom backend models in my Magento Admin Configuration (as defined in system.xml below). They are mutually exclusive depending on another yes/no field.

So far, so good. Everything works fine as expected, the backend models work, too, BUT when I switch from one multiselect to the other, it uses the other options backend model. The backend classes are completely separate and I have no clue what's happening.

Let's say I start with locales_served, select some options and save - it works fine, my values are stored in the DB, all good. Then I go back to the Default Config, change to countries_served, select some options and save - BOOM, it overwrites my locales_served options.

<locales_served translate="label">
  <label>This Store serves these languages:</label>
  <frontend_type>multiselect</frontend_type>
  <backend_model>Foo_Bar_Model_LocaleMappingData</backend_model>
  <sort_order>5</sort_order>
  <source_model>adminhtml/system_config_source_locale</source_model>
  <show_in_default>0</show_in_default>
  <show_in_website>0</show_in_website>
  <show_in_store>1</show_in_store>
  <can_be_empty>1</can_be_empty>
  <depends><redirection_mode_select>locale</redirection_mode_select
  </depends>
</locales_served>  

<countries_served translate="label">
  <label>This Store serves these countries:</label>
  <frontend_type>multiselect</frontend_type
  <backend_model>Foo_Bar_Model_CountryMappingData</backend_model
  <sort_order>4</sort_order
  <source_model>adminhtml/system_config_source_country</source_model>
  <show_in_default>0</show_in_default>
  <show_in_website>0</show_in_website>
  <show_in_store>1</show_in_store>
  <can_be_empty>1</can_be_empty>
  <depends><redirection_mode_select>ip</redirection_mode_select>
  </depends>
</countries_served>  

Backend model class for locale select field:

class Foo_Bar_Model_LocaleMappingData extends Mage_Core_Model_Config_Data
{

const PATH = 'foo_bar/global_config/locales_served';


public function _afterSave()
{

    $h = Mage::helper('foo_bar/ConfigHelper'); 
    $storeId = $this->getScopeId();
    $h->updateMappings($storeId,$this->getValue(),self::PATH);  
}
}

backend model class for country select field, the echo produces this: 'foo_bar/global_config/locales_served' instead of 'foo_bar/global_config/countries_served'

class Foo_Bar_Model_CountryMappingData extends Mage_Core_Model_Config_Data
{

const PATH = 'foo_bar/global_config/countries_served';


public function _afterSave()
{

echo self::PATH;
exit;
    $h = Mage::helper('foo_bar/ConfigHelper'); 
    $storeId = $this->getScopeId();
    $h->updateMappings($storeId,$this->getValue(),self::PATH);      
}
}

Any ideas?

1
  • can you add the updateMappings methods to the question?
    – Marius
    Jun 10, 2016 at 9:22

2 Answers 2

0

What you describe is impossible if you don't add echo self::PATH to the other class as well. self::PATH gets replaced with the constant in the same class at compile time (other than static::PATH which would be replaced at runtime)

So the actual code that is executed must be something else. Possible reasons:

  • uploaded files to the wrong server / wrong location
  • Opcache contains an old version of the code
0

Figured it out - <depends>...</depends> just converts the select field into a hidden field if the condition is not met - the value is still posted though and my backend model is still instantiated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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