Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Add Custom Category Menus for 4.2

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 04-07-2009, 10:18 PM
 
vixnfox vixnfox is offline
 

Advanced Member
  
Join Date: Feb 2006
Location: Adelaide, South Australia
Posts: 82
 

Default Add Custom Category Menus for 4.2

Add Category Menus X-Cart 4.2

This will allow you to add category menus to your x-cart instead of using just the one “Categories” menu installed by default.

I am using x-cart 4.2 and this was developed on a windows XPSP3 laptop using TopStyle Pro and WAMP Server 2.0
PLEASE BACK UP YOUR DATABASE AND EXPORT YOUR SHOP FIRST!!!

I have an online jewellery store and I wanted 2 menus, one for sterling silver and one for 9ct gold. Here is how I did it. From this example you will be able to add further category menus and customize for your own needs.

Decide on what menus you want. I wanted one named Sterling Silver, and one named 9ct Gold.
Step 1:

You need to go to your admin->languages
edit language “English”
Select Topic “labels”
Add New Entry
Variable: lbl_sterlingsilver, value Sterling Silver
Add New Entry
Variable: lbl_9ctgold, value 9ct Gold

Enable a categories menu entry in the database[

Step 2:
Using phpMyAdmin or whatever you use to get under the hood of your database do the following:
Open up your xcart database and select the xcart_categories table.
Click on the Structure Tab
On the bottom, you have the option to add a field. We want to add a field AFTER the categoryid_path field, select and click GO button.
Name the field “catmenu”,
Set type to VARCHAR with a length of 12 (you can use more but might wrap the menu text)
Set Default to “as Defined”, and name it “stgsilver” (or whatever you want your core menu name to be. You can call it “categories”if you want)
This will be the default menu used when you add a category in admin.

Step 3:
We need to make the “catmenu” field appear in $categories_menu_list, so we need to edit the file

/include/func/func.category.php

Around line 539, add this $sql_tbl[categories].catmenu, after this $sql_tbl[categories].categoryid, (it appears twice)
So it looks like this:
Code:
if ($short_list === X_CATEGORIES_FOR_SELECT_BOX) { $to_search = "$sql_tbl[categories].categoryid as cid, $sql_tbl[categories].categoryid, $sql_tbl[categories].catmenu, $sql_tbl[categories].parentid, $sql_tbl[categories].categoryid_path, $sql_tbl[categories].category"; } elseif ($short_list) { $to_search = "$sql_tbl[categories].categoryid as cid, $sql_tbl[categories].categoryid, $sql_tbl[categories].catmenu, $sql_tbl[categories].parentid, $sql_tbl[categories].categoryid_path, $sql_tbl[categories].category, $sql_tbl[categories].avail, $sql_tbl[categories].order_by"; } else { $to_search = "$sql_tbl[categories].categoryid as cid, $sql_tbl[categories].*";

Step 4:

Make 2 copies of Skin1/customer/categories.tpl
Name one sterlingsilver.tpl, the other gold.tpl
Open up each in your html editor (or notepad if you wish)
Look for this code:
Code:
<ul> {foreach from=$categories_menu_list item=c} <li><ahref=home.php?cat={$c.categoryid} title="{$c.category|escape}">{$c.category}</a></li> {/foreach} </ul>

and add this line
{if $c.catmenu eq'stgsilver'} {*OR WHATEVER YOU CALLED IT *******}
and this {/if} so it looks like this:

Code:
<ul> {foreach from=$categories_menu_list item=c} {* this is where our catmenu from step 3 is used *) {if $c.catmenu eq'stgsilver'} {*OR WHATEVER YOU CALLED IT *******} <li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}">{$c.category}</a></li> {/if} {/foreach} </ul>


Last line is:
{include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}

Change it to
{include file="customer/menu_dialog.tpl" title=$lng.lbl_sterlingsilver content=$smarty.capture.menu}

Save the file and then repeat this process for the other file gold.tpl (so $c.catmenu eq’gold’, and $lng.lbl_9ctgold)

Step 5:
Open up /skin1/customer/home.tpl and look for:

{include file="customer/categories.tpl" }

I replaced mine and added the new menu so it looks like this:
{include file="customer/sterlingsilver.tpl" }
{include file="customer/gold.tpl" }

Make the entry show up in the Admin modify category page

Step 6:
Open the file skin1\admin\main\category_modify.tpl

Around line 85 is this:
Code:
<td height="10"> <input type="text" name="order_by" size="5" value="{if $category_error ne ""}{$smarty.post.order_by}{elseif $mode ne "add"}{$current_category.order_by}{/if}" /> </td> </tr>
Directly after the </tr> tag paste this code:
Code:
{* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *} <tr> <td height="10" class="FormButton" nowrap>Category Menu:</td> <td width="10" height="10"></td> <td height="10"> <SELECT name="cat_menu"> <OPTION value="{$current_category.catmenu}">{$current_category.catmenu}</OPTION> <OPTION value="stgsilver">stgsilver</OPTION> <OPTION value="gold">gold</OPTION> (* add other categories here *} </SELECT> </td></tr> {if $current_category.catmenu eq ""} <tr> <td height="10" class="FormButton" nowrap>New Category Menu:</td> <td width="10" height="10"></td> <td hdeight="10"> <INPUT type="text" name="newcatmenu" maxlength="12" size="15" value="NEW"> </td> </tr> {/if} {* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *}

Write the information to the database

Step 7:

Open the file admin\category.modify.php
Note: This is under the Root (shop, store whatever), NOT skin1\admin !!!

Around line 188 is this
Code:
# Update general data of category # $data = array( "category" => $category_name, "description" => $description, "meta_description" => $meta_description, "meta_keywords" => $meta_keywords, "avail" => $avail, "order_by" => $order_by, "override_child_meta" => $override_child_meta );
Above $data = array
( insert this code:
Code:
#added $cat_menu = $_POST['cat_menu']; if ($cat_menu == "") { $cat_menu=$_POST['newcatmenu']; } #end added
And in the $data array add this line

"catmenu" => $cat_menu,

Se we have:
Code:
# Update general data of category # #added $cat_menu = $_POST['cat_menu']; if ($cat_menu == "") { $cat_menu=$_POST['newcatmenu']; } #end added $data = array( "category" => $category_name, "catmenu" => $cat_menu, "description" => $description, "meta_description" => $meta_description, "meta_keywords" => $meta_keywords, "avail" => $avail, "order_by" => $order_by, "override_child_meta" => $override_child_meta );

If I were smarter, I would have a menus table in xcart where I could fill in the details in
skin1\admin\main\category_modify.tpl

<SELECT name="cat_menu">
<OPTION value="{$current_category.catmenu}">{$current_cate gory.catmenu}</OPTION>

<OPTION value="stgsilver">stgsilver</OPTION>
<OPTION value="gold">gold</OPTION>
(* add other categories here *}

</SELECT>
If anyone can write a routine to do this, please let me know, else it is not too much trouble to just add another menu to the options list.

I hope you find this useful.

Vixnfox
http://ifgdesignz.com.au
__________________
V 4.3.1 Live:

Developing on
PHP 5.3.0
MySQL server 5.0.75-community-log
MySQL client 5.1.36
Web server Apache/2.2.11 (Unix) mod_ssl/2.2.11
Windows 7 64bit on a Toshiba Satellite P500

ADELAIDE, SOUTH AUSTRALIA
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:56 PM.

   

 
X-Cart forums © 2001-2020