From a486595d07ea71d091710082aba9127739da4589 Mon Sep 17 00:00:00 2001 From: kent Date: Sun, 14 Dec 2025 00:10:46 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20ItemService=20update()=20=EB=8F=99?= =?UTF-8?q?=EC=A0=81=20=ED=95=84=EB=93=9C=20=EB=B3=91=ED=95=A9=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 item.options 기반으로 동적 필드 병합하도록 수정 - 일부 필드만 변경 시 나머지 필드가 보존됨 - Item-Master 연동 테스트 완료 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/Services/ItemService.php | 38 +++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/app/Services/ItemService.php b/app/Services/ItemService.php index fc4cb6d..68f5d31 100644 --- a/app/Services/ItemService.php +++ b/app/Services/ItemService.php @@ -429,16 +429,40 @@ public function update(int $id, array $data): Model throw new BadRequestHttpException(__('error.not_found')); } - // 동적 필드를 options에 병합 + // 동적 필드를 options에 병합 (기존 item의 options 기반) $dynamicOptions = $this->extractDynamicOptions($data); - if (! empty($dynamicOptions)) { - $existingOptions = $data['options'] ?? []; - $data['options'] = $this->mergeOptionsWithDynamic($existingOptions, $dynamicOptions); + + // 기존 options를 배열 형태로 변환 (label → value 맵) + $existingOptionsMap = []; + if (is_array($item->options)) { + foreach ($item->options as $opt) { + if (isset($opt['label'])) { + $existingOptionsMap[$opt['label']] = $opt['value'] ?? ''; + } + } } - // options 정규화 - if (isset($data['options'])) { - $data['options'] = $this->normalizeOptions($data['options']); + // 새 동적 필드와 기존 options 병합 + if (! empty($dynamicOptions)) { + // 새 동적 필드로 기존 값 덮어쓰기 + foreach ($dynamicOptions as $key => $value) { + $existingOptionsMap[$key] = $value; + } + } + + // 명시적으로 전달된 options 처리 + if (isset($data['options']) && is_array($data['options'])) { + // 배열 형태의 options 병합 + foreach ($data['options'] as $opt) { + if (isset($opt['label'])) { + $existingOptionsMap[$opt['label']] = $opt['value'] ?? ''; + } + } + } + + // 최종 options 설정 (병합된 맵이 비어있지 않으면) + if (! empty($existingOptionsMap)) { + $data['options'] = $this->normalizeOptions($existingOptionsMap); } // code 변경 시 중복 체크 (동적 테이블)