店铺首页挂件创建和使用说明[TianYan出品]

摘自:http://ecmall.shopex.cn/bbs/viewthread.php?tid=1082931

 

店铺首页挂件创建和使用说明[TianYan出品]

首先感谢 biby 编写的"ecmall商铺首页挂件实现及类淘宝分类首页自定义",提供了很多非常有价值的参考意见。

具体功能如下:
1.实现店铺首页挂件自定义
2.实现商城挂件与店铺挂件分离存储
3.实现挂件存储文件、权限、路经与商城挂件分离

修改过程:
1.下载挂件文件,覆盖到系统根目录[不限版本问题直接覆盖]
2.修改 app\store.app.php
function index()
    {
        ..../前接
        $this->assign('store', $store);
                               
                                /* TianYan 设置店铺id */
                                $this->assign('store_id', $id);
                               
        /* 取得友情链接 */
        ....\后接
        
    }
3.修改 app\frontend.base.php  覆盖这个函数
/**
     *    视图回调函数[显示小挂件]
     *
     *    @author    Garbin
     *    @param     array $options
     *    @return    void
     */
    function display_widgets($options,$widgetname='widget.base.php')
    {
        $area = isset($options['area']) ? $options['area'] : '';
        $page = isset($options['page']) ? $options['page'] : '';
        $store_id = isset($options['store_id']) ? $options['store_id'] : ''; //TianYan 增加用于前台店铺挂件显示
        if (!$area || !$page)
        {
            return;
        }
        include_once(ROOT_PATH . '/includes/'.$widgetname);
        /* TianYan 修改判断挂件类型获取该页面的挂件配置信息 */
        $widgets = ($widgetname=='widget.base.php')?get_widget_config($this->_get_template_name(), $page):get_widget_config($this->_get_template_name(), $page,$store_id);
        /* 如果没有该区域 */
        if (!isset($widgets['config'][$area]))
        {
            return;
        }

        /* 将该区域内的挂件依次显示出来 */
        foreach ($widgets['config'][$area] as $widget_id)
        {
            $widget_info = $widgets['widgets'][$widget_id];
            $wn     =   $widget_info['name'];
            $options=   $widget_info['options'];

            $widget =& widget($widget_id, $wn, $options);
            $widget->display();
        }
    }
4.修改 my_theme.app.php

/*---TianYan 增加页面设置----*/
    function page_set() //新增加的函数
    {


      $this->assign('pages',$this->_get_editable_pages());//这里有一个从管理员后台复制来的函数,获取可以编辑的页面,像管理员后台是有首页和分类页可以可视化编辑,就是由这个函数设置.

      $this->_curlocal(LANG::get('member_center'),'index.php?app=member', Lang::get('page_set'));//这里是去语言文件获取汉字并且设置我们的用户中心的“当前位置”。

                        $this->_curitem('my_store');//设置左侧激活的项目这里是“店铺设置”,同样是获取语言文件里的汉字。
                       
                       
                        /* 当前所处子菜单 */
                        $this->_curitem('my_theme');
      $this->_curmenu('page_set');

                       
                        $this->display('my_theme.pageset.html');//调用我们自建的一个模板文件显示。

    }

    /*三级菜单*/
    function _get_member_submenu()
    {
        $array = array(
                    array(
                        'name' => 'theme_menu',
                        'url'  => 'index.php?app=my_theme',
                    ),
                   /*---TianYan 新增加的菜单---*/
                    array(
                        'name' => 'page_set',
                        'url'  => 'index.php?app=my_theme&act=page_set',
                    ),
            );
        return $array;
    }

   
        function _get_editable_pages() //新增加的函数
    {
             return array(
                        'store_index'=>'store_id_index',
                );
        }

 

5.修改 eccore\view\template.php 文件
function select($tag)
{
..../前接
case 'widgets':
                    $t = $this->get_para(substr($tag, 8), 0);
                    return '<?php $this->display_widgets(' . $this->make_array($t) . '); ?>';
                    break;
case 'store_widgets':  //TianYan 显示店铺挂件
                    $t = $this->get_para(substr($tag, 8), 0);
                    return '<?php $this->display_widgets(' . $this->make_array($t) . ',"store_widget.base.php"); ?>';
                    break;
case 'html_radios':
后接/......
}
//重新覆盖以下这个函数
function display_widgets($arr,$widgetname='widget.base.php')
    {
        /* 请求控制器 */
        $controller =& cc();
        $controller->display_widgets($arr,$widgetname);
    }
6.修改includes/global.lib.php 两个函数,直接覆盖即可
/**
*    获取挂件列表
*
*    @author    Garbin
*    @return    array
*/
function list_widget($wpath='/external/widgets')
{
    $widget_dir = ROOT_PATH . $wpath;
    static $widgets    = null;
    if ($widgets === null)
    {
        $widgets = array();
        if (!is_dir($widget_dir))
        {
            return $widgets;
        }
        $dir = dir($widget_dir);
        while (false !== ($entry = $dir->read()))
        {
            if (in_array($entry, array('.', '..')) || $entry{0} == '.' || $entry{0} == '$')
            {
                continue;
            }
            if (!is_dir($widget_dir . '/' . $entry))
            {
                continue;
            }
            $info = get_widget_info($entry,$wpath.'/');
            $widgets[$entry] = $info;
        }
    }

    return $widgets;
}

/**
*    获取挂件信息
*
*    @author    Garbin
*    @param     string $id
*    @return    array
*/
function get_widget_info($name,$wpath='/external/widgets/')
{
    $widget_info_path = ROOT_PATH . $wpath . $name . '/widget.info.php';

    return include($widget_info_path);
}
7.\themes\store\default\header.html 增加一个可编辑代码在</head>
.../上接
<!--<editmode></editmode>-->
</head>

店铺前台挂件需要注意说明的事情
1.在店铺首页store.index.html模板中,挂件拖放的区域要增加一个store_id
<div class="left" area="top_left" widget_type="area">
                <!--{store_widgets page=store_index area=top_left store_id=$store_id}-->
</div>
2.店铺挂件存储目录为 external\store_widgets 区别与商城挂件目录
rar文件中包含一个图片挂件。

3.编写main.widget.php 挂件上传文件目录位置的时候注意存储路经应当设置为店铺自己的目录

return $uploader->save('data/files/store_'.$_SESSION['user_info']['user_id'].'/template', $uploader->random_filename());

 

实际效果展示
1.可以设置店铺首页,商品分类页和店铺导航页的模板布局


2.目前拥有10个独立的店铺挂件



3.用户店铺设置好之后实际的效果图


[ 本帖最后由 tianyan 于 2009-9-28 15:53 编辑 ]

 

posted @ 2010-01-14 13:27  方子尚  阅读(684)  评论(0编辑  收藏  举报