Magento 1.7 Get Config Data from Current Store – Admin Area Guide

magento-1.7shippingshipping-methods

i want to get config data from current store not from default config so for example if i change Table rates title from "Table Rate" to "Something Else" in main webisite config and save it, i can see these changes also in Default store view and that is ok, but if i want to get this title "Something else" i always get title "Table Rates" i am using this code to check it:

$title = Mage::getStoreConfig('carriers/tablerate/title',Mage::app()->getStore()); 
            var_dump($title);
            die();

and it always prints "Table Rate", i have also tried without 'Mage::app()->getStore())' cause i read there that "The getStoreConfig() method looks like return self::app()->getStore($store)->getConfig($path);, so it get the same if you don't pass the second param – 'Mage::app()->getStore()'." so can anyone tell me how to get config from main website not from default config?

p.s. i have my own shipping module with all config and cerrier and etc files, table rates is just a sample that is the same thing happens to the table rates also.

Best Answer

You problem is that your code is always executed from admin area. So it it always getting store ID of admin store. Which is 0.

To change this you have to fetch the store ID from the order and use as a second parameter of Mage::getStoreConfig(). So in your method it should look like this:

public function salesOrderShipmentSaveBefore($observer)
{
    ...
    $order = $observer->getOrder();
    $title = Mage::getStoreConfig('carriers/tablerate/title', $order->getData('store_id'));
    ...
}
Related Topic