关于fecshop升级的疑问

问题咨询 · xi_qing · 于 6年前 发布 · 2188 次阅读

这次更新了一下最新的版本,出现了一个问题来咨询一下,大致问题如下: 由于业务需要,我在分类里面扩展了一个字段,扩展字段的方法是按照YII的ClassMap来处理的,并配置了相关路径,程序也是能够run起来。 更新之后出现的问题是,程序仍然加载了我自己扩展的类,而我的类中并没有重写本次fecshop升级的增加一个是否在菜单显示的功能。 我是想了解一下,是否有什么更好的办法来重写class而不影响升级的内容? 比如: 这个是我重写的Category.php

<?php
namespace fecshop\models\mongodb;

use yii\mongodb\ActiveRecord;

class Category extends ActiveRecord
{
    /**
     * mongodb collection 的名字,相当于mysql的table name
     */
    public static function collectionName()
    {
        return 'category';
    }
    /**
     * mongodb是没有表结构的,因此不能像mysql那样取出来表结构的字段作为model的属性
     * 因此,需要自己定义model的属性,下面的方法就是这个作用
     */
    public function attributes()
    {
        return [
            '_id',
            'parent_id',
            'name',
            'status',
            'url_key',
            'level',
            'thumbnail_image',
            'image',
            'filter_product_attr_selected',
            'filter_product_attr_unselected',
            'description',
            'menu_custom',
            'title',
            'meta_description',
            'meta_keywords',
            'include_in_menu',
            'is_feature',
            'available_sort_by',
            'default_sort_by',
            'theme',
            'active_from',
            'active_to',
            'created_at',
            'updated_at',
            'created_user_id',
            'ori_id',
            'sites'
            //other
            /*
                category filter
                category product


            */
        ];
    }
}

本次升级的Category.php类:

<?php
/**
 * FecShop file.
 *
 * @link http://www.fecshop.com/
 * @copyright Copyright (c) 2016 FecShop Software LLC
 * @license http://www.fecshop.com/license/
 */

namespace fecshop\models\mongodb;

use yii\mongodb\ActiveRecord;

/**
 * @author Terry Zhao <2358269014@qq.com>
 * @since 1.0
 */
class Category extends ActiveRecord
{
    
    
    const MENU_SHOW      = 1;
    const MENU_NOT_SHOW  = 2;
    const STATUS_ENABLE  = 1;
    const STATUS_DISABLE = 2;

    
    /**
     * mongodb collection 的名字,相当于mysql的table name
     */
    public static function collectionName()
    {
        return 'category';
    }
    /**
     * mongodb是没有表结构的,因此不能像mysql那样取出来表结构的字段作为model的属性
     * 因此,需要自己定义model的属性,下面的方法就是这个作用
     */
    public function attributes()
    {
        return [
            '_id',
            'parent_id',
            'name',
            'status',
            'menu_show',//..这个为本次更新增加的字段
            'url_key',
            'level',
            'thumbnail_image',
            'image',
            'filter_product_attr_selected',
            'filter_product_attr_unselected',
            'description',
            'menu_custom',
            'title',
            'meta_description',
            'meta_keywords',
            'include_in_menu',
            'is_feature',
            'available_sort_by',
            'default_sort_by',
            'theme',
            'active_from',
            'active_to',
            'created_at',
            'updated_at',
            'created_user_id',
            //other
            /*
                category filter
                category product


            */
       ];
    }
}

由于ClassMap的配置,程序读取的是我自己写的Category.php,这样就相当于没有执行到更新内容,如何才能做到说重写Class并不影响升级功能的使用?还是说必须重新复制一下核心包的内容再次修改,这样文件重写多了升级会是一个很麻烦的事情? 本来我想利用继承关系来做,但是由于使用ClassMap,命名空间必须一致,无法使用继承来完成。 大家有没有好的思路呢?

共收到 4 条回复
Fecmall#16年前 0 个赞

应该有办法实现,我看看Yii2的底层,尝试重写一下底层。

water#26年前 0 个赞

您好,解决不了这个问题,尝试了很多种方式,都不行,只能复制过来,替换了。

我看了下magento的block model重写,也是这个样子,整个文件替换。

通过classMap的方式无法解决这个问题

后面我想想,看看是否有其他的方式解决这个问题吧。

xi_qing#36年前 0 个赞

@water #2楼 好的,我先用复制过来的方式修改,做的过程中看想想看有没有其他的方式来弄,主要是考虑到有新增需求的时候会有微调的情况,这样升级就变的麻烦了。慢慢完善吧

xi_qing#46年前 0 个赞

@water #2楼 谢谢哈

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics