So ZenCart has a massive back-end that even the most experienced Zenners can get lost in. Even with all the menus and obscene amount of options, there aren't any settings to configure for the centerboxes.
The only way to customise these boxes is to edit the code. Luckily, the ZenCart guys have put all the product lookup functions in
/includes/functions/functions_lookup.php, and have lookups for both the category and the description. We can drop those functions in to the centerbox code quite easily, even though their FAQs and knowledgebase don't really mention it much.
Read on if you're interested in seeing a breakdown of how it's done, or you can jump right to the solution.
1. Backing up and Overriding
The first step is to create some overrides for the files we need to edit, rather than editing the core file.
Fire up your FTP client and go to
/includes/modules/. Download the centerbox you would like to edit. In this example I'll do the featured products box. So download
featured_products.php. If there isn't already, create a folder with the same name as your template.
Upload the file you just created in to this folder, and start editing.
2. Adding the Category Name
If you're using a template that's based on the default "contemporary green" template, the line you need to find should be 73, and should start with
'text' => (($featured_products.
In this line, find where the product name is displayed. The bit of code we're looking for is:
Directly after the link (or
h1 in my case) ends, add the following code:
<h2>' . zen_get_category_name($featured_products->fields['master_categories_id'], $_SESSION['languages_id']) . '</h2>
zen_get_category_name takes two values. The first is the category id, which featured_products already creates for you as
$featured_products->fields['master_categories_id'] and the second value is the language. You can get the users language by using
$_SESSION['languages_id']. This function will result in printing out the category name.
If you've put a h1 around your product title your line should now look like this:
Save the file and you should now see the category listed right under the title for your featured products.
3. Adding the Description
Directly after the
h2 ends, add the following code:
There are a few nested functions here.
zen_trunc_string asks ZenCart how many characters the description should be before it truncates it. The default is 150. This can be changed in the your admin settings. The
stripslashes are functions that remove any HTML so you don't end up messing up your layout with cut off code.
zen_get_product_description is the function that finds the description for the product. It takes the product id and the language. The products id is conveniently accessed via
4. The Whole Lot
After all of that, your text line should end up like so. If you're just joining us, this should be around line 73 in
Save your file and refresh your page. Voila! Product title, product category, product description and price, all listed in the box.
With a little bit of styling, you end up with something like this: