2

For my shipping module, I have created a block which has group of form element.

<options translate="label">
    <label>Other Settings</label>                            
    <frontend_model>Namespace_Module_Block_Form_Field_Options</frontend_model>
    <sort_order>172</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    <can_be_empty>1</can_be_empty>
</options>

And this is block which I have created.

class Namespace_Module_Block_Form_Field_Options extends Mage_Adminhtml_Block_System_Config_Form_Field {
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
        $value = Mage::getStoreConfig('carriers/namespace_module/optionalfield');
        $xhtml = '<input type="text" class="input-text" value="'.$value.'" name="groups[namespace_module][fields][optionalfield][value]" />';
        return $xhtml;
    }
}

In this block I have create more many options, It is working fine. But the issue is that in system->configuration, Mage::getStoreConfig('carriers/namespace_module/optionalfield'); is returning value which is saved in default config, And not showing value according to the store selected.

In each store Mage::getStoreConfig('carriers/namespace_module/optionalfield'); is showing value which is saved in default config.

So I think I use this code Mage::getStoreConfig('carriers/namespace_module/optionalfield',$store_id) than it will show me values according to store selected in system->configuration.

So guide me how to get store id in this block

2 Answers 2

1

Try this piece of code:

if (strlen($code = Mage::getSingleton('adminhtml/config_data')->getStore())) // store level
{
    $store_id = Mage::getModel('core/store')->load($code)->getId();
}
elseif (strlen($code = Mage::getSingleton('adminhtml/config_data')->getWebsite())) // website level
{
    $website_id = Mage::getModel('core/website')->load($code)->getId();
    $store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
}
else // default level
{
    $store_id = 0;
}

you can take more idea from

How to get current store id from current scope in admin

Get current website id in admin

0

I used this one

if (strlen($code = Mage::app()->getRequest()->getParam('store'))) { // store level
            $store_id = Mage::getModel('core/store')->load($code)->getId();
        } elseif (strlen($code = $code = Mage::app()->getRequest()->getParam('website'))) { // website level
            $website_id = Mage::getModel('core/website')->load($code)->getId();
            $store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
        } else { // default level
            $store_id = 0;
        }

and that worked fine for me

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.