How to setup Zencart TEXT attribute for your product

Zencart provides you option to display attributes of your products on the product info page. You can display attributes in radio button, checkbox, dropdown etc controls.
Zencart also provides you the option of displaying text boxes where you can take input from the customer and you can charge the customer for it. This is a good option
but sometimes it does not work as intended due to corrupt template files or conflict due to other modules.

Here I will try to add a TEXT attribute and associate it with a product and then list the most common problem associated with it

If you would like to use TEXT attribute in Zencart please do the following steps

1. Click on Option Name Manager in the Catalog menu

2. Add the option name and select TEXT from the drop down

3. After saving it proceed directly to the Attribute Controller page. Remember we do not need to add any value to the TEXT attribute on the option value manager page.

4. Select the product against which you would like to add the TEXT attribute. The in the Option Value drop down you should see TEXT [RESERVED FOR TEXT/FILE ONLY ATTRIBUTES]. Select it and add the price against it.

5. Click on Insert button and you should see the TEXT attribute against that product on the page.

If you see the TEXT attribute against the product which you have added and it is calculating the price of the product as well as the attribute on the shopping cart page then your system is working correctly and you have nothing to worry about.

If not then you should do the following steps

1. Run the following statements on mySQL or in the Zencart Install SQL patches

INSERT INTO `configuration` VALUES ('', 'Product option type Select', 'PRODUCTS_OPTIONS_TYPE_SELECT', '0', 'The number representing the Select type of product option.', 0, NULL, '2007-03-19 17:57:39', '2007-03-19 17:57:39', NULL, NULL);
INSERT INTO `configuration` VALUES ('', 'Upload prefix', 'UPLOAD_PREFIX', 'upload_', 'Prefix used to differentiate between upload options and other options', 0, NULL, '2007-03-19 17:57:39', '2007-03-19 17:57:39', NULL, NULL);
INSERT INTO `configuration` VALUES ('', 'Text prefix', 'TEXT_PREFIX', 'txt_', 'Prefix used to differentiate between text option values and other option values', 0, NULL, '2007-03-19 17:57:39', '2007-03-19 17:57:39', NULL, NULL);
INSERT INTO `configuration` VALUES ('', 'Image Handler Version', 'IH_VERSION', '2.0', 'This is used by image handler to check if the database is up to date with uploaded image handler files.', 0, 100, NULL, '2007-06-06 16:47:03', NULL, 'zen_cfg_textarea_small(');  

2. Run the following statement if you don’t see the TEXT [RESERVED FOR TEXT/FILE ONLY ATTRIBUTES] in the Option Value drop down on the Attribute Controller page

INSERT INTO products_options_values (products_options_values_id, language_id, products_options_values_name) VALUES (0, 1, 'TEXT');

After running the above SQL statements you should be fine and everything should work correctly. If you still face a problem then do let me know.

How to display state/province dropdown instead of input box in Zencart

In the default Zencart template the customer is asked for his State/Province by entering the value into the text box. However, mistakes can happen at any time and the customer may mistype the name. Zencart checks the name against the zones input in the admin panel. If it does not match Zencart flags an error and the customer has to retype it thus causing frustration which may lead to lost sales.

The way to go is display the State/Province in a drop down so the customer has to just select the name in the drop down and continue with the checkout process.

To do that you need to open the includes/modules/create_account.php file and go to the end of the file where you will see the following line

 $flag_show_pulldown_states = ((($process == true || $entry_state_has_zones == true) && $zone_name == '') || ACCOUNT_STATE_DRAW_INITIAL_DROPDOWN == 'true' || $error_state_input) ? true : false;

This is code which determines whether or not to show the drop down. Now you can either confirm that all the conditions are true or take the practical (aka shorter) route and comment the line and add the following code on the next line. So the above line would look like

// $flag_show_pulldown_states = ((($process == true || $entry_state_has_zones == true) && $zone_name == '') || ACCOUNT_STATE_DRAW_INITIAL_DROPDOWN == 'true' || $error_state_input) ? true : false;

$flag_show_pulldown_states = true;

Now if you run the register page you can see that the dropdown will show.

Hope the above helped.

How to add an input field in a delivery module in Zencart?

I was working on implementing the Royal Mail Airmail and DPD International delivery modules for a client. His website had been developed in Zencart and he wanted to use Royal Mail and DPD on his website. As there was no ready to use module available for these two so I got down to developing my own module.

After studying the formula provided by the client I decided it was best to hack the Zones delivery module (provided in Zencart 1.3.8 by default) and use it for the task in hand. After completing the module and testing it I deployed the code online. However, as luck would have it, client wanted to customize it further by allowing him to change the rate of VAT. Currently the rate of VAT is 15% in the UK but this would be increased to 17.5% in the year 2011 so he wanted to change the rate as and when he wanted.

So, I did the following changes in the includes/modules/shipping/<module_file>
where module_file is the name of the file I have created for my function. Your file can have any other name.

I added the following line in the function install()

$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('VAT', 'MODULE_DPDINTERNATIONAL_VAT', '', 'Enter rate of VAT:', '6', '1', 'zen_cfg_textarea(', now())");

To let the system know that VAT is an input field I had to add the key MODULE_DPDINTERNATIONAL_VAT in the keys array in the function keys().
I added it at the end.

To let Zencart know of this change I removed the module and reinstalled it and the input box for the VAT came up. I added the 15% in the input box and saved it. The system performed the calculations perfectly and

Hope the above helped.

What is the minimum mySQL version requirement for Zencart?

A client of mine developed his website in Zencart and after careful scrutiny approved the website for deployment to his production machine. He provided the FTP and mySQL information for us to deploy the website.

As is the practice, I check for any version conflicts that may conflict with our system before I give the signal to my team for deployment. Howsoever was I in for a shock. When I checked the mySQL version using the following statement

SELECT VERSION()

I got the result 4.1.x which was not compatible with our system. The minimum mySQL version supported by the latest Zencart version 1.3.8 is 4.3.x.

I at once updated the client of this and realizing his mistake he contacted his hosting support to have the issue resolved.

This just goes to show you that you need to check everything and not leave anything to others no matter who they are because mistakes can happen at any time and at any time. They don’t need a reason to come up so DON’T GIVE THEM THAT REASON.

Hope the above helped

How to implement CAPTCHA on Zencart registration forms?

A client of ours was facing an issue with spam registrations on his website. We had developed his website on Zencart. The issue was that spam bots were registering on his website in the hundreds and the client wanted us to put a stop to this.

I decided on implementing CAPTCHA on the registration forms so that these unwanted registrations are stopped. I browsed the Zencart website and found the CAPTCHA Anti-Robot Registration mod.

I downloaded and, as is the practice, copied the files to the relevant directories. After copying over the files, however, it was not working smoothly. I then made some changes to the includes/modules/create_account.php file and it started working on our local development machine.

After checking several times I moved the files to our production server. Our production server was running PHP 4.3.3 and the code stopped working online as it was developed keeping in mind PHP 5. I again made the changes in the includes/modules/create_account.php and includes/templates/<your_template_folder>/templates/tpl_modules_create_account.php file and it started working online too.

Just beware of PHP and its versions or you’ll get into a lot of trouble 🙂

Hope the above helped

Zencart ver. 1.3.8 security update

A vulnerability has been discovered in the admin section of v1.3.8 (and previous versions). To take advantage of this vulnerability any attacker must know the URL of your admin section

Please apply the following updates

1. RENAME YOUR ADMIN FOLDER !!!!!
Yes, if you haven’t already renamed your /admin/ folder, do it NOW!
Instructions can be found here: http://tutorials.zen-cart.com/index.php?article=33

2. APPLY THE SECURITY PATCH !!!
http://www.zen-cart.com/forum/showthread.php?t=130161

3. Subscribe yourself to the Zen Cart Announcements mailing list:
http://www.zen-cart.com/forum/subscription.php?do=addsubscription&f=2

4. Keep your site’s Zen Cart software up-to-date at all times. Numerous bugs, improvements, and security fixes are included in every new release. It is in your best interests to remain current.
http://www.zen-cart.com/forum/forumdisplay.php?f=2

Hope the above helps

How to debug an error in Zencart

By default Zencart disables all types of errors. Due to this if an error is encountered then all you would see is the “dreaded white page” and that is bad programming practice if you are developing in PHP. As PHP is a scripting language it stops execution as soon as it encounters an error due to which you will have a hard time debugging your application. You will not only waste your time and effort but also some of the hair left on your head. I know I did. Just joking!

You need to enable error reporting in your application during development and disable it when deploying it to the production server.

Open the includes/application_top.php file. Search for error_reporting and you will encounter a block of code as follows

if (defined('STRICT_ERROR_REPORTING') && STRICT_ERROR_REPORTING == true) {
  @ini_set('display_errors', '1');
  error_reporting(E_ALL);
} else {
  error_reporting(0);
}

The code checks for a constant STRICT_ERROR_REPORTING and if its true then it enables error_reporting and also displays the errors on the web page. If its false (by default) then error_reporting is disabled. You need to define the constant as its not present in the code. Just add the following line before the if block and now the block of code will look like.

define('STRICT_ERROR_REPORTING', true);
if (defined('STRICT_ERROR_REPORTING') && STRICT_ERROR_REPORTING == true) {
  @ini_set('display_errors', '1');
  error_reporting(E_ALL);
} else {
  error_reporting(0);
}

Now when you run the website it will display all notices, warnings and errors. Don’t get scared if you see a lot of lines come up on the web page. This will help you to debug the issue and correct it. This also helps you in writing good code and provides you the opportunity to make the code as error free as possible.

Hope the above helps

Redirect from SSL URLs to non-SSL URLs in Zencart

A client of the company I work for pointed out a problem in which some how the SSL version of his website got indexed into Google and other search engines.  Now this posed a problem for the client as search engines don’t rank web pages well which can be referenced from two or more different urls.

As the website was in Zencart I knew that there was no option than to write code to effect redirection from SSL to non-SSL url.

So, I opened the html_header.php file present in the includes/templates/<Your_Template>/common folder and wrote the following code at the top:

<?php
if ($_SERVER['HTTPS'] == 'on') {
if (isset($_GET['main_page'])) {
$strMainPage = $_GET['main_page'];
switch($strMainPage) {
case 'index':
case 'product_info':
case 'privacy':
$strURL = "https://". $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
$arrFrom[] = "https://";
$arrTo[] = "http://";

$strURL = str_replace($arrFrom,$arrTo,$strUrl);
header("Location: $strUrl");
exit;
}
}
}
?>

The above code helped redirect those pages whose SSL version got indexed by mistake into the search engines. If you note from above I have not redirected post shopping cart pages as they need to be running in secure mode so that customer can enjoy safe and secure shopping.