Add custom Admin configuration field setting for Zencart

Have you created your own module for Zencart? And you would like to add configuration setting for your module, so that your client can configure your module via Admin area? Here is how to do that…

What I do usually is adding new group (with your module name) under Configuration in zencart administrator, then add fields under that group to be setup. Just like if you go to Configuration > My Store, you will find many settings there. All of this fields are declared inside your database, specifically inside zen_configuration_group and zen_configuration table (NB: zen_ is used as table prefix).

So let’s insert new row to your zen_configuration_group to create new group under “Configuration” menu. The following SQL script will add “My New Module” group under “Configuration” menu and position it in the last order. Use this script as template.

1
2
3
4
5
INSERT INTO configuration_group
(configuration_group_id, configuration_group_title, configuration_group_description, sort_order, visible)
VALUES (NULL, 'My New Module', 'My New Module Description....', '1', '1');
 
UPDATE configuration_group SET sort_order = last_insert_id() WHERE configuration_group_id = last_insert_id();

Secondly, to add config items under your new “Configuration > My New Module” use the following SQL

1
2
3
4
5
6
7
8
9
SET @last_id=0;
SELECT (@last_id:=configuration_group_id) AS last_id 
FROM configuration_group
WHERE configuration_group_title= 'My New Module';
 
INSERT INTO configuration 
(configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added)
VALUES 
('', 'Small Image Height', 'IMAGE_VIEWER_SMALL_IMAGE_HEIGHT','75','Description of Small Image Height Setting. Default 75.', @last_id, 1, now());

Note that to run this SQL smoothly without bothering with your zencart database table prefix, execute this script from zencart admin area Tools > Install SQL Patches.

Once you executed those SQL, you will find My New Module category under Configuration menu and Small Image Height setting inside that category. You can then access the value of this configuration from your module straight away by using configuration_key which you have set in your SQL (i.e. echo IMAGE_VIEWER_SMALL_IMAGE_HEIGHT). Please leave comment if you find any difficulties or feel grateful with this blog. Cheers.

Send HTML Newsletter Email to Admin Zencart 1.3.8

In my last project, I designed new newsletter template and created custom newsletter administration area. When I send newsletter to admin to test the email, it does not send HTML email but plain text mail. Scratching my head, I searched Zencart documentation as well as Google for couple hours to find the answer. Now, I will share the solution here, just in case you go through the same pain as me.

First of all, you need to configure your Zencart to use HTML type email. Login to your administrator area and go to configuration > E-mail options.

  1. Make sure your “E-Mail Transport Method” is set appropriately
  2. Use MIME HTML When Sending Emails = “true”
  3. Send E-Mails = true
  4. Email Admin Format? = HTML

Now try to send a newsletter to the admin, if it still sends plain text mail, do the following. Backup and open in your text editor includes/functions/functions_email.php. In your functions_email.php try to find these codes

120
121
122
if (ADMIN_EXTRA_EMAIL_FORMAT == 'TEXT' && substr($module,-6)=='_extra') {
        $email_html='';  // just blank out the html portion if admin has selected text-only
}

Just below that add the following codes

125
126
127
128
// if no customer email record found, and admin email format is set to HTML, and sending newsletter, and admin is logged in, use HTML:
if ($customers_email_format_read->RecordCount() == 0 && ADMIN_EXTRA_EMAIL_FORMAT == 'HTML' && in_array($module, array('newsletters', 'product_notification')) && isset($_SESSION['admin_id'])) {
     $customers_email_format = 'HTML';
}

Now, you should send email in HTML format. Leave comment if it does not work for you or if this post has helped you and save your time.

Integrate Zencart 1.3.8 with phpbb3

These are steps to integrate zencart 1.3.8 with phpBB 3.0.1. These steps will ensure if a user create an account in Zencart, an account for the phpBB will also be created and your phpbb3 display appropriate Total number of user and Newest Member nickname at the board index.

1. Install your phpbb3 and ensure it runs perfectly.

2. Open your configure.php inside /includes folder of your Zen-Cart installation and edit this configuration define(‘DIR_WS_PHPBB’, ‘…..Your  Path to your phpbb3 ….’); with correct physical path to your phpbb installation. It must be your physical path! NOT your relative path. For example of physical path see your ‘DIR_FS_CATALOG’ value inside the same configure.php (ensure you have ‘/’ at the end of the path).

3. Enable link to your phpbb3 from your zencart administrator. Inside your zencart administrator go to “Configuration” -> “My Store” and set “Enable phpBB Linkage?” to TRUE.

4. edit class.phpbb.php inside your …/includes/classes folders. Try to find phpbb_create_account function and replace with the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function phpbb_create_account($nick, $password, $email_address) {
	if ($this->phpBB['installed'] != true || !zen_not_null($password) || !zen_not_null($email_address) || !zen_not_null($nick)) return false;
	if ($this->phpbb_check_for_duplicate_email($email_address) == 'already_exists') {
		// $this->phpbb_change_email($old_email, $email_address);
	} else {
		$sql = "select max(user_id) as total from " . $this->phpBB['users_table'];
		$phpbb_users = $this->db_phpbb->Execute($sql);
 
		$user_id = ($phpbb_users->fields['total'] + 1);
		$sql = "insert into " . $this->phpBB['users_table'] . "(user_id, group_id, username, username_clean, user_password, user_email, user_regdate) values ('" . (int)$user_id . "',2, '" . $nick . "', '" . $nick . "', '" . md5($password) . "', '" . $email_address . "', '" . time() ."')";
		$this->db_phpbb->Execute($sql);
 
		$sql = "update phpbb_config SET config_value = '{$user_id}' WHERE config_name = 'newest_user_id'";
		$this->db_phpbb->Execute($sql);
 
		$sql = "update phpbb_config SET config_value = '{$nick}' WHERE config_name = 'newest_username'";
		$this->db_phpbb->Execute($sql);
 
		$sql = "update phpbb_config SET config_value = config_value + 1 WHERE config_name = 'num_users'";
		$this->db_phpbb->Execute($sql);
 
		$sql = "INSERT INTO " . $this->phpBB['user_group_table'] . " (user_id, group_id, user_pending) VALUES ($user_id, 2, 0)";
		$this->db_phpbb->Execute($sql);
	}
}

5. Enjoy your nicely integrated phpbb3 forum with zencart. From now on, if a user register an account in Zen-Cart, they will be registered in PHPBB as well.

If you have follow my instruction correctly, now when you create new account in Zen-Cart you will be asked to provide “Forum Nick Name”. You can login in the forum using the Forum Nick Name you have provided and your Zencart password.

Optional: You can manually copy Zen-Cart account that has been setup previously to phpbb user database to integrate them. Next, you can create theme that reflect your store for your phpBB forum. I will not go into detail in here and ZC developers should be able to do these. PS: if you find better solution please let me know 🙂

Setup Zen-cart for non-English Language

Within the last couple of days, I have been stressfully tried to upgrade Zencart shop with French language. I have backup the same data in the old database exactly, and move it to my workstation. I have installed French language pack for zen-cart, but it does not work. The special characters in French / other languages (i.e. é, à, ç and the like) was rendered differently (become ê, é, etc.).

At first, I thought the problem was on the database. Since I am not allowed to upload any new files to the server and I don’t want to create security risk by uploading phpmyadmin, so I used MySQL Administration tools to process the database. I have tried to use backup function and MySQL Migration tool but the characters on the web page is still faulty. I have also tried to change the collation and database type from “latin” to “utf8”, but again it did not work.

Finally, I just figured out that it has nothing to do with the database. I just have to change the CHARSET of the html page of the zencart, which can be modified from the language file (English.php, French.php, etc.). The strange characters was rendered differently because It was rendered using iso-8859-1 not UTF-8. The solution is to modify the following line “define(‘CHARSET’, ‘iso-8859-1’);” into “define(‘CHARSET’, ‘utf-8’);”.