0
点赞
收藏
分享

微信扫一扫

Magento 获取Configuration属性 Retrieve Magento Core Configuration variables


Magento has a vast configuration table (core_config_data in your database) that is managed in the Magento admin under System > Configuration. Occasionally you might need to find the value of a core configuration variable to do something on the fronted of your Magento store. To do this you can use the Magento Mage::getStoreConfig() method.

 

Here is an example where we get the value of the Logo Image Src found in System > Configuration > Design > Header:

// Get the logo from the current store config
$logoSrc = Mage::getStoreConfig('design/header/logo_src');

 

This will return something like "images/logo.gif" which you can then use to pull the logo wherever you want. This way if your logo is ever changed to say, ""images/logo.jpg", you don't have to hunt through all your templates to replace the .gif extension with .jpg. The value will be updated instantly when you save your configuration.

 

The "design/header/logo_src" matches the path column in the core_config_data table in the database. You can use the path value to load the value of any config row.

Example: we need to find out what language locale the current store is using. We can do this by getting the value for the general/locale/code path:



cale = Mage::getStoreConfig('general/locale/code');



 

For English stores this will return something like: en_US.

 

I hope this makes sense and is useful to someone. Any questions or problems, please post in the comments!

 

$configValue = Mage::getStoreConfig('sectionName/groupName/fieldName');

 

实例1 Get store contact telephone



 

That's a Core configuration, so it's saved in core_config_data table, and the phone information is the field: general/store_information/phone So, all you need is to read the configuration data as

$storePhone = Mage::getStoreConfig('general/store_information/phone');

For CMS pages insert the following variable:



{{config path="general/store_information/phone"}}

 


You can find more info on this here, and you can always do the reverse programmatically



 

实例2 magento get store configuration:

 

How to get Magento system configuration value? It's easy:

Mage::getStoreConfig($path, $storeCode) // $storeCode is not required

 

for example you need to get value set for store phone number from system config:

Mage::getStoreConfig('general/store_information/phone');

 

Also, you can get configuration value as true or false like this:

Mage::getStoreConfigFlag('general/store_information/phone'); // return true
Mage::getStoreConfigFlag('general/yes_no/choice'); // true or false based on selection

 

 

实例3 Get Store Email Addresses:

 



General Contact

/* Sender Name */
Mage::getStoreConfig('trans_email/ident_general/name'); 
/* Sender Email */
Mage::getStoreConfig('trans_email/ident_general/email');

Sales Representative

/* Sender Name */
Mage::getStoreConfig('trans_email/ident_sales/name'); 
/* Sender Email */
Mage::getStoreConfig('trans_email/ident_sales/email');

Customer Support

/* Sender Name */
Mage::getStoreConfig('trans_email/ident_support/name'); 
/* Sender Email */
Mage::getStoreConfig('trans_email/ident_support/email');

Custom Email 1

/* Sender Name */
Mage::getStoreConfig('trans_email/ident_custom1/name'); 
/* Sender Email */
Mage::getStoreConfig('trans_email/ident_custom1/email');

 

Custom Email 2

/* Sender Name */
Mage::getStoreConfig('trans_email/ident_custom2/name'); 
/* Sender Email */
Mage::getStoreConfig('trans_email/ident_custom2/email');

 



 

举报

相关推荐

0 条评论