|
@@ -107,6 +107,50 @@ public class ProductController {
|
|
|
int groupId = 1;
|
|
int groupId = 1;
|
|
|
|
|
|
|
|
for (ProductSku sku : skus) {
|
|
for (ProductSku sku : skus) {
|
|
|
|
|
+ boolean isLinked = sku.getLinkedProductId() != null;
|
|
|
|
|
+
|
|
|
|
|
+ if (isLinked) {
|
|
|
|
|
+ // Linked SKU: 查询关联商品摘要,库存为0/不存在则跳过
|
|
|
|
|
+ Map<String, Object> linkedSummary = productSkuService.getLinkedProductSummary(sku.getLinkedProductId());
|
|
|
|
|
+ if (linkedSummary == null) continue;
|
|
|
|
|
+
|
|
|
|
|
+ // 选项名:label 优先,否则用 linked 商品名
|
|
|
|
|
+ String optionName = sku.getLabel();
|
|
|
|
|
+ if (optionName == null || optionName.trim().isEmpty()) {
|
|
|
|
|
+ optionName = (String) linkedSummary.get("name");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 用 "关联商品" 作为分组名
|
|
|
|
|
+ String groupName = "关联商品";
|
|
|
|
|
+ if (!nameToGroupId.containsKey(groupName)) {
|
|
|
|
|
+ nameToGroupId.put(groupName, groupId++);
|
|
|
|
|
+ Map<String, Object> grp = new HashMap<>();
|
|
|
|
|
+ grp.put("groupId", nameToGroupId.get(groupName));
|
|
|
|
|
+ grp.put("groupName", groupName);
|
|
|
|
|
+ grp.put("options", new ArrayList<Map<String, Object>>());
|
|
|
|
|
+ groups.add(grp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> option = new HashMap<>();
|
|
|
|
|
+ option.put("id", sku.getId());
|
|
|
|
|
+ option.put("groupId", nameToGroupId.get(groupName));
|
|
|
|
|
+ option.put("name", optionName);
|
|
|
|
|
+ option.put("skuId", sku.getId());
|
|
|
|
|
+ option.put("linkedProductId", sku.getLinkedProductId());
|
|
|
|
|
+ option.put("isLinked", true);
|
|
|
|
|
+ option.put("linked", linkedSummary);
|
|
|
|
|
+
|
|
|
|
|
+ for (Map<String, Object> g : groups) {
|
|
|
|
|
+ if (g.get("groupId").equals(nameToGroupId.get(groupName))) {
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ List<Map<String, Object>> opts = (List<Map<String, Object>>) g.get("options");
|
|
|
|
|
+ opts.add(option);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Legacy SKU: 原有 specs 解析逻辑
|
|
|
if (sku.getSpecs() == null) continue;
|
|
if (sku.getSpecs() == null) continue;
|
|
|
if (sku.getSpecs().toString().trim().isEmpty()) continue;
|
|
if (sku.getSpecs().toString().trim().isEmpty()) continue;
|
|
|
try {
|
|
try {
|
|
@@ -133,6 +177,7 @@ public class ProductController {
|
|
|
option.put("price", sku.getPrice());
|
|
option.put("price", sku.getPrice());
|
|
|
option.put("stock", sku.getStock());
|
|
option.put("stock", sku.getStock());
|
|
|
option.put("enabled", sku.getEnabled());
|
|
option.put("enabled", sku.getEnabled());
|
|
|
|
|
+ option.put("isLinked", false);
|
|
|
|
|
|
|
|
for (Map<String, Object> g : groups) {
|
|
for (Map<String, Object> g : groups) {
|
|
|
if (g.get("groupId").equals(nameToGroupId.get(name))) {
|
|
if (g.get("groupId").equals(nameToGroupId.get(name))) {
|