fix(ecommerce): 배송비 구간 경계 포함 + 무게/부피 단위 환산

구간별 배송비의 종료값이 구간에 포함되지 않아 경계값이 무료배송으로
새고, 상품 옵션의 g/cm³ 저장값을 정책의 kg/L 로 환산하지 않아 금액이
1000배로 청구되던 문제를 수정한다.

- 구간 매칭을 종료값 오름차순 사다리로 교체 — 시작값은 표시 전용이
 되어 기존 저장 데이터의 두 형태 모두에서 정확히 계산된다
- 단위 환산을 배송비 계산 한 지점으로 모으고, 부피무게와 실무게를
 같은 kg 단위로 비교하도록 교정
- 계산이 조용히 0원이 되는 설정(구간 미등록·단위값/기준금액 누락·
 중간 구간 무제한·계산 API 폴백 0원)을 저장 시점에 차단하고,
 런타임 잔여 경로에는 경고 로그를 남긴다
- 연속성 규칙을 정책 타입별로 분리해 소수 구간(2.5kg) 저장을 허용
- 상품 옵션 무게/부피 응답 왕복, 주문 총 무게/부피 실값 기록
This commit is contained in:
HeuJung committed 2026-08-12 23:43:08 +09:00
1 parent 9131ee6bb7
commit 55bc9399e6
60 files changed
+4210 -420

No files matched your search

@@ -644,6 +644,79 @@ class OrderProcessingServiceTest extends ModuleTestCase
$this->assertStringContainsString('"items":[', json_encode($snapshot));
}
/**
* 주문의 총 무게/부피는 주문 옵션 소계의 합으로 기록된다 (공개 #94 / N7).
*
* 기존에는 0 으로 고정 기록되어, 배송사 연동·운임 정산이 이 값을 읽으면
* 무게 없는 주문으로 취급됐다. 값의 단위는 상품 옵션과 같은 g / cm³ 다.
*/
public function test_create_from_temp_order_records_total_weight_and_volume(): void
{
$user = User::factory()->create();
$product = Product::factory()->create();
$productOption = ProductOption::factory()->create([
'product_id' => $product->id,
'weight' => 500,
'volume' => 1200,
]);
$tempOrder = TempOrderFactory::new()
->forUser($user)
->withItems([
[
'cart_id' => 1,
'product_id' => $product->id,
'product_option_id' => $productOption->id,
'quantity' => 3,
],
])
->withCalculationResult([
'summary' => ['final_amount' => 103000],
'items' => [],
'promotions' => [
'product_promotions' => ['coupons' => [], 'discount_codes' => [], 'events' => []],
'order_promotions' => ['coupons' => [], 'discount_codes' => [], 'events' => []],
],
'validation_errors' => [],
])
->create();
$item = new ItemCalculation(
productId: $product->id,
productOptionId: $productOption->id,
quantity: 3,
unitPrice: 100000,
subtotal: 300000,
finalAmount: 300000,
);
$this->mockCalculationService($this->makeCalculationResult(103000, [
'items' => [$item],
]));
$order = $this->service->createFromTempOrder(
$tempOrder,
['name' => 'Test', 'phone' => '010-0000-0000', 'email' => 'test@test.com'],
['recipient_name' => 'Test', 'recipient_phone' => '010-0000-0000', 'zipcode' => '00000', 'address' => 'Test', 'address_detail' => 'Test'],
'card',
103000
);
$order->refresh();
// 단위 무게는 상품 옵션의 g 값을 그대로 복사한다 (kg 환산은 배송비 계산 시점에만)
$orderOption = $order->options()->first();
$this->assertEquals(500.0, (float) $orderOption->unit_weight);
$this->assertEquals(1200.0, (float) $orderOption->unit_volume);
$this->assertEquals(1500.0, (float) $orderOption->subtotal_weight);
$this->assertEquals(3600.0, (float) $orderOption->subtotal_volume);
// 주문 합계는 옵션 소계의 합
$this->assertEquals(1500.0, (float) $order->total_weight);
$this->assertEquals(3600.0, (float) $order->total_volume);
}
public function test_create_from_temp_order_saves_order_meta_with_calculation_input(): void
{
$this->allowAnyMileageUsage();