如图, 用http://fecshop.appapi.fancyecommerce.com/v1/product/addone 这个API 添加产品。 这二个字段无法新增数据 , 左侧是新增以后返回的数据 , 右侧是新增之前传递的数据 , 返回的数据当中 meta_title和 remark 都是空值 ,同时url_key 无法使用自定义后缀名的问题, URL keY, 经过测试, 好像这个参数也没有生效, 是直接 拿 name生成出来的url key, 不知道 这个是不是一个BUG。
1.找时间处理一下
2.自己去找找相应的文件,很容易自己处理一下的,去找找代码。
对应的就是这个文件:
https://github.com/fecshop/yii2_fecshop/blob/master/app/appapi/modules/V1/controllers/ProductController.php#L105
我看了下 https://github.com/fecshop/yii2_fecshop/blob/master/services/product/ProductApi.php 这个文件的源代码 。 在 大约 332行处, // 选填
$remark = $post['remark']; if (!$remark) { $this->_param['remark'] = $remark; }
和 360行
// 选填 产品的url key
$url_key = $post['url_key']; if (!$url_key) { $this->_param['url_key'] = $url_key; }
这里的判断 应该是if($remark) 和 if($url_key), 不应该是非的判断 。
理伦上应该是所有的选填 应该都判断 反了条件, // 选填
$remark = $post['remark']; if (!$remark) { $this->_param['remark'] = $remark; } // 选填 $relation_sku = $post['relation_sku']; if (!$relation_sku) { $this->_param['relation_sku'] = $relation_sku; } // 选填 $buy_also_buy_sku = $post['buy_also_buy_sku']; if (!$buy_also_buy_sku) { $this->_param['buy_also_buy_sku'] = $buy_also_buy_sku; } // 选填 $see_also_see_sku = $post['see_also_see_sku']; if (!$see_also_see_sku) { $this->_param['see_also_see_sku'] = $see_also_see_sku; }
我个人的理解。
经过测试, 确实是 API 里面 所有的选填的判断 全部条件都写反了。 同时 在428 行 把
$title = $post['title']; if (!empty($title) && is_array($title)) { $this->_param['title'] = $title; }
修改为
$title = $post['meta_title']; if (!empty($title) && is_array($title)) { $this->_param['meta_title'] = $title; }
问题解决。
meta_title 和 title 是没有问题的,因为是多语言,需要是数组的格式。
meta_title
title
其他的你指出的是正确的
代码提交:https://github.com/fecshop/yii2_fecshop/commit/0eafd920567da9837f981f5c3099bc1de14ea808