I am going to update Shop_controller today.
Rather than manually updating Shop_controller.php, it is much better to add preferences or settings in the BackendPro.
BeP has an excellent manual and it explains about how to add ‘Preferences’.
Download Page
Shop_controller revisited
I am going to update the following lines by using ‘Preferences’ in BeP.
// main nav // this is ugly, I need to add to setting and pull it here for $parentid $tree = array(); $parentid = 107; $this->MMenus->generateTree($tree,$parentid); $this->data['mainnav'] = $tree; // left category menu // this is ugly too. Same as above. $parentid=1; $this->data['navlist'] = $this->MCats->getCatNav($parentid);
Settings.php
Open a file system/application/controllers/admin/settings.php.
After ‘maintenance’ in $config['group'], add ‘webshop’, name of setting page and names of fields as follows.
...
// Setup preference groups
$config['group'] = array(
...
...
'maintenance' => array('name'=> $this->lang->line('preference_page_maintenance_debugging_settings'), 'fields'=>'page_debug,keep_error_logs_for'),
'webshop'=> array('name'=> $this->lang->line('preference_webshop_configuration'),'fields'=>'main_nav_parent_id,categories_parent_id'),
);
...
After this you need to add rules and/or type of fields as follows. Please add them at the end of $config['field'] in the same file.
...
// for webshop
$config['field']['main_nav_parent_id'] = array('rules'=>'trim|numeric');
$config['field']['categories_parent_id'] = array('rules'=>'trim|numeric');
...
We also need to add ‘preference_webshop_configuration’ to system/application/language/english/backendpro_lang.php file as follows.
/* For Webshop */ $lang['preference_webshop_configuration'] = "Webshop Configuration";

By now you should see ‘Web Configuration’ link at the bottom of System>Settings in the back-end. And you can click to go to the Webshop Configuration page.
However we need to add fields in our db so that our preferences will be stored in the database.
Adding Fields in DB

All you need to do is go to be_preferences and insert two new fields, ‘main_nav_parent_id’ and ‘categories_parent_id’.
Then go back to the back-end System > Settings > Web Configuration, add your ‘Main Nav Parent Id’ and ‘Categories Parent Id’.
In my case 107 and 1.
You may ask ‘Where can I find them?’.
For your ‘Main Nav Parent Id’, go to General > Menus and find your root menu id which has ‘parentid’ 0.
In my case it has ’107′ for it’s ID.

(Click to enlarge)
To find ‘Categories Parent Id’, go to General > Categories and find ID which has ‘parent id’ 0.
In my case it has ’1′ for it’s ID.
Shop_controller.php update
Now we can use these preferences with $this->preference->item(‘name’) as follows
// main nav
// webshop config main_nav_parent_id
$tree = array();
// it used to be like this $parentid = 107;
$parentid = $this->preference->item('main_nav_parent_id');
$this->MMenus->generateTree($tree,$parentid);
$this->data['mainnav'] = $tree;
// left category menu
// webshop config categories_parent_id
// it used to be like this $parentid=1;
$parentid = $this->preference->item('categories_parent_id');
$this->data['navlist'] = $this->MCats->getCatNav($parentid);
Label and Description
At the moment it is ok, but it is better to have proper labels and adding descriptions for our new settings.
Open modules/preferences/language/english/preferences_lang.php and add the followings at the end of the file.
// for Webshop label and description $lang['preference_label_main_nav_parent_id'] = 'Main navigation ID for webshop'; $lang['preference_desc_main_nav_parent_id'] = 'In order to show your main navigation, enter the ID where parent id is 0 from Menus'; $lang['preference_label_categories_parent_id'] = 'Category ID for webshop'; $lang['preference_desc_categories_parent_id'] = 'Enter an ID for your webshop on the left column. Find it in the Categories';
Now you should have the following in your Webshop Configuration.

If you are using only one language, this method can be used for your shop messages. Rather than storing them in modules/webshop/language/english/webshop_lang.php, you can create series of messages and words in the back-end so that you can easily change them. This might be a better way especially if you are making CMS for your customers who knows little about coding.




















[...] Codeigniter shopping cart v1.1 Part 14: Adding webshop preferences [...]
[...] Read the original article [...]
[...] Codeigniter shopping cart v1.1 Part 14: Adding webshop preferences [...]
[...] Codeigniter shopping cart v1.1 Part 14: Adding webshop preferences [...]