fecshop产品属性疑问

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

在维护产品的时候颜色属性存在双色的,如white & blue,在保存的时候会把第一个空格替换成号,如下图 但是在html5前端获取产品数据的时候,并没有做号的处理,导致多色的产品属性出不来,代码如下:

public function getAllItems()
    {
        $custom_option_attr_info = Yii::$service->product->getCustomOptionAttrInfo($this->attr_group);

        //#########
        $my_arr = [];
        $arr = [];
        //#在custom_option里面第一个属性
        $img_attr = '';
        if (is_array($custom_option_attr_info) && !empty($custom_option_attr_info)) {
            foreach ($custom_option_attr_info as $attr => $info) {
                if (isset($info['showAsImg']) && $info['showAsImg']) {
                    $img_attr = $attr;
                    break;
                }
            }
        }
        $img_arr = [];
        if (is_array($this->custom_option) && (!empty($this->custom_option))) {
            foreach ($this->custom_option as $option) {
                $qty = $option['qty'];
                if ($qty > 0) {
                    $this->_custom_option_arr[] = $option;
                    if (isset($option[$img_attr])) {
                        $val = $option[$img_attr];
                        $img_arr[$val] = $option['image'];
                    }
                    foreach ($option as $k=>$v) {
                        $my_arr[$k][] = $v;
                    }
                }
            }
        }
        if (is_array($custom_option_attr_info) && !empty($custom_option_attr_info)) {
            foreach ($custom_option_attr_info as $attr => $info) {
                if (isset($info['display']['type']) && ($info['display']['type'] == 'select')) {
                    if (isset($info['display']['data']) && is_array($info['display']['data'])) {
                        foreach ($info['display']['data'] as $key=>$val) {
                            if (is_array($my_arr[$attr]) && in_array($key, $my_arr[$attr])) {
                                $t_arr = [
                                    'key' => $key,
                                    'val' => $val,
                                ];
                                $require = isset($info['require']) ? $info['require'] : 0;
                                if (isset($info['showAsImg']) && $info['showAsImg']) {
                                    if (isset($img_arr[$key])) {
                                        $t_arr['image'] = $img_arr[$key];
                                    }
                                }
                                $arr[$attr]['info'][] = $t_arr;
                                $arr[$attr]['require'] = $require;
                            }
                        }
                    }
                }
            }
        }

        return $arr;
    }

在以上的代码中,并没有加入*号的判断导致多色的产品属性出不来。

is_array($my_arr[$attr]) && in_array($key, $my_arr[$attr]
共收到 3 条回复
xi_qing#16年前 0 个赞

我对上面的代码改了一下可以出来,其他流程还测试看会不会影响

public function getAllItems()
    {
        $custom_option_attr_info = Yii::$service->product->getCustomOptionAttrInfo($this->attr_group);

        //#########
        $my_arr = [];
        $arr = [];
        //#在custom_option里面第一个属性
        $img_attr = '';
        if (is_array($custom_option_attr_info) && !empty($custom_option_attr_info)) {
            foreach ($custom_option_attr_info as $attr => $info) {
                if (isset($info['showAsImg']) && $info['showAsImg']) {
                    $img_attr = $attr;
                    break;
                }
            }
        }
        $img_arr = [];
        if (is_array($this->custom_option) && (!empty($this->custom_option))) {
            foreach ($this->custom_option as $option) {
                $qty = $option['qty'];
                if ($qty > 0) {
                    $this->_custom_option_arr[] = $option;
                    if (isset($option[$img_attr])) {
                        $val = $option[$img_attr];
                        $img_arr[$val] = $option['image'];
                    }
                    foreach ($option as $k=>$v) {
                        $my_arr[$k][] = $v;
                    }
                }
            }
        }
        if (is_array($custom_option_attr_info) && !empty($custom_option_attr_info)) {
            foreach ($custom_option_attr_info as $attr => $info) {
                if (isset($info['display']['type']) && ($info['display']['type'] == 'select')) {
                    if (isset($info['display']['data']) && is_array($info['display']['data'])) {
                        foreach ($info['display']['data'] as $key=>$val) {
                            if (is_array($my_arr[$attr]) && in_array(htmlspecialchars($key), $my_arr[$attr])) {
                                $t_arr = [
                                    'key' => $key,
                                    'val' => $val,
                                ];
                                $require = isset($info['require']) ? $info['require'] : 0;
                                if (isset($info['showAsImg']) && $info['showAsImg']) {
                                    if (isset($img_arr[htmlspecialchars($key)])) {
                                        $t_arr['image'] = $img_arr[htmlspecialchars($key)];
                                    }
                                }
                                $arr[$attr]['info'][] = $t_arr;
                                $arr[$attr]['require'] = $require;
                            }
                        }
                    }
                }
            }
        }

        return $arr;
    }

增加了对$key的html转义

2楼 已删除.
Fecmall#36年前 0 个赞

这个bug已经处理,原因:custom option sku 含有 & 特殊字符被转义成 “&” 进而导致的bug

代码需要进行的修改参看:https://github.com/fecshop/yii2_fecshop/commit/2af0be0f6c7c96911101dd6fe6e71d5c2d3481b2

我测试已经通过,测试地址: https://fecshop.appfront.fancyecommerce.com/reindeer-pattern-glitter-christmas-dress-86519596

Fecmall#46年前 0 个赞

@xi_qing #1楼 修改完代码后,需要去后台把产品重新保存一下。

还是从根源部分去除这个bug吧,原因是:

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