View Single Post
  #7  
Old 08-02-2011, 12:26 AM
 
dmpinder dmpinder is offline
 

Advanced Member
  
Join Date: Jun 2009
Posts: 86
 

Wink Re: Adding new fields to category pages

Quote:
Originally Posted by Eyeglasses Expert
details, and sample code, pls!

Good news, I figured out how to do this myself, here is my method:



Version: X-Cart Gold 4.4.3

Steps for adding a new column to X-Cart category data

MySQL:
1. To create a new column in the `xcart_categories`, enter the following line into the SQL query box:
Code:
ALTER TABLE `xcart_categories` ADD `new_column` TEXT NOT NULL;

PHP:
2. Add the new column to the "// Prepare an array for further processing" array in \admin\category_modify.php using the following example:
PHP Code:
'new_column'              => $new_column

3. Create a new array for the new column in the $import_specification['CATEGORIES'] array in \include\import_categories.php using the following example:
PHP Code:
"new_column" => array(), 

If you need to set a default value, use the following example:
PHP Code:
"new_column" => array(
        
"default" => "0"), 

If you need to set a type, use the following example:
PHP Code:
"new_column" => array(
        
"type" => "B",
        
"default" => "0"), 

Smarty:
4. In the {$SkinDir}\main\product_details.tpl file add a new row for the new column so it is editable in the Admin area, for example:
HTML Code:
<tr> <td height="10" class="FormButton" nowrap="nowrap">New Column:</td> <td width="10" height="10"><font class="FormButtonOrange"></font></td> <td height="10"> <textarea cols="65" rows="4" name="new_column">{$current_category.new_column}</textarea> </td> </tr>

5. Place the Smarty tag to call the new data anywhere in a category page, using the following code:
HTML Code:
{$current_category.new_column}

NOTE: You may need to force a cache regeneration if you get an X-Cart SQL error (code 79). It will say there is a mis-match between sent data and database table structure, however this is usually a cache issue. Visit yoursite.com/cleanup.php and/or use "Force Cache Regeneration" in the Maintenance section of the admin area. This usually fixes the error. If not, double check your database structure.

NOTE: If the field you are creating will contain HTML tags, you need to include this new column into a "trusted post variables" array. You do this in \admin\category_modify.php
Inside: $trusted_post_variables = array('
Include: 'new_column',
__________________
Darren

X-Cart Gold 4.3.1
Reply With Quote