fix: ItemService update 시 attributes 머지 로직 추가
- 기존: attributes 전체 덮어쓰기 → 수정: 기존 값 보존 후 새 값만 머지 - 품목 수정 시 레거시 속성(sales_price, legacy 정보 등) 유실 방지 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
use App\Models\ItemMaster\ItemPage;
|
||||
use App\Models\Items\Item;
|
||||
use App\Models\Items\ItemDetail;
|
||||
use App\Models\Products\CommonCode;
|
||||
use App\Models\Scopes\TenantScope;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
@@ -425,7 +427,18 @@ public function index(array $params): LengthAwarePaginator
|
||||
}
|
||||
}
|
||||
|
||||
$paginator = $query->orderBy('id', 'desc')->paginate($size);
|
||||
// common_codes에서 item_type 한글명 조회 (서브쿼리로 컬럼 충돌 방지)
|
||||
$tableName = $query->getModel()->getTable();
|
||||
$query->addSelect([
|
||||
'item_type_name' => CommonCode::withoutGlobalScope(TenantScope::class)
|
||||
->select('name')
|
||||
->whereColumn('code', "{$tableName}.item_type")
|
||||
->where('code_group', 'item_type')
|
||||
->where('is_active', true)
|
||||
->limit(1),
|
||||
]);
|
||||
|
||||
$paginator = $query->orderBy("{$tableName}.id", 'desc')->paginate($size);
|
||||
|
||||
// 날짜 형식 변환, files 그룹화, options 펼침, code → item_code
|
||||
$paginator->setCollection(
|
||||
@@ -702,6 +715,12 @@ public function update(int $id, array $data): Model
|
||||
$this->validateBom($data['bom'], $id);
|
||||
}
|
||||
|
||||
// attributes 병합 (기존 값 보존, 새 값으로 덮어쓰기)
|
||||
if (isset($data['attributes']) && is_array($data['attributes'])) {
|
||||
$existingAttributes = is_array($item->attributes) ? $item->attributes : [];
|
||||
$data['attributes'] = array_merge($existingAttributes, $data['attributes']);
|
||||
}
|
||||
|
||||
// 테이블 업데이트
|
||||
$itemData = array_intersect_key($data, array_flip([
|
||||
'item_type', 'code', 'name', 'unit', 'category_id',
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
* GCS(Google Cloud Storage) URI 저장 컬럼 추가
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasColumn('sales_consultations', 'gcs_uri')) {
|
||||
Schema::table('sales_consultations', function (Blueprint $table) {
|
||||
$table->string('gcs_uri', 500)->nullable()->after('duration')->comment('GCS 저장 URI');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sales_consultations', function (Blueprint $table) {
|
||||
$table->dropColumn('gcs_uri');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user