西部数码主机 | 阿里云主机| 虚拟主机 | 服务器 | 返回乐道官网
当前位置: 主页 > php教程 > zencart教程 >

zencart新增categories分类表字段步骤

时间:2016-02-19 01:32来源: 作者: 点击:
zencart新增分类字段步骤 1.categories表新增字段related_categories、related_products ALTER TABLE `categories` ADD `related_categories` VARCHAR( 255 ) NOT NULL , ADD `related_products` VARCHAR( 255 ) NOT NULL; 2.修改admin\categ

zencart新增分类字段步骤

1.categories表新增字段related_categories、related_products

ALTER TABLE `categories` ADD `related_categories` VARCHAR( 255 ) NOT NULL , ADD `related_products` VARCHAR( 255 ) NOT NULL;

2.修改admin\categories.php

大概212行

$insert_sql_data = array('parent_id' => $current_category_id,
                                 'date_added' => 'now()');

改为

$insert_sql_data = array('parent_id' => $current_category_id,
                                 'date_added' => 'now()',
                                 'related_categories'=>$_POST['related_categories'],
                                 'related_products'=>$_POST['related_products']);


大概239行

$update_sql_data = array('last_modified' => 'now()');

改为

$update_sql_data = array('last_modified' => 'now()','related_categories'=>$_POST['related_categories'],'related_products'=>$_POST['related_products']);

大概776行
在代码

$contents[] = array('text' => '<br />' . TEXT_CATEGORIES_DESCRIPTION . $category_inputs_string);

下面一行新增

$contents[] = array('text' => '<br />关联分类ID(ID之间用英文半角逗号隔开)<br />' . zen_draw_input_field('related_categories', '', zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name')));
$contents[] = array('text' => '<br />关联产品ID(ID之间用英文半角逗号隔开)<br />' . zen_draw_input_field('related_products', '', zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name')));


大概834行
在代码

$contents[] = array('text' => '<br />' . TEXT_CATEGORIES_DESCRIPTION . $category_inputs_string);

下面一行新增

$contents[] = array('text' => '<br />关联分类ID(ID之间用英文半角逗号隔开)<br />' . zen_draw_input_field('related_categories', zen_get_related_categories($cInfo->categories_id), zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name')));
$contents[] = array('text' => '<br />关联产品ID(ID之间用英文半角逗号隔开)<br />' . zen_draw_input_field('related_products', zen_get_related_products($cInfo->categories_id), zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name')));


3.admin\includes\functions\extra_functions\目录下新建文件extra_functions.php
写入以下代码:

复制代码
<?php

function zen_get_related_categories($category_id) {
    global $db;
    $category = $db->Execute("select related_categories
                              from " . TABLE_CATEGORIES . "
                              where categories_id = '" . (int)$category_id . "'");
    return $category->fields['related_categories'];
}

function zen_get_related_products($category_id) {
    global $db;
    $category = $db->Execute("select related_products
                              from " . TABLE_CATEGORIES . "
                              where categories_id = '" . (int)$category_id . "'");
    return $category->fields['related_products'];
}  

?>
复制代码

 

4.前台显示新增字段,includes\functions\extra_functions\目录下新建文件extra_functions.php

写入以下代码:

复制代码
<?php

function zen_get_related_categories($category_id) {
    global $db;
    $category = $db->Execute("select related_categories
                              from " . TABLE_CATEGORIES . "
                              where categories_id = '" . (int)$category_id . "'");
    return $category->fields['related_categories'];
}

function zen_get_related_products($category_id) {
    global $db;
    $category = $db->Execute("select related_products
                              from " . TABLE_CATEGORIES . "
                              where categories_id = '" . (int)$category_id . "'");
    return $category->fields['related_products'];
}  

?>
复制代码

接着,在前台页面tpl_index_categories.php、tpl_index_product_list.php里面适当位置调用新增字段值

echo zen_get_related_categories($current_category_id);
echo zen_get_related_products($current_category_id);

打完收工!

(责任编辑:好模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容