diff --git a/app/modules/cafe24/CLAUDE.md b/app/modules/cafe24/CLAUDE.md index a0f011c..897d3c5 100644 --- a/app/modules/cafe24/CLAUDE.md +++ b/app/modules/cafe24/CLAUDE.md @@ -17,7 +17,8 @@ NNEditor 업로드 경로를 PUT `detail_image` 에 넣는 방식은 적용 안 됨. - 옵션/품목 팝업 「판매 가격」 열: 기본 정보 판매가 + 추가금액을 보여주고, 입력하면 추가금액을 역산(`cafe24-options.js` `bindSalePrice`). 저장되는 값은 추가금액뿐. - 기본 정보에서 판매가를 바꾸면 같은 잠금 안에서 품목 추가금액을 (옛 판매가 − 새 판매가)만큼 옮겨 품목 판매 가격을 유지(`_keep_variant_sale_prices`, `store.shift_additional_amounts`). 공급가·소비자가는 품목과 무관. 판매가는 이미 반영됐으므로 품목 조정 실패는 화면 메시지(`variants_error`)로만. - - 옵션/품목 팝업 옵션값 이름·자체 품목코드·추가금액·판매 가격 칸: Enter·↓ 아래 행, ↑ 위 행 같은 열로 이동(한글 조합 중에는 이동 안 함). + - 옵션/품목 팝업 「재고관리」(use_inventory)·「재고」(quantity)·「품절표시」(display_soldout) 열: 같은 PUT variants 로 기본몰에만 보냄(재고는 쇼핑몰 공통). + - 옵션/품목 팝업 옵션값 이름·자체 품목코드·추가금액·판매 가격·재고 칸: Enter·↓ 아래 행, ↑ 위 행 같은 열로 이동(한글 조합 중에는 이동 안 함). - 옵션/품목 팝업(단일 옵션 화면) 「모바일 스와이프 복사(코드)」: `// 상품명` + `"품목코드": "/web/…썸네일 경로",` 줄들을 클립보드로 (`cafe24-options.js` `swipeCode` — 행에 지금 보이는 썸네일 기준, 도메인/CDN 은 떼고 `/web/` 부터). 「모바일 스와이프 복사(이름)」은 키가 품목코드 대신 옵션값 이름(`swipeCode(tbody, true)`, 품목코드 있는 행만). diff --git a/app/modules/cafe24/routes_product_info.py b/app/modules/cafe24/routes_product_info.py index de6bf44..ff6ac11 100644 --- a/app/modules/cafe24/routes_product_info.py +++ b/app/modules/cafe24/routes_product_info.py @@ -257,6 +257,7 @@ def _variant_view(v: dict[str, Any]) -> dict[str, Any]: "selling": products._flag(v.get("selling")), # noqa: SLF001 "quantity": v.get("quantity"), "use_inventory": products._flag(v.get("use_inventory"), default=False), # noqa: SLF001 + "display_soldout": products._flag(v.get("display_soldout"), default=False), # noqa: SLF001 "image": str(v.get("image") or ""), } @@ -664,7 +665,7 @@ def variants_update( product_no: int, payload: dict[str, Any] = Body(default_factory=dict), ) -> dict[str, Any]: - """품목 여러 건의 자체코드 · 추가금액 · 진열 · 판매를 한 번에 바꾼다 — **행별 결과**. + """품목 여러 건의 자체코드 · 추가금액 · 진열 · 판매 · 재고(사용·수량·품절표시)를 한 번에 바꾼다 — **행별 결과**. 응답 {"ok": 전부 성공?, "partial": 일부만?, "updated": {code: 반영된 값}, "failed": {code: 사유}, "unknown": {code: 사유}} @@ -697,7 +698,8 @@ def variants_update( code = result["variant_code"] if result["status"] == products.VARIANT_OK: patch = dict(sent.get(code) or {}) - for key in ("custom_variant_code", "additional_amount", "display", "selling", "display_order"): + for key in ("custom_variant_code", "additional_amount", "display", "selling", "display_order", + "use_inventory", "display_soldout", "quantity"): value = (result.get("variant") or {}).get(key) if value is not None: patch[key] = value diff --git a/app/modules/cafe24/store.py b/app/modules/cafe24/store.py index 44c5dcf..3c6b4bd 100644 --- a/app/modules/cafe24/store.py +++ b/app/modules/cafe24/store.py @@ -1106,9 +1106,17 @@ def build_variant_updates(rows: list[dict]) -> list[dict]: amount = parse_additional_amount(row["additional_amount"]) if amount is not None: item["additional_amount"] = amount - for flag in ("display", "selling"): + for flag in ("display", "selling", "use_inventory", "display_soldout"): if row.get(flag) is not None: item[flag] = "T" if parse_tristate(row[flag]) else "F" + if row.get("quantity") is not None and str(row["quantity"]).strip() != "": + try: + qty = int(str(row["quantity"]).strip().replace(",", "")) + except ValueError: + raise ValueError("재고 수량은 숫자여야 합니다.") from None + if not 0 <= qty <= ADDITIONAL_AMOUNT_MAX: + raise ValueError("재고 수량은 0 이상이어야 합니다.") + item["quantity"] = qty # 진열 순서(1~300) — 카페24 문서: 조합형 옵션 품목에만. 화면의 드래그 정렬이 보낸다. if row.get("display_order") is not None: try: diff --git a/app/modules/cafe24/tests/test_cafe24.py b/app/modules/cafe24/tests/test_cafe24.py index 53337f1..da9a45f 100644 --- a/app/modules/cafe24/tests/test_cafe24.py +++ b/app/modules/cafe24/tests/test_cafe24.py @@ -1353,6 +1353,18 @@ def test_build_variant_updates(): pass else: raise AssertionError("bad code accepted") + # 재고관리 사용 · 수량 · 품절표시 + assert store.build_variant_updates([ + {"variant_code": "P000000R000A", "use_inventory": "on", "quantity": "1,200", "display_soldout": "off"}, + {"variant_code": "P000000R000B", "quantity": ""}, # 빈 수량 → 변경 없음 + ]) == [{"variant_code": "P000000R000A", "use_inventory": "T", "display_soldout": "F", "quantity": 1200}] + for bad in ("-1", "x"): + try: + store.build_variant_updates([{"variant_code": "P000000R000A", "quantity": bad}]) + except ValueError: + pass + else: + raise AssertionError(bad) # 드래그 정렬 → display_order (1~300) assert store.build_variant_updates([{"variant_code": "P000000R000A", "display_order": "3"}]) == [ {"variant_code": "P000000R000A", "display_order": 3} diff --git a/app/static/cafe24-options.js b/app/static/cafe24-options.js index ade85bb..51365f4 100644 --- a/app/static/cafe24-options.js +++ b/app/static/cafe24-options.js @@ -149,10 +149,16 @@ return out + ""; } + // 품목 토글 — [켜짐, 꺼짐] 표기 + var FLAG_LABELS = { + display: ["진열", "미진열"], selling: ["판매", "중지"], + use_inventory: ["사용", "미사용"], display_soldout: ["표시", "안함"] + }; + var FLAGS = Object.keys(FLAG_LABELS); + function toggleBtn(flag, on) { - var label = flag === "display" ? (on ? "진열" : "미진열") : (on ? "판매" : "중지"); return '"; + '" data-on="' + (on ? 1 : 0) + '" data-initial="' + (on ? 1 : 0) + '">' + FLAG_LABELS[flag][on ? 0 : 1] + ""; } function paintToggle(btn, on, resetInitial) { @@ -160,7 +166,25 @@ if (resetInitial) btn.dataset.initial = btn.dataset.on; btn.classList.toggle("is-on", on); btn.classList.toggle("is-dirty", btn.dataset.on !== btn.dataset.initial); - btn.textContent = btn.dataset.flag === "display" ? (on ? "진열" : "미진열") : (on ? "판매" : "중지"); + btn.textContent = FLAG_LABELS[btn.dataset.flag][on ? 0 : 1]; + } + + // 재고관리 · 재고 수량 · 품절표시 칸 (진열·판매 다음) + var INVENTORY_TH = '재고관리재고품절표시'; + function inventoryCells(variant) { + var qty = variant && variant.quantity != null ? String(variant.quantity) : "0"; + return '' + toggleBtn("use_inventory", !!(variant && variant.use_inventory)) + "" + + '' + + '' + toggleBtn("display_soldout", !!(variant && variant.display_soldout)) + ""; + } + + // 행의 품목 입력 요소들 — 저장 패치(variantPatch/newRowPatch)용 + function variantFields(tr, into) { + into.custom = tr.querySelector('[name="custom_variant_code"]'); + into.amount = tr.querySelector('[name="additional_amount"]'); + into.quantity = tr.querySelector('[name="quantity"]'); + FLAGS.forEach(function (flag) { into[flag] = tr.querySelector('.cf24-v-toggle[data-flag="' + flag + '"]'); }); + return into; } function bindToggles(container) { @@ -339,7 +363,7 @@ }); tbody.addEventListener("keydown", function (e) { // isComposing: 한글 조합 중 Enter 는 글자 확정용이다 — 여기서 옮기면 글자가 깨지거나 두 칸 내려간다. - if (e.isComposing || !e.target.matches('[name="option_text"], [name="custom_variant_code"], [name="additional_amount"], .cf24-sale-price')) return; + if (e.isComposing || !e.target.matches('[name="option_text"], [name="custom_variant_code"], [name="additional_amount"], .cf24-sale-price, [name="quantity"]')) return; var down = e.key === "Enter" || e.key === "ArrowDown"; if (!down && e.key !== "ArrowUp") return; e.preventDefault(); @@ -425,6 +449,7 @@ salePriceCell(variant ? variant.additional_amount : "0") + '' + toggleBtn("display", variant ? !!variant.display : true) + "" + '' + toggleBtn("selling", variant ? !!variant.selling : true) + "" + + inventoryCells(variant) + '' + (awaiting ? "" : '') + "" + ""; } @@ -449,7 +474,7 @@ "" + '
' + '' + - '' + + '' + INVENTORY_TH + '' + ""; rows.forEach(function (r, i) { html += rowHtml(r, canDrag, i); }); if (isNew) html += rowHtml({ index: null, value: null, variant: null }, true, null); @@ -569,8 +594,8 @@ link: tr.querySelector('[name="option_link_image"]').value, custom: tr.querySelector('[name="custom_variant_code"]').value, amount: tr.querySelector('[name="additional_amount"]').value, - display: tr.querySelector('.cf24-v-toggle[data-flag="display"]').dataset.on, - selling: tr.querySelector('.cf24-v-toggle[data-flag="selling"]').dataset.on + quantity: tr.querySelector('[name="quantity"]').value, + flags: FLAGS.map(function (flag) { return tr.querySelector('.cf24-v-toggle[data-flag="' + flag + '"]').dataset.on; }) }; }); } @@ -598,11 +623,12 @@ set('[name="option_text"]', k.text); set('[name="custom_variant_code"]', k.custom); set('[name="additional_amount"]', k.amount); + set('[name="quantity"]', k.quantity); if (k.image) { tr.querySelector('[name="option_image_file"]').value = k.image; } if (k.link) { tr.querySelector('[name="option_link_image"]').value = k.link; } - ["display", "selling"].forEach(function (flag) { + FLAGS.forEach(function (flag, i) { var btn = tr.querySelector('.cf24-v-toggle[data-flag="' + flag + '"]'); - if (btn && btn.dataset.on !== k[flag]) paintToggle(btn, k[flag] === "1", false); + if (btn && btn.dataset.on !== k.flags[i]) paintToggle(btn, k.flags[i] === "1", false); }); }); } @@ -766,7 +792,7 @@ /* ── 저장 (통합) ── */ function collectUnified(tbody) { return Array.prototype.map.call(tbody.children, function (tr, i) { - return { + return variantFields(tr, { tr: tr, position: i, isNew: tr.classList.contains("is-new"), @@ -774,12 +800,8 @@ code: tr.dataset.code || "", text: tr.querySelector('[name="option_text"]').value.trim(), image: tr.querySelector('[name="option_image_file"]').value, - link: tr.querySelector('[name="option_link_image"]').value, - custom: tr.querySelector('[name="custom_variant_code"]'), - amount: tr.querySelector('[name="additional_amount"]'), - display: tr.querySelector('.cf24-v-toggle[data-flag="display"]'), - selling: tr.querySelector('.cf24-v-toggle[data-flag="selling"]') - }; + link: tr.querySelector('[name="option_link_image"]').value + }); }); } @@ -801,20 +823,25 @@ var any = false; if (r.custom.value !== r.custom.defaultValue) { patch.custom_variant_code = r.custom.value.trim(); any = true; } if (r.amount.value !== r.amount.defaultValue) { patch.additional_amount = r.amount.value.trim() || "0"; any = true; } - if (r.display.dataset.on !== r.display.dataset.initial) { patch.display = r.display.dataset.on === "1" ? "on" : "off"; any = true; } - if (r.selling.dataset.on !== r.selling.dataset.initial) { patch.selling = r.selling.dataset.on === "1" ? "on" : "off"; any = true; } + if (r.quantity.value !== r.quantity.defaultValue) { patch.quantity = r.quantity.value.trim() || "0"; any = true; } + FLAGS.forEach(function (flag) { + if (r[flag].dataset.on !== r[flag].dataset.initial) { patch[flag] = r[flag].dataset.on === "1" ? "on" : "off"; any = true; } + }); if (withOrder) { patch.display_order = r.position + 1; any = true; } return any ? patch : null; } - // 새 행(아직 품목 없음)의 초기 패치 — 기본값(빈 코드·0원·진열·판매)과 다른 것만 + // 새 행(아직 품목 없음)의 초기 패치 — 기본값(빈 코드·0원·진열·판매·재고관리 미사용·재고 0·품절표시 안함)과 다른 것만 function newRowPatch(r, code) { var p = { variant_code: code }; var any = false; if (r.custom.value.trim()) { p.custom_variant_code = r.custom.value.trim(); any = true; } if (amountPlain(r.amount.value) !== "0") { p.additional_amount = r.amount.value.trim(); any = true; } - if (r.display.dataset.on !== "1") { p.display = "off"; any = true; } - if (r.selling.dataset.on !== "1") { p.selling = "off"; any = true; } + if (amountPlain(r.quantity.value) !== "0") { p.quantity = r.quantity.value.trim(); any = true; } + FLAGS.forEach(function (flag) { + var defaultOn = flag === "display" || flag === "selling"; + if ((r[flag].dataset.on === "1") !== defaultOn) { p[flag] = defaultOn ? "off" : "on"; any = true; } + }); return any ? p : null; } @@ -866,7 +893,7 @@ var lines = []; if (optionsChanged) lines.push("옵션명·옵션값 이름/썸네일/표시방식"); - if (patches.length) lines.push("품목 " + patches.length + "건 (자체코드·추가금액·진열/판매" + (orderChanged ? "·순서" : "") + ")"); + if (patches.length) lines.push("품목 " + patches.length + "건 (자체코드·추가금액·진열/판매·재고" + (orderChanged ? "·순서" : "") + ")"); window.erpConfirm("카페24에 바로 반영합니다. 계속할까요?\n\n- " + lines.join("\n- ")).then(function (ok) { if (!ok) return; saveBtn.disabled = true; @@ -1013,7 +1040,7 @@ html += '

품목이 아직 조회되지 않았습니다. 잠시 뒤 창을 닫았다 다시 여세요.

'; } else { html += '
썸네일옵션값 이름품목코드자체 품목코드추가금액판매 가격진열판매자체 품목코드추가금액판매 가격진열판매
' + - ''; + '' + INVENTORY_TH + ''; variants.forEach(function (v) { var label = v.options.map(function (o) { return o.value; }).join(" / ") || v.variant_code; html += '' + @@ -1024,6 +1051,7 @@ '' + salePriceCell(v.additional_amount) + '" + + inventoryCells(v) + ''; }); html += "
옵션품목코드자체 품목코드추가금액판매 가격진열판매
자체 품목코드추가금액판매 가격진열판매
' + toggleBtn("display", !!v.display) + "" + toggleBtn("selling", !!v.selling) + "
" + @@ -1106,9 +1134,7 @@ var saveBtn = body.querySelector("#cf24-var-save"); var rows = []; wrap.querySelectorAll("tr[data-code]").forEach(function (tr) { - var r = { code: tr.dataset.code, custom: tr.querySelector('[name="custom_variant_code"]'), amount: tr.querySelector('[name="additional_amount"]'), - display: tr.querySelector('.cf24-v-toggle[data-flag="display"]'), selling: tr.querySelector('.cf24-v-toggle[data-flag="selling"]') }; - var p = variantPatch(r, false); + var p = variantPatch(variantFields(tr, { code: tr.dataset.code }), false); if (p) rows.push(p); }); if (!rows.length) { setMsg(msg, "바뀐 품목이 없습니다.", ""); return; } @@ -1125,6 +1151,7 @@ if (!tr) return; if (u.custom_variant_code !== undefined) tr.querySelector('[name="custom_variant_code"]').value = u.custom_variant_code; if (u.additional_amount !== undefined) tr.querySelector('[name="additional_amount"]').value = amountPlain(u.additional_amount); + if (u.quantity != null) tr.querySelector('[name="quantity"]').value = String(u.quantity); tr.querySelectorAll(".cf24-v-toggle").forEach(function (btn) { if (u[btn.dataset.flag] !== undefined) paintToggle(btn, !!u[btn.dataset.flag], true); }); @@ -1132,8 +1159,8 @@ if (v.variant_code !== code) return; if (u.custom_variant_code !== undefined) v.custom_variant_code = u.custom_variant_code; if (u.additional_amount !== undefined) v.additional_amount = u.additional_amount; - if (u.display !== undefined) v.display = !!u.display; - if (u.selling !== undefined) v.selling = !!u.selling; + if (u.quantity != null) v.quantity = u.quantity; + FLAGS.forEach(function (flag) { if (u[flag] !== undefined) v[flag] = !!u[flag]; }); }); }); commitValues(wrap); diff --git a/app/static/cafe24.css b/app/static/cafe24.css index 6a987a7..943991d 100644 --- a/app/static/cafe24.css +++ b/app/static/cafe24.css @@ -1348,6 +1348,8 @@ body.cf24-modal-open { .cf24-v-code { width: 132px; } .cf24-v-amount { width: 90px; } .cf24-v-amount input { text-align: right; } +.cf24-v-qty { width: 70px; } +.cf24-v-qty input { text-align: right; } .cf24-v-flag { width: 56px; text-align: center; } /* 품목코드 — 클릭하면 클립보드로. 눌리는 것임을 커서·밑줄로 알린다. */