From a9608cb34ff9ed65e9202f8feb5c46f770d5d02b Mon Sep 17 00:00:00 2001 From: tangwang Date: Wed, 17 Dec 2025 17:11:55 +0800 Subject: [PATCH] 1. 第一列“商品ID”这一列 进行填充,从1开始增 2. 如果变体的标题跟主商品不一致,请打印一条错误日志,并且忽略这一条数据 --- scripts/amazon_xlsx_to_shoplazza_xlsx.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/amazon_xlsx_to_shoplazza_xlsx.py b/scripts/amazon_xlsx_to_shoplazza_xlsx.py index cf87549..8beb3e7 100644 --- a/scripts/amazon_xlsx_to_shoplazza_xlsx.py +++ b/scripts/amazon_xlsx_to_shoplazza_xlsx.py @@ -458,16 +458,45 @@ def main(): # 先按 SPU 构造每个组的行,方便做“按最大行数拆分但不拆组” group_rows_list = [] # List[List[dict]] spu_count = 0 + next_product_id = 1 # 用于填充商品ID,全局自增 + for spu_id, variants in groups.items(): if not variants: continue + + # 过滤掉标题与主商品不一致的变体 + main_title = variants[0].get("商品标题") or "" + filtered = [] + for v in variants: + title = v.get("商品标题") or "" + if main_title and title and title != main_title: + print( + f"SKIP variant due to title mismatch: SPU={spu_id}, ASIN={v.get('ASIN')}, " + f"main_title='{main_title}', variant_title='{title}'", + flush=True, + ) + continue + filtered.append(v) + + if not filtered: + # 整个SPU都被过滤掉 + continue + spu_count += 1 if args.max_products is not None and spu_count > int(args.max_products): break - if len(variants) == 1: - group_rows_list.append([build_s_row(variants[0])]) + + if len(filtered) == 1: + rows = [build_s_row(filtered[0])] else: - group_rows_list.append(build_m_p_rows(variants)) + rows = build_m_p_rows(filtered) + + # 填充商品ID(从1开始全局递增) + for r in rows: + r["商品ID"] = next_product_id + next_product_id += 1 + + group_rows_list.append(rows) # 按最大行数拆成多个文件(注意:同一 SPU 不拆分) data_start_row = 4 # 与模板/写入工具保持一致 -- libgit2 0.21.2