diff --git a/app/admin/controller/ReceiveProductSync.php b/app/admin/controller/ReceiveProductSync.php index 4aa670fb..04ddf5d8 100644 --- a/app/admin/controller/ReceiveProductSync.php +++ b/app/admin/controller/ReceiveProductSync.php @@ -99,18 +99,20 @@ class ReceiveProductSync } $category = ProductCategoryModel::language($lang_id)->tcoId($tco_category['id'])->find(); - $tco_parent = ProductTcoCategoryModel::language($lang_id)->tcoId($tco_category['tco_pid'])->find(); - if (!empty($tco_parent)) { - $parent = ProductCategoryModel::language($lang_id)->tcoId($tco_parent['id'])->find(); - if ($parent->isEmpty()) { - throw new \Exception('产品分类父级不存在'); + if (!empty($category)) { + $tco_parent = ProductTcoCategoryModel::language($lang_id)->tcoId($tco_category['tco_pid'])->find(); + if (!empty($tco_parent)) { + $parent = ProductCategoryModel::language($lang_id)->tcoId($tco_parent['id'])->find(); + if ($parent->isEmpty()) { + throw new \Exception('产品分类父级不存在'); + } + $category['pid'] = $parent['id']; + $category['path'] = $parent['path'] . $parent['pid']; + $category['level'] = $parent['level'] + 1; + } + if (!$category->save()) { + throw new \Exception('产品分类更新失败'); } - $category['pid'] = $parent['id']; - $category['path'] = $parent['path'] . $parent['pid']; - $category['level'] = $parent['level'] + 1; - } - if (!$category->save($category)) { - throw new \Exception('产品分类更新失败'); } }