Jump to content

Resolved - Tech question - accessing config settings in plugin files


markscarts
 Share

Recommended Posts

All the store's settings are found at:

$GLOBALS['config']->get(config_name, element) where config_name is the major group, kind of like a namespace ('config' for the store's settings, and others like 'gift_certs', 'Contact_Form', 'Free-Shipping', and whatever $variable for the name of the module in play that the module handler is handling, etc) and element, which is optional, is the key into the first dimension of the array. If element is not present, the whole namespace is retrieved. As best I can tell, this is limited to one dimension.

The config class does not have the magic getter and setter functions. So this will not work: $GLOBALS['config']->namespace['keyname'], although I know that one of the classes does have these magic functions (Language, I think).

There are the companion ->set(), ->merge(), ->has(), and isEmpty().

Once the configuration values have been retrieved from a config xml file, or entered/edited on a form, they are saved to the CC_config database table. The metadata about the module is saved in the CC_modules table.

If there is a database record for the 'namespace', ->get() will fetch it if it's not already loaded into memory. ->set() will put the array to the database when PHP is shutting down. The settings are stored in base64 encoded, json format.

The config class is instantiated early in CubeCart's awakening cycle, so it should be available from wherever you are. But, during shut-down, there is no guarantee it will still be available at any particular point in time. If that's the case and you get errors of calls to methods of undefined objects, you will need to use:

Config::getInstance()->set(args).

To see all the Config stuff that is available to the skin, open controller.index.inc.php for editing at the bottom, just before offline();, add:

if( $GLOBALS['session']->has('super_user', 'admin_data') ) Smarty_Internal_Debug::display_debug($GLOBALS['smarty']);

An admin designated as 'Super User' must be logged in to the admin side, then viewing the store front. In this case, there will be a popup containing all the stuff the skins can use.

Link to comment
Share on other sites

@Dirty Butter, yes I am busy perusing the stock CubeCart files, I haven't found an instance where the store email address is retrieved yet.

@bsmithers, thank you I was hoping you might shed some light. Also, thanks for the tip on showing smarty globals. Presently, I am looking to retrieve a config value for store email for use in a php file as mentioned previously, and it won't be used in the template. You've given me some help with the discussion already, maybe I can figure out how to do this.

Link to comment
Share on other sites

If this is the email address found on the Advanced tab of the Store Settings, it is:

$GLOBALS['config']->get('config', 'email_name')

$GLOBALS['config']->get('config', 'email_address')

The Mailer class is one such class that uses this.

Each administrator has their own email address as well and is available when signed in. So, if a module is doing some admin work and the result of that work needs to be sent to that admin or to someone else from that admin, use:

$GLOBALS['session']->get('email', 'admin_data')

Link to comment
Share on other sites

Glad Bsmither could help - didn't notice who was asking when I stuck my 2 cents in - or I would have realized you had already checked the default plugins for clues. I'll rename this thread as Resolved when you're ready. For some reason the owner of the thread can't do that here, the way you can on the 3rd party forum.

Link to comment
Share on other sites

Thanks Dirty Butter, you can mark it resolved. I am way behind on CC5 and finding my way around a bit, I had not been very active in this forum since the days of CC3.

Brian has been and is a blessing to the community, very knowledgeable and very helpful, I appreciate you guys and your service to the community has been awesome.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...