Jump to content

Writing new field into the config database?


Guest Brivtech

Recommended Posts

Guest Brivtech

I'm a bit stuck here, probably because of the encryption. How do I add in values to the CC config database?

I don't seem to be able to edit the fields.

I'm trying to create a new option in admin/index.php. It's pretty straight forward adding in a form, but it's the array handling that's giving me grief.

Let's say for example, I want an option to switch light on or off. (Nice easy example)...

<!-- START: Light Switch Option MOD -->

<tr>

<td colspan="2" class="tdTitle"><?php echo $lang['admin']['settings']['Switch_Title'];?></td>

</tr>

<tr>

<td width="30%" class="tdText"><strong><?php echo $lang['admin']['settings']['Switch_Option_Text'];?> </strong></td>

<td align="left">

<select name="config[Switch_Status]" class="textbox">

<option value="1" <?php if($config['Switch_Status']==1) echo "selected='selected'"; ?>><?php echo $lang['admin']['settings']['Switch_On'];?></option>

<option value="0" <?php if($config['Switch_Status']==0) echo "selected='selected'"; ?>><?php echo $lang['admin']['settings']['Switch_Off'];?></option>

</select></td>

</tr>

<!-- END: Light Switch Option MOD -->

So, in the above example:

- I've entered the text into the relevant section of lang.inc.php, so it can be translated easier later on, this is reflected in the use of $lang['admin']['settings']['reference"], and that's no problem.

- I'm using a variable called "switch_state" that would be the field from the array, which again, is something that I should be able to access later on.

But the problem is - How do I get the switch state to become a field within the _CubeCart_config database, and how do I access/write the record data (1 = on, 2 = off)?

Anyone out there able to help? Or is there a better way of doing it?

Link to comment
Share on other sites

You do not need to create a field in the db for info in config settings, you simply code what you need into admin/settings/index.php rather than admin/index.php

In your example: If you want a light switch to set on or off, just copy the code for any other switches you see there, and create your new one by analogy that way. For instance, Latest Products can be switched on or off, so you can copy the code related to that "switch" and by analogy create a new one. Put new unique names/tags where called for. That's it. Your info will be stored in config file along with everything else on that page, and you can use it like this: $config['switchName']==1 or $config['switchName']==0

You are better to code a switchName with value of either 1 or 0 on select, rather than a 'switchOff' vs. 'swichOn' and I would advise reading and learning from Al's existing code than trying to create your own from scratch for something this simple.

Hope this helps :)

Link to comment
Share on other sites

Guest Brivtech

Hi Mark, many thanks for your reply, but you didn't read the code properly. :huh:

Switch_On and Switch_Off were referenced in the language config file, whereas $config['Switch_Status'] was used for the 1/0 on/off value.

Also, I had a typo :lol: ...

You do not need to create a field in the db for info in config settings, you simply code what you need into admin/settings/index.php rather than admin/index.php

That's actually where I was codeing it. Oops. However, it's one thing to add in an option, another to store the value so it can be used everywhere else.

The problem I have, is being able to get this variable's value from various parts of cubecart, not just within the config page. The point here is that it will become a new global variable, and I believe I would need to get into the database to store and fetch the value of this variable for it to work properly. I need to set up several new global variables like this for some adaptions I'm working on.

Unlike the language config file, the system variables are encrpyted directly into the database.

The code example I gave in my post was actually taken from the view store offline on/off code in the index.php file, adapting it with new variable names, but as you can see, the offline setting makes use of the database config table.

The problem therefore still remains, how do I add a new field (switch_status) into the config data array when it's all encrypted?

I've thought about creating my own config file (Like a "MOD_config.inc.php" type thing), but it would be so much easier simply including the global variables in a page rather than having to include the extra config file every time it's needed.

Link to comment
Share on other sites

What Mark told you is 100% correct. You're not understanding how the $config variable works. $config is an array. The array is then serialized and base64_encoded to be stored as one item. So any key you add to that array will be not only stored, but retrieved every time CC is run....from ANY page whether it's on the Admin side or the customer side.

This is the beauty of the way it's coded. Adding more stuff is cake. :lol:

:huh:

Link to comment
Share on other sites

Guest Brivtech

What Mark told you is 100% correct. You're not understanding how the $config variable works.

LOL! Obviously I'm not. I'm actually really struggling to get to grips with this.

I know it's an array...

I know how to use it as a variable...

From what both you and Mark said, I'm making an assumption here - I don't need to actually fiddle around in the database, by simply adding my config[switch_Status] into the config file, when the settings are updated through the page, it'll do all the work for me straight away?

If that's the case (and this is a completely new concept to me) that's awesome...

This is the beauty of the way it's coded. Adding more stuff is cake. :D

:huh:

is an understatement! :lol:

I'm going to try this out straight away and see what happens!

EDIT:

YES YES YES!

It worked brilliantly!

I needed to set the value to start with because the form displays the current value by default. once I had done that, each time I submitted the settings page with an updated value, it worked!

YAHOO!

I feel like a whole new area of CuebCart has been opened up to me.

Many thanks for both your help with this, I can't begin to tell you how appreciated it is. B)

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.

×
×
  • Create New...