ShopWind多商户商城系统支持批量编辑商品,在编辑商品,未选择店铺分类的情况下报有以下错误。经过详细排查、测试,需做以下的修复。错误已经修复,已经更新到码云上:https://gitee.com/shopwind/yii2-shopwind/commit/7cc749ee2c07a85813d2d2db1eab60aef548be99
修复方案:
1、打开frontend/controllers/My_goodsController.php文件,搜索if($post->sgcate_id),将代码
if($post->sgcate_id)
{
$scateIds = array_unique(ArrayHelper::toArray($post->sgcate_id)),
CategoryGoodsModel::deleteAll(['in', 'goods_id', $goodsIds]),
$model = new CategoryGoodsModel(),
foreach($goodsIds as $goods_id)
{
foreach($scateIds as $cate_id) {
$model->isNewRecord = true;
$model->goods_id = $goods_id;
$model->cate_id = $cate_id;
$model->save(),
}
}
}
修改为:
if($array = ArrayHelper::toArray($post->sgcate_id))
{
$scateIds = array_unique($array),
foreach($scateIds as $key => $value) {
if(!$value) unset($scateIds[$key]),
}
if($scateIds) {
CategoryGoodsModel::deleteAll(['in', 'goods_id', $goodsIds]),
foreach($goodsIds as $goods_id) {
foreach($scateIds as $cate_id) {
$model = new CategoryGoodsModel(),
$model->goods_id = $goods_id;
$model->cate_id = $cate_id;
$model->save(),
}
}
}
}