v7.0.0 release

This commit is contained in:
HeuJung committed 2026-07-01 10:30:32 +09:00
1 parent 0e7fa04b03
commit c4ea9a6cd1
3582 files changed
+626189 -160151

No files matched your search

@@ -0,0 +1,11 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
/**
* 빈 장바구니 예외
*
* 주문서 생성 시 장바구니가 비어 있을 때 발생합니다.
* 컨트롤러는 i18n 문자열 매칭 대신 이 타입으로 분기해 400 을 반환합니다 (U14/MP06).
*/
class CartEmptyException extends TempOrderException {}
@@ -0,0 +1,62 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 장바구니 단건 조작 예외 (항목없음/권한없음/옵션없음/타상품옵션)
*
* reason 에 따라 HTTP 상태코드와 메시지 키를 결정한다.
* 컨트롤러가 catch 하여 generic 500 대신 사유별 4xx(404/403/422)로 매핑한다.
* (체크아웃 전용 CartUnavailableException 과는 의미가 다른 별도 클래스 — MP07 §1-c)
*/
class CartOperationException extends Exception
{
/**
* @param string $reason 사유 (item_not_found|access_denied|option_not_found|invalid_option)
*/
public function __construct(private string $reason)
{
parent::__construct(__($this->getMessageKey()));
}
/**
* 사유 문자열을 반환합니다.
*
* @return string 사유 코드
*/
public function getReason(): string
{
return $this->reason;
}
/**
* 사유별 HTTP 상태코드를 반환합니다.
*
* @return int 404(항목없음) / 403(권한없음) / 422(옵션없음·타상품옵션)
*/
public function getStatusCode(): int
{
return match ($this->reason) {
'item_not_found' => 404,
'access_denied' => 403,
default => 422, // option_not_found, invalid_option
};
}
/**
* 사유별 다국어 메시지 키를 반환합니다. (전부 기존 키 — 신규 추가 없음)
*
* @return string lang 키
*/
public function getMessageKey(): string
{
return match ($this->reason) {
'item_not_found' => 'sirsoft-ecommerce::exceptions.cart_item_not_found',
'access_denied' => 'sirsoft-ecommerce::exceptions.cart_access_denied',
'invalid_option' => 'sirsoft-ecommerce::exceptions.invalid_option_for_product',
default => 'sirsoft-ecommerce::exceptions.option_not_found',
};
}
}
@@ -12,8 +12,8 @@ use Exception;
class CartUnavailableException extends Exception
{
/**
* @param string $message 예외 메시지
* @param array $unavailableItems 구매불가 상품 목록
* @param string $message 예외 메시지
* @param array $unavailableItems 구매불가 상품 목록
*/
public function __construct(
string $message,
@@ -26,20 +26,20 @@ class CartUnavailableException extends Exception
* 구매불가 상품 목록 반환
*
* @return array 구매불가 상품 배열
* [
* [
* 'cart_id' => int,
* 'product_id' => int,
* 'product_option_id' => int,
* 'name' => string,
* 'option' => string|null,
* 'thumbnail' => string|null,
* 'quantity' => int,
* 'stock' => int,
* 'reason' => 'stock'|'status', // 재고부족 or 판매상태
* ],
* ...
* ]
* [
* [
* 'cart_id' => int,
* 'product_id' => int,
* 'product_option_id' => int,
* 'name' => string,
* 'option' => string|null,
* 'thumbnail' => string|null,
* 'quantity' => int,
* 'stock' => int,
* 'reason' => 'stock'|'status'|'restricted'|'min_qty'|'max_qty', // 재고부족, 판매상태, 구매대상제한, 최소수량미달, 최대수량초과
* ],
* ...
* ]
*/
public function getUnavailableItems(): array
{
@@ -49,7 +49,7 @@ class CartUnavailableException extends Exception
/**
* 재고 부족 상품이 있는지 확인
*
* @return bool
* @return bool 재고 부족 상품 존재 여부
*/
public function hasStockIssue(): bool
{
@@ -65,7 +65,7 @@ class CartUnavailableException extends Exception
/**
* 판매상태 문제 상품이 있는지 확인
*
* @return bool
* @return bool 판매상태 문제 상품 존재 여부
*/
public function hasStatusIssue(): bool
{
@@ -78,10 +78,58 @@ class CartUnavailableException extends Exception
return false;
}
/**
* 구매 대상 제한(역할) 문제 상품이 있는지 확인
*
* @return bool 구매 대상 제한 상품 존재 여부
*/
public function hasRestrictionIssue(): bool
{
foreach ($this->unavailableItems as $item) {
if (($item['reason'] ?? '') === 'restricted') {
return true;
}
}
return false;
}
/**
* 최소 구매수량 미달 상품이 있는지 확인
*
* @return bool 최소 구매수량 미달 상품 존재 여부
*/
public function hasMinQtyIssue(): bool
{
foreach ($this->unavailableItems as $item) {
if (($item['reason'] ?? '') === 'min_qty') {
return true;
}
}
return false;
}
/**
* 최대 구매수량 초과 상품이 있는지 확인
*
* @return bool 최대 구매수량 초과 상품 존재 여부
*/
public function hasMaxQtyIssue(): bool
{
foreach ($this->unavailableItems as $item) {
if (($item['reason'] ?? '') === 'max_qty') {
return true;
}
}
return false;
}
/**
* 로깅용 전체 데이터 반환
*
* @return array
* @return array 구매불가 사유별 플래그를 포함한 로깅용 데이터
*/
public function toArray(): array
{
@@ -91,14 +139,77 @@ class CartUnavailableException extends Exception
'item_count' => count($this->unavailableItems),
'has_stock_issue' => $this->hasStockIssue(),
'has_status_issue' => $this->hasStatusIssue(),
'has_restriction_issue' => $this->hasRestrictionIssue(),
'has_min_qty_issue' => $this->hasMinQtyIssue(),
'has_max_qty_issue' => $this->hasMaxQtyIssue(),
];
}
/**
* 사용자에게 보여줄 구체 사유 메시지를 반환합니다.
*
* 첫 번째 구매불가 항목의 reason 에 맞춰 한도/상품명을 치환한 안내를 생성합니다.
* (재고/판매상태/구매대상제한/최소·최대 구매수량). 항목이 없거나 reason 미상이면
* 일반 메시지(cart_unavailable)로 폴백합니다.
*
* @return string 사용자용 안내 메시지
*/
public function getUserMessage(): string
{
$item = $this->unavailableItems[0] ?? null;
if (! $item) {
return __('sirsoft-ecommerce::exceptions.cart_unavailable');
}
$name = (string) ($item['name'] ?? '');
$prefix = $name !== '' ? $name.': ' : '';
$detail = match ($item['reason'] ?? '') {
'min_qty' => __('sirsoft-ecommerce::exceptions.min_purchase_qty_not_met', [
'limit' => $item['limit'] ?? 0,
'requested' => $item['requested'] ?? ($item['quantity'] ?? 0),
]),
'max_qty' => __('sirsoft-ecommerce::exceptions.max_purchase_qty_exceeded', [
'limit' => $item['limit'] ?? 0,
'requested' => $item['requested'] ?? ($item['quantity'] ?? 0),
]),
'status' => __('sirsoft-ecommerce::exceptions.product_unavailable'),
'restricted' => __('sirsoft-ecommerce::exceptions.purchase_not_allowed'),
'country_not_shippable' => __('sirsoft-ecommerce::exceptions.country_not_shippable'),
'stock' => __('sirsoft-ecommerce::exceptions.stock_exceeded', [
'requested' => $item['quantity'] ?? 0,
'available' => $item['stock'] ?? 0,
]),
'additional_option_invalid' => __('sirsoft-ecommerce::exceptions.additional_option_invalid'),
'additional_option_required' => __('sirsoft-ecommerce::exceptions.additional_option_required', [
'name' => $name,
]),
'additional_option_custom_text_required' => __('sirsoft-ecommerce::exceptions.additional_option_custom_text_required', [
'name' => $name,
]),
default => __('sirsoft-ecommerce::exceptions.cart_unavailable'),
};
// 추가옵션 reason 은 메시지에 그룹명(:name)을 이미 포함하므로 상품명 prefix 를 생략
$skipPrefixReasons = [
'additional_option_invalid',
'additional_option_required',
'additional_option_custom_text_required',
];
if (in_array($item['reason'] ?? '', $skipPrefixReasons, true)) {
return $detail;
}
return $prefix.$detail;
}
/**
* 구매불가 상품 목록으로 예외 생성 (팩토리 메서드)
*
* @param array $items 구매불가 상품 목록
* @return static
* @param array $items 구매불가 상품 목록
* @return static 구매불가 예외 인스턴스
*/
public static function fromItems(array $items): static
{
@@ -0,0 +1,22 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 마일리지 검증 예외
*
* 사용/차감 시 조건(잔액, 최소금액, 사용단위, 최대한도) 미충족 시 발생합니다.
* 메시지는 다국어 키로 해석된 문자열을 전달받습니다.
*/
class MileageValidationException extends Exception
{
/**
* @param string $message 검증 실패 메시지 (다국어 해석 완료된 문자열)
*/
public function __construct(string $message)
{
parent::__construct($message);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 주문 취소·환불 처리 예외
*
* 취소 불가 상태, 취소 옵션 부재/중복, 취소 수량 오류, 환불 금액 오류,
* PG 환불 실패 등 주문 취소·환불 라이프사이클에서 발생하는 비즈니스 예외입니다.
*/
class OrderCancellationException extends Exception
{
/**
* 생성자
*
* @param string $message 다국어 처리된 예외 메시지
*/
public function __construct(string $message)
{
parent::__construct($message);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 주문 수정 예외
*
* 배송 전이 아니어서 배송지를 변경할 수 없거나 대상 주소를 찾을 수 없는 등
* 주문 수정 과정에서 발생하는 비즈니스 예외입니다.
*/
class OrderModificationException extends Exception
{
/**
* 생성자
*
* @param string $message 다국어 처리된 예외 메시지
*/
public function __construct(string $message)
{
parent::__construct($message);
}
}
@@ -0,0 +1,23 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 주문 처리 예외
*
* 주문 금액 계산 검증 실패 등 주문 생성·처리 과정에서 발생하는 비즈니스 예외입니다.
*/
class OrderProcessingException extends Exception
{
/**
* 생성자
*
* @param string $message 다국어 처리된 예외 메시지
*/
public function __construct(string $message)
{
parent::__construct($message);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 상품 주문 이력 존재 예외
*
* 삭제하려는 상품에 주문 이력이 있을 때 발생합니다.
*/
class ProductHasOrderHistoryException extends Exception
{
/**
* @param int $count 주문 이력 건수
* @param string|null $message 예외 메시지
*/
public function __construct(int $count = 0, ?string $message = null)
{
parent::__construct(
$message ?? __('sirsoft-ecommerce::messages.products.has_order_history', ['count' => $count])
);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use RuntimeException;
/**
* 상품 이미지 업로드 최대 개수 초과 예외
*
* 상품당 허용된 최대 이미지 수를 초과하여 업로드를 시도할 때 발생합니다.
* 컨트롤러의 기존 catch (\Exception) 흐름에서 분기하여 422 응답을 반환합니다.
*/
class ProductImageUploadLimitException extends RuntimeException
{
/**
* @param int $maxImages 허용된 최대 이미지 수
*/
public function __construct(public readonly int $maxImages)
{
parent::__construct(
__('sirsoft-ecommerce::exceptions.product_image_limit_exceeded', ['max' => $maxImages])
);
}
}
@@ -0,0 +1,23 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 상품정보제공고시 템플릿을 찾을 수 없을 때 발생하는 예외
*/
class ProductNoticeTemplateNotFoundException extends Exception
{
/**
* @param int|null $templateId 템플릿 ID
*/
public function __construct(?int $templateId = null)
{
parent::__construct(
__('sirsoft-ecommerce::exceptions.product_notice_template_not_found', [
'id' => $templateId ?? '',
])
);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use RuntimeException;
/**
* 리뷰 이미지 업로드 최대 개수 초과 예외
*
* 리뷰당 허용된 최대 이미지 수를 초과하여 업로드를 시도할 때 발생합니다.
* 컨트롤러의 기존 catch (\RuntimeException) 흐름을 유지하기 위해 RuntimeException 을 상속합니다.
*/
class ReviewImageUploadLimitException extends RuntimeException
{
/**
* @param int $maxImages 허용된 최대 이미지 수
*/
public function __construct(int $maxImages)
{
parent::__construct(
__('sirsoft-ecommerce::review.image_upload_limit_exceeded', ['max' => $maxImages])
);
}
}
@@ -0,0 +1,35 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use RuntimeException;
/**
* 리뷰 작성 불가 예외
*
* 리뷰 작성 자격 검증(canWrite)에 실패한 상태에서 리뷰 생성을 시도할 때 발생합니다.
* 컨트롤러의 기존 catch (\RuntimeException) 흐름을 유지하기 위해 RuntimeException 을 상속합니다.
*/
class ReviewNotWritableException extends RuntimeException
{
/**
* @param string $reason 작성 불가 사유 식별자 (예: already_written, deadline_passed)
*/
public function __construct(
private string $reason
) {
parent::__construct(
__('sirsoft-ecommerce::messages.reviews.cannot_write', ['reason' => $reason])
);
}
/**
* 작성 불가 사유 식별자 반환
*
* @return string 사유 식별자
*/
public function getReason(): string
{
return $this->reason;
}
}
@@ -0,0 +1,24 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 임시 주문(주문서) 예외
*
* 장바구니가 비어 있거나 임시 주문을 찾을 수 없는 등
* 주문서 생성·조회 과정에서 발생하는 비즈니스 예외입니다.
*/
class TempOrderException extends Exception
{
/**
* 생성자
*
* @param string $message 다국어 처리된 예외 메시지
*/
public function __construct(string $message)
{
parent::__construct($message);
}
}
@@ -0,0 +1,11 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
/**
* 임시 주문(주문서) 미발견 예외
*
* 임시 주문이 만료되었거나 존재하지 않을 때 발생합니다.
* 컨트롤러는 i18n 문자열 매칭 대신 이 타입으로 분기해 404 를 반환합니다 (U14/MP06).
*/
class TempOrderNotFoundException extends TempOrderException {}
@@ -0,0 +1,41 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Exceptions;
use Exception;
/**
* 미지원 결제 통화 예외
*
* 주문의 결제 통화(order_currency)가 PG 가 청구할 수 없는 통화일 때 발생합니다.
* - 통화의 환율이 미설정/0 이하라 base 통화로 환산할 수 없는 경우
* - 환산 결과가 0 이하라 PG 최소 청구금액을 만족하지 못하는 경우
*
* 결제 통화 결정은 정상(유저 영속 통화 등)이나 그 통화로 결제할 수 없는 상황을
* 주문 생성 전에 명확한 422 로 차단하기 위한 예외입니다(서버 우회 방지).
*/
class UnsupportedPaymentCurrencyException extends Exception
{
/**
* 생성자
*
* @param string $currency 결제 통화 코드
* @param string $message 다국어 처리된 예외 메시지
*/
public function __construct(
protected string $currency,
string $message
) {
parent::__construct($message);
}
/**
* 결제 통화 코드를 반환합니다.
*
* @return string 결제 통화 코드
*/
public function getCurrency(): string
{
return $this->currency;
}
}