ecshop实现文章扩展分类
2009-09-25 18:20 来源:www.chinab4c.com 作者:ecshop专家
1:模板article_info.htm中增加以下程序,用于扩展ecshop文章分类
 <tr>
            <td class="label">扩展分类</td>
            <td>
              <input type="button" value="{$lang.add}" onclick="addOtherCat(this.parentNode)" class="button" />
              {foreach from=$article.other_cat item=cat_id}
              <select name="other_cat[]"><option value="0">{$lang.select_please}</option>{$other_cat_list.$cat_id}</select>
              {/foreach}
            </td>
          </tr>
2:模板article_info.htm中增加以下JS,控制扩展分类
function addOtherCat(conObj)
  {
      var sel = document.createElement("SELECT");
      var selCat = document.forms['theForm'].elements['article_cat'];
      for (i = 0; i < selCat.length; i++)
      {
          var opt = document.createElement("OPTION");
          opt.text = selCat.options[i].text;
          opt.value = selCat.options[i].value;
          if (Browser.isIE)
          {
              sel.add(opt);
          }
          else
          {
              sel.appendChild(opt);
          }
      }
      conObj.appendChild(sel);
      sel.name = "other_cat[]";
      sel.onChange = function() {checkIsLeaf(this);};
  }
3:article.php中增加以下函数
编辑和扩展分类
function handle_article_other_cat($article_id, $cat_list)
{
    /* 查询现有的扩展分类 */
    $sql = "SELECT cat_id FROM " . $GLOBALS['ecs']->table('article_category') .
            " WHERE article_id = '$article_id'";
    $exist_list = $GLOBALS['db']->getCol($sql);
    /* 删除不再有的分类 */
    $delete_list = array_diff($exist_list, $cat_list);
    if ($delete_list)
    {
        $sql = "DELETE FROM " . $GLOBALS['ecs']->table('article_category') .
                " WHERE article_id = '$article_id' " .
                "AND cat_id " . db_create_in($delete_list);
        $GLOBALS['db']->query($sql);
    }
    /* 添加新加的分类 */
    $add_list = array_diff($cat_list, $exist_list, array(0));
    foreach ($add_list AS $cat_id)
    {
        // 插入记录
        $sql = "INSERT INTO " . $GLOBALS['ecs']->table('article_category') .
                " (article_id, cat_id) " .
                "VALUES ('$article_id', '$cat_id')";
        $GLOBALS['db']->query($sql);
    }
}
4:article.php中的act=insert中加入
if (isset($_POST['other_cat']))
    {
        handle_article_other_cat($article_id, array_unique($_POST['other_cat']));
    }
用于写入扩展分类ID和文章ID
5:article.php中的act=edit中加入
$other_cat_list = array();
        $sql = "SELECT cat_id FROM " . $ecs->table('article_category') . " WHERE article_id = '$_REQUEST[id]'";
        $article['other_cat'] = $db->getCol($sql);
       
        foreach ($article['other_cat'] AS $cat_id)
        { 
            $other_cat_list[$cat_id] = article_cat_list(0, $cat_id);
        }
        $smarty->assign('other_cat_list', $other_cat_list);
6:article.php中的act=update加以下代码
 if (isset($_POST['other_cat']))
     {
         handle_article_other_cat($_POST[id], array_unique($_POST['other_cat']));
     }
用来编辑扩展分类
6:建立数据表article_category
CREATE TABLE `ecs_article_category` (
  `article_id` int(1) DEFAULT NULL,
  `cat_id` int(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
 
最近更新
常用插件
- ecshop满多少件免运费
                                  ecshop满多少件免运费,这个插件是对ecshop运费优惠插件的一个补充,e... 
- ecshop2.7.1打印发货单插件
                                  ecshop2.7.1打印发货单插件介绍:ecshop2.7.1和以前的ecshop版本不一样,ecs... 
- ecshop后台手动发送订单信
                                  ecshop后台手动发送订单信息短信插件,这个插件非常有用,如果你的货... 
- ecshop根据订单批量发红包
                                  ecshop根据订单批量发红包 ,大家肯定对ecshop红包不陌生,但是对ecshop订... 
- ecshop整合baidu百度开放平台
                                  大家都知道,baidu的开放平台已经很成熟了。可以方便中小型B2C企业数据... 



