您现在的位置是:crmeb显示一级分类商品

crmeb显示一级分类商品

分类: crmeb 日期:2020-07-22点击:2770

crmeb分类页面,只能显示二级分类,如果要显示一级分类下所有商品,修改如下


\app\models\store\StoreProduct.php

修改 function getProductList($data, $uid)

        if ($sId) {
            // yuli 20200714
            // 显示当前分类及其子分类的商品
            $cateIds= StoreCategory::getCateIdsByPid($sId);
            $model->whereIn('id', function ($query) use ($cateIds) {
                $query->name('store_product_cate')->where('cate_id', 'in', $cateIds)->field('product_id')->select();
            });
            /*
            // 原代码, 仅显示当前分类商品
            $model->whereIn('id', function ($query) use ($sId) {
                $query->name('store_product_cate')->where('cate_id', $sId)->field('product_id')->select();
            });
            */
        } elseif ($cId) {
            $model->whereIn('id', function ($query) use ($cId) {
                $query->name('store_product_cate')->whereIn('cate_id', function ($q) use ($cId) {
                    $q->name('store_category')->where('pid', $cId)->field('id')->select();
                })->field('product_id')->select();
            });
        }

\app\models\store\StoreCategory.php

增加:function getCateIdsByPid($pid)

    // 获取当前分类及其之分类的id 返回数组
    // yuli 20200714
    public static function getCateIdsByPid($pid)
    {
        $parentId = [$pid];
        $chlidIds = self::where('pid', $pid)->column('id');
        if($chlidIds){
            $CateIds = array_merge($parentId,$chlidIds);
            return $CateIds;
        }
        return $parentId;
    }






标签: PHP crmeb

站长简介

    姓名:喻理
    微信:yuli0927
    邮箱:yuli0927@126.com
    不懂业务的运维工程师不是一个好程序员。

分类

最新文章

热门文章

全站标签