Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a scenario where i need to be able to select magento stores like this from the system configuration section . Store view

Thanks in advance for any kind of help.

share|improve this question
up vote 6 down vote accepted

This goes in the system.xml under the fields tag.

<field_name_here translate="title" module="[module]">
    <label>Label goes here</label>
    <frontend_type>multiselect</frontend_type>
    <source_model>[module]/store</source_model>
    <sort_order>10</sort_order> <!-- feel free to change this value -->
    <show_in_default>1</show_in_default><!-- can be 0 or 1 -->
    <show_in_website>0</show_in_website><!-- can be 0 or 1 -->
    <show_in_store>0</show_in_store><!-- can be 0 or 1 -->
</field_name_here>

Then create the source model.
For that you need a class inside your module.

app/code/[codebool]/[Namespace]/[Module]/Model/Store.php with this code:

<?php
class [Namespace]_[Module]_Model_Store {
    public function toOptionArray() {
        return Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true);
    }
}

Replace in the code above the values between [] with the appropriate values and you are done.

share|improve this answer
    
Thanks a lot, it works like a charm. Thanks again. – Haris Aug 25 '14 at 8:04
    
when I use this code it shows the options Yes and No in the screen not the stores. Weird stuff, any idea why? – Sander van Zuidam Mar 14 at 15:49
    
maybe you have the wrong source model. – Marius Mar 14 at 15:53
    
It shows the store information and I can select it but how can I actually save the value that was selected? Would be great if I can save it in the core_config_table so I can use it later on. – Sander van Zuidam Mar 16 at 15:30

when I use this code it shows the options Yes and No in the screen not the stores. Weird stuff, any idea why?

        <stores>
        <label>Select store</label>
        <frontend_type>multiselect</frontend_type>
        <source_model>Modulename/store</source_model>
        <sort_order>60</sort_order> <!-- feel free to change this value -->
        <show_in_default>1</show_in_default><!-- can be 0 or 1 -->
        <show_in_website>1</show_in_website><!-- can be 0 or 1 -->
        <show_in_store>1</show_in_store><!-- can be 0 or 1 -->
        </stores>

Above is my system.xml code for this field. Next to this I have the folder

app/code/community/MageModule/Modulename/Model/Store.php

<?php
class MageModule_Modulename_Model_Store {
public function toOptionArray() {
    return Mage::getSingleton('adminhtml/system_store')-      >getStoreValuesForForm(false, true);
  }
}
share|improve this answer
    
you can ask this question in comment as you had asked a question in answer section. for your issue, you may be using <source_model>adminhtml/system_config_source_yesno</source_model> – Haris Mar 14 at 6:24
    
Sure thanks, changed it, no I am actually using the module/store source model – Sander van Zuidam Mar 14 at 15:51
    
can you post the code here, for source model? – Haris Mar 15 at 6:09
    
Sure, see above – Sander van Zuidam Mar 15 at 19:32
    
It actually works :-) But I missed one capital letter and needed to clear my cache. – Sander van Zuidam Mar 16 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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