v7.0.0-beta.2 release
This commit is contained in:
1 parent
6595fd0eb5
commit
fa8eba7a0d
1165 files changed
+107118
-762127
No files matched your search
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Enums;
|
||||
|
||||
/**
|
||||
* 배송방법 Enum
|
||||
* 배송정책에서 사용 (ShippingTypeEnum과 별개)
|
||||
*/
|
||||
enum ShippingMethodEnum: string
|
||||
{
|
||||
case PARCEL = 'parcel'; // 택배
|
||||
case FREIGHT = 'freight'; // 화물
|
||||
case EXPRESS = 'express'; // 특급
|
||||
case ECONOMY = 'economy'; // 이코노미
|
||||
case EMS = 'ems'; // EMS
|
||||
case COLLECT = 'collect'; // 착불
|
||||
case QUICK = 'quick'; // 퀵서비스
|
||||
case DIRECT = 'direct'; // 직접배송
|
||||
case PICKUP = 'pickup'; // 방문수령
|
||||
case OTHER = 'other'; // 기타
|
||||
|
||||
/**
|
||||
* 다국어 라벨을 반환합니다.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return __('sirsoft-ecommerce::enums.shipping_method.'.$this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 프론트엔드용 라벨 키를 반환합니다.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label();
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 값 배열을 반환합니다.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
* 프론트엔드용 옵션 배열을 반환합니다.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function toSelectOptions(): array
|
||||
{
|
||||
return array_map(fn ($case) => [
|
||||
'value' => $case->value,
|
||||
'label' => $case->label(),
|
||||
], self::cases());
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Enums;
|
||||
|
||||
/**
|
||||
* 배송 유형 Enum
|
||||
*/
|
||||
enum ShippingTypeEnum: string
|
||||
{
|
||||
case DOMESTIC_PARCEL = 'domestic_parcel'; // 국내택배
|
||||
case DOMESTIC_EXPRESS = 'domestic_express'; // 국내특급
|
||||
case DOMESTIC_QUICK = 'domestic_quick'; // 퀵서비스
|
||||
case INTERNATIONAL_EMS = 'international_ems'; // 국제EMS
|
||||
case INTERNATIONAL_STANDARD = 'international_standard'; // 국제일반
|
||||
case PICKUP = 'pickup'; // 방문수령
|
||||
case CVS = 'cvs'; // 편의점택배
|
||||
case DIGITAL = 'digital'; // 디지털상품
|
||||
|
||||
/**
|
||||
* 다국어 라벨을 반환합니다.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return __('sirsoft-ecommerce::enums.shipping_type.'.$this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 프론트엔드용 라벨 키를 반환합니다.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label();
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 값 배열을 반환합니다.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
* 프론트엔드용 옵션 배열을 반환합니다.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function toSelectOptions(): array
|
||||
{
|
||||
return array_map(fn ($case) => [
|
||||
'value' => $case->value,
|
||||
'label' => $case->label(),
|
||||
], self::cases());
|
||||
}
|
||||
|
||||
/**
|
||||
* 국내 배송 유형 목록을 반환합니다.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function domesticTypes(): array
|
||||
{
|
||||
return [
|
||||
self::DOMESTIC_PARCEL,
|
||||
self::DOMESTIC_EXPRESS,
|
||||
self::DOMESTIC_QUICK,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 국제 배송 유형 목록을 반환합니다.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function internationalTypes(): array
|
||||
{
|
||||
return [
|
||||
self::INTERNATIONAL_EMS,
|
||||
self::INTERNATIONAL_STANDARD,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 중복 배송지명 예외
|
||||
*
|
||||
* 동일한 이름의 배송지가 이미 존재할 때 발생합니다.
|
||||
*/
|
||||
class DuplicateAddressException extends Exception
|
||||
{
|
||||
/**
|
||||
* @param int $duplicateAddressId 중복된 기존 배송지 ID
|
||||
*/
|
||||
public function __construct(
|
||||
private int $duplicateAddressId
|
||||
) {
|
||||
parent::__construct(__('sirsoft-ecommerce::messages.address.name_duplicate'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 중복된 기존 배송지 ID를 반환합니다.
|
||||
*
|
||||
* @return int 중복 배송지 ID
|
||||
*/
|
||||
public function getDuplicateAddressId(): int
|
||||
{
|
||||
return $this->duplicateAddressId;
|
||||
}
|
||||
}
|
||||
-176
@@ -1,176 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Controllers\Admin;
|
||||
|
||||
use App\Helpers\ResponseHelper;
|
||||
use App\Http\Controllers\Api\Base\AdminBaseController;
|
||||
use App\Http\Requests\MailTemplate\MailTemplateIndexRequest;
|
||||
use App\Http\Requests\MailTemplate\MailTemplatePreviewRequest;
|
||||
use App\Http\Requests\MailTemplate\UpdateMailTemplateRequest;
|
||||
use App\Http\Resources\MailTemplateCollection;
|
||||
use App\Http\Resources\MailTemplateResource;
|
||||
use Modules\Sirsoft\Ecommerce\Models\EcommerceMailTemplate;
|
||||
use Modules\Sirsoft\Ecommerce\Services\EcommerceMailTemplateService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 이커머스 메일 템플릿 관리 컨트롤러
|
||||
*/
|
||||
class EcommerceMailTemplateController extends AdminBaseController
|
||||
{
|
||||
/**
|
||||
* EcommerceMailTemplateController 생성자.
|
||||
*
|
||||
* @param EcommerceMailTemplateService $service 메일 템플릿 서비스
|
||||
*/
|
||||
public function __construct(
|
||||
private EcommerceMailTemplateService $service
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿 목록을 페이지네이션하여 조회합니다.
|
||||
*
|
||||
* @param MailTemplateIndexRequest $request 검증된 목록 조회 요청
|
||||
* @return JsonResponse 페이지네이션된 템플릿 목록
|
||||
*/
|
||||
public function index(MailTemplateIndexRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$filters = array_filter($request->validated(), fn ($value) => $value !== null);
|
||||
$perPage = (int) ($request->validated('per_page') ?? 20);
|
||||
$templates = $this->service->getTemplates($filters, $perPage);
|
||||
|
||||
$collection = new MailTemplateCollection($templates);
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_fetch_success',
|
||||
$collection->toArray($request)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_fetch_failed',
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿을 수정합니다.
|
||||
*
|
||||
* @param UpdateMailTemplateRequest $request 수정 요청
|
||||
* @param EcommerceMailTemplate $ecommerceMailTemplate 수정 대상
|
||||
* @return JsonResponse 수정 결과
|
||||
*/
|
||||
public function update(UpdateMailTemplateRequest $request, EcommerceMailTemplate $ecommerceMailTemplate): JsonResponse
|
||||
{
|
||||
try {
|
||||
$userId = $request->user()?->id;
|
||||
$template = $this->service->updateTemplate(
|
||||
$ecommerceMailTemplate,
|
||||
$request->validated(),
|
||||
$userId
|
||||
);
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_save_success',
|
||||
new MailTemplateResource($template)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_save_error',
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿의 활성 상태를 토글합니다.
|
||||
*
|
||||
* @param EcommerceMailTemplate $ecommerceMailTemplate 토글 대상
|
||||
* @return JsonResponse 토글 결과
|
||||
*/
|
||||
public function toggleActive(EcommerceMailTemplate $ecommerceMailTemplate): JsonResponse
|
||||
{
|
||||
try {
|
||||
$template = $this->service->toggleActive($ecommerceMailTemplate);
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_toggle_success',
|
||||
new MailTemplateResource($template)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_toggle_failed',
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿 미리보기를 반환합니다.
|
||||
*
|
||||
* @param MailTemplatePreviewRequest $request 검증된 미리보기 요청
|
||||
* @return JsonResponse 미리보기 결과
|
||||
*/
|
||||
public function preview(MailTemplatePreviewRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$result = $this->service->getPreview($request->validated());
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_preview_success',
|
||||
$result
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_preview_failed',
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿을 시더 기본값으로 복원합니다.
|
||||
*
|
||||
* @param EcommerceMailTemplate $ecommerceMailTemplate 복원 대상
|
||||
* @return JsonResponse 복원 결과
|
||||
*/
|
||||
public function reset(EcommerceMailTemplate $ecommerceMailTemplate): JsonResponse
|
||||
{
|
||||
try {
|
||||
$defaultData = $this->service->getDefaultTemplateData($ecommerceMailTemplate->type);
|
||||
|
||||
if (! $defaultData) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_reset_no_default',
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
$template = $this->service->resetToDefault($ecommerceMailTemplate, $defaultData);
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_reset_success',
|
||||
new MailTemplateResource($template)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.mail_template_reset_failed',
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+93
@@ -5,6 +5,7 @@ namespace Modules\Sirsoft\Ecommerce\Http\Controllers\Admin;
|
||||
use App\Helpers\PermissionHelper;
|
||||
use App\Helpers\ResponseHelper;
|
||||
use App\Http\Controllers\Api\Base\AdminBaseController;
|
||||
use App\Seo\Contracts\SeoCacheManagerInterface;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\GetSettingRequest;
|
||||
@@ -14,6 +15,7 @@ use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\UpdateSettingRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Services\ClaimReasonService;
|
||||
use Modules\Sirsoft\Ecommerce\Services\EcommerceSettingsService;
|
||||
use Modules\Sirsoft\Ecommerce\Services\ShippingCarrierService;
|
||||
use Modules\Sirsoft\Ecommerce\Services\ShippingTypeService;
|
||||
|
||||
/**
|
||||
* 이커머스 모듈 환경설정 컨트롤러
|
||||
@@ -25,6 +27,7 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
public function __construct(
|
||||
private EcommerceSettingsService $settingsService,
|
||||
private ShippingCarrierService $carrierService,
|
||||
private ShippingTypeService $shippingTypeService,
|
||||
private ClaimReasonService $claimReasonService
|
||||
) {}
|
||||
|
||||
@@ -38,6 +41,7 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
try {
|
||||
$settings = $this->settingsService->getAllSettings();
|
||||
$settings = $this->appendCarriersToSettings($settings);
|
||||
$settings = $this->appendShippingTypesToSettings($settings);
|
||||
$settings = $this->appendClaimReasonsToSettings($settings);
|
||||
$settings['available_pg_providers'] = $this->settingsService->getRegisteredPgProviders();
|
||||
$settings['abilities'] = [
|
||||
@@ -107,6 +111,13 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
unset($settings['shipping']['carriers']);
|
||||
}
|
||||
|
||||
// shipping.types는 DB 관리 대상 — JSON 저장에서 제외
|
||||
$shippingTypes = null;
|
||||
if (isset($settings['shipping']['types'])) {
|
||||
$shippingTypes = $settings['shipping']['types'];
|
||||
unset($settings['shipping']['types']);
|
||||
}
|
||||
|
||||
// claim.refund_reasons는 DB 관리 대상 — JSON 저장에서 제외
|
||||
$refundReasons = null;
|
||||
if (isset($settings['claim']['refund_reasons'])) {
|
||||
@@ -121,6 +132,11 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
$this->carrierService->syncCarriers($carriers);
|
||||
}
|
||||
|
||||
// shipping types DB 동기화
|
||||
if ($result && $shippingTypes !== null) {
|
||||
$this->shippingTypeService->syncShippingTypes($shippingTypes);
|
||||
}
|
||||
|
||||
// claim reasons DB 동기화
|
||||
if ($result && $refundReasons !== null) {
|
||||
$this->claimReasonService->syncReasons('refund', $refundReasons);
|
||||
@@ -130,6 +146,7 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
// 저장 후 전체 설정 반환 (관리자 UI 상태 업데이트용)
|
||||
$updatedSettings = $this->settingsService->getAllSettings();
|
||||
$updatedSettings = $this->appendCarriersToSettings($updatedSettings);
|
||||
$updatedSettings = $this->appendShippingTypesToSettings($updatedSettings);
|
||||
$updatedSettings = $this->appendClaimReasonsToSettings($updatedSettings);
|
||||
$updatedSettings['available_pg_providers'] = $this->settingsService->getRegisteredPgProviders();
|
||||
|
||||
@@ -266,6 +283,7 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
{
|
||||
try {
|
||||
$this->settingsService->clearCache();
|
||||
app(SeoCacheManagerInterface::class)->clearAll();
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
@@ -281,6 +299,66 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SEO 캐시 정보를 조회합니다.
|
||||
*
|
||||
* @return JsonResponse 캐시 페이지 수 및 용량을 포함한 JSON 응답
|
||||
*/
|
||||
public function seoCacheInfo(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$cacheManager = app(SeoCacheManagerInterface::class);
|
||||
$urls = $cacheManager->getCachedUrls();
|
||||
$count = count($urls);
|
||||
|
||||
// 각 캐시 엔트리의 HTML 크기를 합산하여 총 용량 계산
|
||||
$totalBytes = 0;
|
||||
foreach ($urls as $url) {
|
||||
foreach (config('app.supported_locales', ['ko']) as $locale) {
|
||||
$html = $cacheManager->get($url, $locale);
|
||||
if ($html !== null) {
|
||||
$totalBytes += strlen($html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.settings.fetch_success',
|
||||
[
|
||||
'count' => $count,
|
||||
'size_bytes' => $totalBytes,
|
||||
'size_formatted' => $this->formatBytes($totalBytes),
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.settings.fetch_failed',
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 바이트를 사람이 읽기 쉬운 형태로 변환합니다.
|
||||
*
|
||||
* @param int $bytes 바이트 수
|
||||
* @return string 포맷된 문자열 (예: "1.5 MB")
|
||||
*/
|
||||
private function formatBytes(int $bytes): string
|
||||
{
|
||||
if ($bytes === 0) {
|
||||
return '0 B';
|
||||
}
|
||||
|
||||
$units = ['B', 'KB', 'MB', 'GB'];
|
||||
$i = (int) floor(log($bytes, 1024));
|
||||
$i = min($i, count($units) - 1);
|
||||
|
||||
return round($bytes / (1024 ** $i), 1).' '.$units[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정 응답에 배송사 목록을 추가합니다.
|
||||
*
|
||||
@@ -306,6 +384,21 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정 응답에 배송유형 목록을 추가합니다.
|
||||
*
|
||||
* DB 관리 대상인 shipping types를 shipping 섹션에 포함시킵니다.
|
||||
*
|
||||
* @param array $settings 설정 배열
|
||||
* @return array shipping types가 추가된 설정 배열
|
||||
*/
|
||||
private function appendShippingTypesToSettings(array $settings): array
|
||||
{
|
||||
$settings['shipping']['types'] = $this->shippingTypeService->getTypesForSettings();
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정 응답에 클래임 사유 목록을 추가합니다.
|
||||
*
|
||||
|
||||
+8
-2
@@ -8,6 +8,7 @@ use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\DuplicateAddressException;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\User\StoreUserAddressRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\User\UpdateUserAddressRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Resources\UserAddressCollection;
|
||||
@@ -112,8 +113,13 @@ class UserAddressController extends AuthBaseController
|
||||
return ResponseHelper::success('sirsoft-ecommerce::messages.address.created', [
|
||||
'address' => new UserAddressResource($address),
|
||||
], 201);
|
||||
} catch (\Illuminate\Http\Exceptions\HttpResponseException $e) {
|
||||
throw $e;
|
||||
} catch (DuplicateAddressException $e) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.address.name_duplicate',
|
||||
409,
|
||||
['duplicate_address_id' => $e->getDuplicateAddressId()]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
Log::error('User address creation failed', [
|
||||
'message' => $e->getMessage(),
|
||||
|
||||
@@ -9,7 +9,7 @@ use Modules\Sirsoft\Ecommerce\Enums\DeviceTypeEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\OrderDateTypeEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\OrderStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\PaymentMethodEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingTypeEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ShippingType;
|
||||
|
||||
/**
|
||||
* 주문 목록 조회 요청
|
||||
@@ -53,7 +53,7 @@ class OrderListRequest extends FormRequest
|
||||
|
||||
// 배송유형 (다중선택)
|
||||
'shipping_type' => ['nullable', 'array'],
|
||||
'shipping_type.*' => ['string', Rule::in(ShippingTypeEnum::values())],
|
||||
'shipping_type.*' => ['string', Rule::in(ShippingType::pluck('code')->toArray())],
|
||||
|
||||
// 결제수단 (다중선택)
|
||||
'payment_method' => ['nullable', 'array'],
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ use App\Extension\HookManager;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ChargePolicyEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingMethodEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ShippingType;
|
||||
|
||||
/**
|
||||
* 배송정책 목록 조회 요청
|
||||
@@ -36,7 +36,7 @@ class ShippingPolicyListRequest extends FormRequest
|
||||
|
||||
// 배송방법 (다중선택)
|
||||
'shipping_methods' => ['nullable', 'array'],
|
||||
'shipping_methods.*' => ['string', Rule::in(ShippingMethodEnum::values())],
|
||||
'shipping_methods.*' => ['string', Rule::in(ShippingType::pluck('code')->toArray())],
|
||||
|
||||
// 부과정책 (다중선택)
|
||||
'charge_policies' => ['nullable', 'array'],
|
||||
|
||||
+104
-10
@@ -32,7 +32,13 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'_tab' => ['sometimes', 'string', 'in:basic_info,language_currency,seo,order_settings,claim,shipping,review_settings,mail_templates,inquiry'],
|
||||
'_tab' => ['sometimes', 'string', 'in:basic_info,language_currency,seo,order_settings,claim,shipping,review_settings,notification_definitions,notifications,inquiry'],
|
||||
|
||||
'notifications' => ['sometimes', 'array'],
|
||||
'notifications.channels' => ['sometimes', 'array'],
|
||||
'notifications.channels.*.id' => ['required_with:notifications.channels', 'string', 'max:50'],
|
||||
'notifications.channels.*.is_active' => ['required_with:notifications.channels', 'boolean'],
|
||||
'notifications.channels.*.sort_order' => ['nullable', 'integer', 'min:0'],
|
||||
|
||||
'basic_info' => ['sometimes', 'array'],
|
||||
'basic_info.shop_name' => ['required_with:basic_info', 'string', 'max:255'],
|
||||
@@ -81,9 +87,12 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
'seo.meta_search_description' => ['nullable', 'string', 'max:1000'],
|
||||
'seo.meta_product_title' => ['nullable', 'string', 'max:500'],
|
||||
'seo.meta_product_description' => ['nullable', 'string', 'max:1000'],
|
||||
'seo.meta_shop_index_title' => ['nullable', 'string', 'max:500'],
|
||||
'seo.meta_shop_index_description' => ['nullable', 'string', 'max:1000'],
|
||||
'seo.seo_category' => ['nullable', 'boolean'],
|
||||
'seo.seo_search_result' => ['nullable', 'boolean'],
|
||||
'seo.seo_product_detail' => ['nullable', 'boolean'],
|
||||
'seo.seo_shop_index' => ['nullable', 'boolean'],
|
||||
|
||||
// inquiry 섹션
|
||||
'inquiry' => ['sometimes', 'array'],
|
||||
@@ -145,9 +154,6 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
'shipping.available_countries.*.name.*' => ['string', 'max:100'],
|
||||
'shipping.available_countries.*.is_active' => ['nullable', 'boolean'],
|
||||
'shipping.international_shipping_enabled' => ['nullable', 'boolean'],
|
||||
'shipping.remote_area_enabled' => ['nullable', 'boolean'],
|
||||
'shipping.remote_area_extra_fee' => ['nullable', 'integer', 'min:0'],
|
||||
'shipping.island_extra_fee' => ['nullable', 'integer', 'min:0'],
|
||||
'shipping.free_shipping_threshold' => ['nullable', 'integer', 'min:0'],
|
||||
'shipping.free_shipping_enabled' => ['nullable', 'boolean'],
|
||||
'shipping.address_validation_enabled' => ['nullable', 'boolean'],
|
||||
@@ -162,6 +168,15 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
'shipping.carriers.*.tracking_url' => ['nullable', 'string', 'max:500'],
|
||||
'shipping.carriers.*.is_active' => ['nullable', 'boolean'],
|
||||
'shipping.carriers.*.sort_order' => ['nullable', 'integer', 'min:0'],
|
||||
|
||||
// shipping.types 섹션 (DB 동기화 대상)
|
||||
'shipping.types' => ['nullable', 'array'],
|
||||
'shipping.types.*.id' => ['nullable', 'integer'],
|
||||
'shipping.types.*.code' => ['required_with:shipping.types', 'string', 'max:50', 'regex:/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/'],
|
||||
'shipping.types.*.name' => ['required_with:shipping.types', 'array', new LocaleRequiredTranslatable(maxLength: 100)],
|
||||
'shipping.types.*.category' => ['required_with:shipping.types', 'string', 'in:domestic,international,other'],
|
||||
'shipping.types.*.is_active' => ['nullable', 'boolean'],
|
||||
'shipping.types.*.sort_order' => ['nullable', 'integer', 'min:0'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -193,6 +208,8 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
$this->validateDefaultCountryExists($validator);
|
||||
$this->validateUniqueCarrierCodes($validator);
|
||||
$this->validateCarrierNames($validator);
|
||||
$this->validateUniqueShippingTypeCodes($validator);
|
||||
$this->validateShippingTypeNames($validator);
|
||||
$this->validateUniqueRefundReasonCodes($validator);
|
||||
$this->validateRefundReasonNames($validator);
|
||||
});
|
||||
@@ -529,6 +546,72 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송유형 코드 중복 검증
|
||||
*
|
||||
* @param Validator $validator Validator 인스턴스
|
||||
*/
|
||||
protected function validateUniqueShippingTypeCodes(Validator $validator): void
|
||||
{
|
||||
$types = $this->input('shipping.types', []);
|
||||
|
||||
if (empty($types) || ! is_array($types)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$codes = [];
|
||||
foreach ($types as $index => $type) {
|
||||
if (! isset($type['code'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$code = strtolower(trim($type['code']));
|
||||
if (in_array($code, $codes)) {
|
||||
$validator->errors()->add(
|
||||
"shipping.types.{$index}.code",
|
||||
__('sirsoft-ecommerce::validation.custom.shipping.types.duplicate_code')
|
||||
);
|
||||
}
|
||||
$codes[] = $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송유형명 필수 검증 - ko 로케일에 이름이 있어야 함
|
||||
*
|
||||
* @param Validator $validator Validator 인스턴스
|
||||
*/
|
||||
protected function validateShippingTypeNames(Validator $validator): void
|
||||
{
|
||||
$types = $this->input('shipping.types', []);
|
||||
|
||||
if (empty($types) || ! is_array($types)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($types as $index => $type) {
|
||||
$name = $type['name'] ?? [];
|
||||
|
||||
if (! is_array($name) || empty($name)) {
|
||||
$validator->errors()->add(
|
||||
"shipping.types.{$index}.name",
|
||||
__('sirsoft-ecommerce::validation.custom.shipping.types.name_required')
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$locale = app()->getLocale();
|
||||
$localeName = $name[$locale] ?? '';
|
||||
if (! is_string($localeName) || trim($localeName) === '') {
|
||||
$validator->errors()->add(
|
||||
"shipping.types.{$index}.name.{$locale}",
|
||||
__('sirsoft-ecommerce::validation.custom.shipping.types.name_required')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 환불 사유 코드 중복 검증
|
||||
*
|
||||
@@ -697,6 +780,11 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
'seo.seo_category.boolean' => __('sirsoft-ecommerce::validation.custom.seo.seo_category.boolean'),
|
||||
'seo.seo_search_result.boolean' => __('sirsoft-ecommerce::validation.custom.seo.seo_search_result.boolean'),
|
||||
'seo.seo_product_detail.boolean' => __('sirsoft-ecommerce::validation.custom.seo.seo_product_detail.boolean'),
|
||||
'seo.meta_shop_index_title.string' => __('sirsoft-ecommerce::validation.custom.seo.meta_shop_index_title.string'),
|
||||
'seo.meta_shop_index_title.max' => __('sirsoft-ecommerce::validation.custom.seo.meta_shop_index_title.max'),
|
||||
'seo.meta_shop_index_description.string' => __('sirsoft-ecommerce::validation.custom.seo.meta_shop_index_description.string'),
|
||||
'seo.meta_shop_index_description.max' => __('sirsoft-ecommerce::validation.custom.seo.meta_shop_index_description.max'),
|
||||
'seo.seo_shop_index.boolean' => __('sirsoft-ecommerce::validation.custom.seo.seo_shop_index.boolean'),
|
||||
|
||||
// order_settings 섹션 - banks
|
||||
'order_settings.banks.*.code.required_with' => __('sirsoft-ecommerce::validation.custom.banks.code.required_with'),
|
||||
@@ -758,11 +846,6 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
'shipping.available_countries.*.name.*.max' => __('sirsoft-ecommerce::validation.custom.shipping.available_countries.name.max'),
|
||||
'shipping.available_countries.*.is_active.boolean' => __('sirsoft-ecommerce::validation.custom.shipping.available_countries.is_active.boolean'),
|
||||
'shipping.international_shipping_enabled.boolean' => __('sirsoft-ecommerce::validation.custom.shipping.international_shipping_enabled.boolean'),
|
||||
'shipping.remote_area_enabled.boolean' => __('sirsoft-ecommerce::validation.custom.shipping.remote_area_enabled.boolean'),
|
||||
'shipping.remote_area_extra_fee.integer' => __('sirsoft-ecommerce::validation.custom.shipping.remote_area_extra_fee.integer'),
|
||||
'shipping.remote_area_extra_fee.min' => __('sirsoft-ecommerce::validation.custom.shipping.remote_area_extra_fee.min'),
|
||||
'shipping.island_extra_fee.integer' => __('sirsoft-ecommerce::validation.custom.shipping.island_extra_fee.integer'),
|
||||
'shipping.island_extra_fee.min' => __('sirsoft-ecommerce::validation.custom.shipping.island_extra_fee.min'),
|
||||
'shipping.free_shipping_threshold.integer' => __('sirsoft-ecommerce::validation.custom.shipping.free_shipping_threshold.integer'),
|
||||
'shipping.free_shipping_threshold.min' => __('sirsoft-ecommerce::validation.custom.shipping.free_shipping_threshold.min'),
|
||||
'shipping.free_shipping_enabled.boolean' => __('sirsoft-ecommerce::validation.custom.shipping.free_shipping_enabled.boolean'),
|
||||
@@ -782,6 +865,17 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
'shipping.carriers.*.tracking_url.string' => __('sirsoft-ecommerce::validation.custom.shipping.carriers.tracking_url.string'),
|
||||
'shipping.carriers.*.tracking_url.max' => __('sirsoft-ecommerce::validation.custom.shipping.carriers.tracking_url.max'),
|
||||
'shipping.carriers.*.is_active.boolean' => __('sirsoft-ecommerce::validation.custom.shipping.carriers.is_active.boolean'),
|
||||
|
||||
// shipping.types 섹션
|
||||
'shipping.types.*.code.required_with' => __('sirsoft-ecommerce::validation.custom.shipping.types.code.required_with'),
|
||||
'shipping.types.*.code.string' => __('sirsoft-ecommerce::validation.custom.shipping.types.code.string'),
|
||||
'shipping.types.*.code.max' => __('sirsoft-ecommerce::validation.custom.shipping.types.code.max'),
|
||||
'shipping.types.*.code.regex' => __('sirsoft-ecommerce::validation.custom.shipping.types.code.regex'),
|
||||
'shipping.types.*.name.required_with' => __('sirsoft-ecommerce::validation.custom.shipping.types.name.required_with'),
|
||||
'shipping.types.*.name.array' => __('sirsoft-ecommerce::validation.custom.shipping.types.name.array'),
|
||||
'shipping.types.*.category.required_with' => __('sirsoft-ecommerce::validation.custom.shipping.types.category.required_with'),
|
||||
'shipping.types.*.category.in' => __('sirsoft-ecommerce::validation.custom.shipping.types.category.in'),
|
||||
'shipping.types.*.is_active.boolean' => __('sirsoft-ecommerce::validation.custom.shipping.types.is_active.boolean'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -796,7 +890,7 @@ class StoreEcommerceSettingsRequest extends FormRequest
|
||||
public function validatedSettings(): array
|
||||
{
|
||||
$validated = $this->validated();
|
||||
$validCategories = ['basic_info', 'language_currency', 'seo', 'order_settings', 'claim', 'shipping', 'review_settings', 'inquiry'];
|
||||
$validCategories = ['basic_info', 'language_currency', 'seo', 'order_settings', 'claim', 'shipping', 'review_settings', 'inquiry', 'notifications'];
|
||||
|
||||
return array_filter(
|
||||
$validated,
|
||||
|
||||
+37
-2
@@ -7,7 +7,7 @@ use App\Rules\LocaleRequiredTranslatable;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ChargePolicyEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingMethodEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ShippingType;
|
||||
|
||||
/**
|
||||
* 배송정책 생성 요청
|
||||
@@ -37,7 +37,9 @@ class StoreShippingPolicyRequest extends FormRequest
|
||||
// 국가별 설정 (최소 1개 필수)
|
||||
'country_settings' => ['required', 'array', 'min:1'],
|
||||
'country_settings.*.country_code' => ['required', 'string', 'max:10', 'distinct'],
|
||||
'country_settings.*.shipping_method' => ['required', Rule::enum(ShippingMethodEnum::class)],
|
||||
'country_settings.*.shipping_method' => ['required', 'string', Rule::in(ShippingType::pluck('code')->toArray())],
|
||||
'country_settings.*.custom_shipping_name' => ['nullable', 'array'],
|
||||
'country_settings.*.custom_shipping_name.*' => ['nullable', 'string', 'max:100'],
|
||||
'country_settings.*.currency_code' => ['required', 'string', 'max:10'],
|
||||
'country_settings.*.charge_policy' => ['required', Rule::enum(ChargePolicyEnum::class)],
|
||||
|
||||
@@ -111,6 +113,7 @@ class StoreShippingPolicyRequest extends FormRequest
|
||||
$validator->after(function (\Illuminate\Validation\Validator $validator) {
|
||||
$this->validateRangeTiersContinuity($validator);
|
||||
$this->validateNonFreeBaseFee($validator);
|
||||
$this->validateCustomShippingName($validator);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -224,6 +227,38 @@ class StoreShippingPolicyRequest extends FormRequest
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* custom 배송방법 선택 시 custom_shipping_name 필수 검증
|
||||
*
|
||||
* @param \Illuminate\Validation\Validator $validator Validator 인스턴스
|
||||
*/
|
||||
private function validateCustomShippingName(\Illuminate\Validation\Validator $validator): void
|
||||
{
|
||||
$countrySettings = $this->input('country_settings', []);
|
||||
|
||||
if (! is_array($countrySettings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$locale = app()->getLocale();
|
||||
|
||||
foreach ($countrySettings as $i => $cs) {
|
||||
if (($cs['shipping_method'] ?? '') !== 'custom') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$customName = $cs['custom_shipping_name'] ?? [];
|
||||
$localeName = is_array($customName) ? trim($customName[$locale] ?? $customName['ko'] ?? '') : '';
|
||||
|
||||
if ($localeName === '') {
|
||||
$validator->errors()->add(
|
||||
"country_settings.{$i}.custom_shipping_name.{$locale}",
|
||||
__('sirsoft-ecommerce::validation.shipping_policy.custom_shipping_name_required')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 데이터 전처리
|
||||
*
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use App\Http\Resources\Traits\HasRowNumber;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
/**
|
||||
* 브랜드 컬렉션 리소스
|
||||
*
|
||||
* 브랜드 목록을 페이지네이션 및 통계와 함께 반환합니다.
|
||||
*/
|
||||
class BrandCollection extends ResourceCollection
|
||||
class BrandCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
use HasRowNumber;
|
||||
|
||||
/**
|
||||
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
|
||||
|
||||
@@ -4,14 +4,14 @@ namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
|
||||
/**
|
||||
* 카테고리 컬렉션 리소스
|
||||
*
|
||||
* 카테고리 목록을 계층 구조 및 권한 정보와 함께 반환합니다.
|
||||
*/
|
||||
class CategoryCollection extends ResourceCollection
|
||||
class CategoryCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use App\Http\Resources\Traits\HasRowNumber;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
/**
|
||||
* 클래임 사유 컬렉션 리소스
|
||||
*
|
||||
* 클래임 사유 목록을 반환합니다.
|
||||
*/
|
||||
class ClaimReasonCollection extends ResourceCollection
|
||||
class ClaimReasonCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
use HasRowNumber;
|
||||
|
||||
/**
|
||||
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
|
||||
|
||||
@@ -4,13 +4,13 @@ namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* 쿠폰 컬렉션 리소스
|
||||
*/
|
||||
class CouponCollection extends ResourceCollection
|
||||
class CouponCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* 쿠폰 발급 내역 컬렉션 리소스
|
||||
*/
|
||||
class CouponIssueCollection extends ResourceCollection
|
||||
class CouponIssueCollection extends BaseApiCollection
|
||||
{
|
||||
/**
|
||||
* The resource that this resource collects.
|
||||
|
||||
+2
-4
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use App\Http\Resources\Traits\HasRowNumber;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
@@ -13,10 +12,9 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
*
|
||||
* 추가배송비 템플릿 목록을 페이지네이션 및 통계와 함께 반환합니다.
|
||||
*/
|
||||
class ExtraFeeTemplateCollection extends ResourceCollection
|
||||
class ExtraFeeTemplateCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
use HasRowNumber;
|
||||
|
||||
/**
|
||||
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use App\Http\Resources\Traits\HasRowNumber;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
@@ -13,10 +12,9 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
*
|
||||
* 주문 목록을 페이지네이션 및 통계와 함께 반환합니다.
|
||||
*/
|
||||
class OrderCollection extends ResourceCollection
|
||||
class OrderCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
use HasRowNumber;
|
||||
|
||||
/**
|
||||
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
|
||||
|
||||
@@ -88,12 +88,19 @@ class OrderListResource extends BaseApiResource
|
||||
]),
|
||||
|
||||
// 배송 (첫 번째)
|
||||
'shipping' => $this->whenLoaded('shippings', fn () => [
|
||||
'shipping_type' => $this->shippings->first()?->shipping_type,
|
||||
'shipping_type_label' => $this->shippings->first()?->shipping_type?->label(),
|
||||
'carrier_name' => $this->shippings->first()?->carrier?->getLocalizedName(),
|
||||
'tracking_number' => $this->shippings->first()?->tracking_number,
|
||||
]),
|
||||
'shipping' => $this->whenLoaded('shippings', function () {
|
||||
$shipping = $this->shippings->first();
|
||||
|
||||
return [
|
||||
'shipping_type' => $shipping?->shipping_type,
|
||||
'shipping_type_label' => $shipping?->shipping_type
|
||||
? \Modules\Sirsoft\Ecommerce\Models\ShippingType::getCachedByCode($shipping->shipping_type)?->getLocalizedName()
|
||||
: null,
|
||||
'shipping_method_label' => $this->resolveSnapshotMethodLabel($shipping),
|
||||
'carrier_name' => $shipping?->carrier?->getLocalizedName(),
|
||||
'tracking_number' => $shipping?->tracking_number,
|
||||
];
|
||||
}),
|
||||
|
||||
// 권한 정보 (is_owner + abilities)
|
||||
...$this->resourceMeta($request),
|
||||
@@ -147,4 +154,37 @@ class OrderListResource extends BaseApiResource
|
||||
|
||||
return ! empty($result) ? $result : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 스냅샷 기반 배송방법 라벨을 해석합니다.
|
||||
*
|
||||
* @param \Modules\Sirsoft\Ecommerce\Models\OrderShipping|null $shipping 배송 레코드
|
||||
* @return string|null
|
||||
*/
|
||||
private function resolveSnapshotMethodLabel(?\Modules\Sirsoft\Ecommerce\Models\OrderShipping $shipping): ?string
|
||||
{
|
||||
if (! $shipping) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$snapshot = $shipping->delivery_policy_snapshot;
|
||||
$method = $snapshot['shipping_method'] ?? null;
|
||||
|
||||
if (! $method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($method === 'custom') {
|
||||
$name = $snapshot['custom_shipping_name'] ?? null;
|
||||
if (is_array($name)) {
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return $name[$locale] ?? $name['ko'] ?? $name[array_key_first($name)] ?? null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Modules\Sirsoft\Ecommerce\Models\ShippingType::getCachedByCode($method)?->getLocalizedName();
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,36 @@ class OrderOptionResource extends BaseApiResource
|
||||
return $this->shippings->first()?->delivery_policy_snapshot['policy_name'] ?? null;
|
||||
}),
|
||||
'shipping_type_label' => $this->whenLoaded('shippings', function () {
|
||||
return $this->shippings->first()?->shipping_type?->label();
|
||||
$shippingType = $this->shippings->first()?->shipping_type;
|
||||
|
||||
return $shippingType
|
||||
? \Modules\Sirsoft\Ecommerce\Models\ShippingType::getCachedByCode($shippingType)?->getLocalizedName()
|
||||
: null;
|
||||
}),
|
||||
'shipping_method_label' => $this->whenLoaded('shippings', function () {
|
||||
$shipping = $this->shippings->first();
|
||||
if (! $shipping) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$snapshot = $shipping->delivery_policy_snapshot;
|
||||
$method = $snapshot['shipping_method'] ?? null;
|
||||
if (! $method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($method === 'custom') {
|
||||
$name = $snapshot['custom_shipping_name'] ?? null;
|
||||
if (is_array($name)) {
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return $name[$locale] ?? $name['ko'] ?? $name[array_key_first($name)] ?? null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Modules\Sirsoft\Ecommerce\Models\ShippingType::getCachedByCode($method)?->getLocalizedName();
|
||||
}),
|
||||
'shipping_amount' => $this->whenLoaded('shippings', function () {
|
||||
return $this->shippings->first()?->total_shipping_amount ?? 0;
|
||||
|
||||
@@ -27,7 +27,11 @@ class OrderShippingResource extends BaseApiResource
|
||||
'shipping_status_label' => $this->shipping_status ? $this->shipping_status->label() : null,
|
||||
'shipping_status_variant' => $this->shipping_status ? $this->shipping_status->variant() : null,
|
||||
'shipping_type' => $this->shipping_type,
|
||||
'shipping_type_label' => $this->shipping_type ? $this->shipping_type->label() : null,
|
||||
'shipping_type_label' => $this->shipping_type
|
||||
? \Modules\Sirsoft\Ecommerce\Models\ShippingType::getCachedByCode($this->shipping_type)?->getLocalizedName()
|
||||
: null,
|
||||
'shipping_method' => $this->delivery_policy_snapshot['shipping_method'] ?? null,
|
||||
'shipping_method_label' => $this->resolveSnapshotShippingMethodLabel(),
|
||||
'shipping_policy_id' => $this->shipping_policy_id,
|
||||
'base_shipping_amount' => $this->base_shipping_amount,
|
||||
'base_shipping_amount_formatted' => number_format($this->base_shipping_amount).'원',
|
||||
@@ -60,4 +64,32 @@ class OrderShippingResource extends BaseApiResource
|
||||
'visit_pickup_phone' => $this->visit_pickup_phone,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 스냅샷 기반 배송방법 라벨을 해석합니다.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function resolveSnapshotShippingMethodLabel(): ?string
|
||||
{
|
||||
$snapshot = $this->delivery_policy_snapshot;
|
||||
$method = $snapshot['shipping_method'] ?? null;
|
||||
|
||||
if (! $method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($method === 'custom') {
|
||||
$name = $snapshot['custom_shipping_name'] ?? null;
|
||||
if (is_array($name)) {
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return $name[$locale] ?? $name['ko'] ?? $name[array_key_first($name)] ?? null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Modules\Sirsoft\Ecommerce\Models\ShippingType::getCachedByCode($method)?->getLocalizedName();
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use App\Http\Resources\Traits\HasRowNumber;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
@@ -13,10 +12,9 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
*
|
||||
* 상품 목록을 페이지네이션 및 통계와 함께 반환합니다.
|
||||
*/
|
||||
class ProductCollection extends ResourceCollection
|
||||
class ProductCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
use HasRowNumber;
|
||||
|
||||
/**
|
||||
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
|
||||
|
||||
+2
-2
@@ -4,14 +4,14 @@ namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
|
||||
/**
|
||||
* 공통정보 템플릿 컬렉션 리소스
|
||||
*
|
||||
* 공통정보 목록을 abilities와 함께 반환합니다.
|
||||
*/
|
||||
class ProductCommonInfoCollection extends ResourceCollection
|
||||
class ProductCommonInfoCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@ namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
|
||||
/**
|
||||
* 상품 라벨 컬렉션 리소스
|
||||
*
|
||||
* 라벨 목록을 abilities와 함께 반환합니다.
|
||||
*/
|
||||
class ProductLabelCollection extends ResourceCollection
|
||||
class ProductLabelCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
|
||||
|
||||
+2
-2
@@ -4,14 +4,14 @@ namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
|
||||
/**
|
||||
* 상품정보제공고시 템플릿 컬렉션 리소스
|
||||
*
|
||||
* 템플릿 목록을 abilities와 함께 반환합니다.
|
||||
*/
|
||||
class ProductNoticeTemplateCollection extends ResourceCollection
|
||||
class ProductNoticeTemplateCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ class PublicProductResource extends BaseApiResource
|
||||
'short_description_localized' => $this->resolveLocalizedField($this->short_description),
|
||||
'description' => $this->description,
|
||||
'description_localized' => $this->getLocalizedDescription(),
|
||||
'description_mode' => $this->description_mode,
|
||||
|
||||
// 이미지
|
||||
'images' => ProductImageResource::collection($this->whenLoaded('images')),
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use App\Http\Resources\Traits\HasRowNumber;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
/**
|
||||
* 배송사 컬렉션 리소스
|
||||
*
|
||||
* 배송사 목록을 반환합니다.
|
||||
*/
|
||||
class ShippingCarrierCollection extends ResourceCollection
|
||||
class ShippingCarrierCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
use HasRowNumber;
|
||||
|
||||
/**
|
||||
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use App\Http\Resources\Traits\HasAbilityCheck;
|
||||
use App\Http\Resources\Traits\HasRowNumber;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
@@ -13,10 +12,9 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
*
|
||||
* 배송정책 목록을 페이지네이션 및 통계와 함께 반환합니다.
|
||||
*/
|
||||
class ShippingPolicyCollection extends ResourceCollection
|
||||
class ShippingPolicyCollection extends BaseApiCollection
|
||||
{
|
||||
use HasAbilityCheck;
|
||||
use HasRowNumber;
|
||||
|
||||
/**
|
||||
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
|
||||
@@ -101,11 +99,25 @@ class ShippingPolicyCollection extends ResourceCollection
|
||||
public function toSimpleArray(): array
|
||||
{
|
||||
return $this->collection->map(function ($shippingPolicy) {
|
||||
$countrySetting = $shippingPolicy->countrySettings->first();
|
||||
$method = $countrySetting?->shipping_method;
|
||||
|
||||
if ($method === 'custom') {
|
||||
$name = $countrySetting->custom_shipping_name;
|
||||
$locale = app()->getLocale();
|
||||
$methodLabel = is_array($name) ? ($name[$locale] ?? $name['ko'] ?? $name[array_key_first($name)] ?? null) : null;
|
||||
} else {
|
||||
$methodLabel = $method
|
||||
? \Modules\Sirsoft\Ecommerce\Models\ShippingType::getCachedByCode($method)?->getLocalizedName()
|
||||
: null;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $shippingPolicy->id,
|
||||
'name' => $shippingPolicy->getLocalizedName(),
|
||||
'shipping_method' => $shippingPolicy->shipping_method->value,
|
||||
'charge_policy' => $shippingPolicy->charge_policy->value,
|
||||
'shipping_method' => $method,
|
||||
'shipping_method_label' => $methodLabel,
|
||||
'charge_policy' => $countrySetting?->charge_policy?->value,
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
+30
-2
@@ -23,8 +23,9 @@ class ShippingPolicyCountrySettingResource extends BaseApiResource
|
||||
'country_code' => $this->country_code,
|
||||
|
||||
// 배송방법
|
||||
'shipping_method' => $this->shipping_method?->value,
|
||||
'shipping_method_label' => $this->shipping_method?->label(),
|
||||
'shipping_method' => $this->shipping_method,
|
||||
'shipping_method_label' => $this->resolveShippingMethodLabel(),
|
||||
'custom_shipping_name' => $this->custom_shipping_name,
|
||||
|
||||
// 통화
|
||||
'currency_code' => $this->currency_code,
|
||||
@@ -52,4 +53,31 @@ class ShippingPolicyCountrySettingResource extends BaseApiResource
|
||||
'is_active' => $this->is_active,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송방법 라벨을 해석합니다.
|
||||
*
|
||||
* custom인 경우 custom_shipping_name에서 현재 로케일 값을 반환합니다.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function resolveShippingMethodLabel(): ?string
|
||||
{
|
||||
if (! $this->shipping_method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->shipping_method === 'custom') {
|
||||
$name = $this->custom_shipping_name;
|
||||
if (is_array($name)) {
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return $name[$locale] ?? $name['ko'] ?? $name[array_key_first($name)] ?? null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Modules\Sirsoft\Ecommerce\Models\ShippingType::getCachedByCode($this->shipping_method)?->getLocalizedName();
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
|
||||
/**
|
||||
* 사용자 배송지 컬렉션 리소스
|
||||
*/
|
||||
class UserAddressCollection extends ResourceCollection
|
||||
class UserAddressCollection extends BaseApiCollection
|
||||
{
|
||||
/**
|
||||
* The resource that this resource collects.
|
||||
@@ -26,6 +26,8 @@ class UserAddressCollection extends ResourceCollection
|
||||
{
|
||||
return [
|
||||
'data' => $this->collection->toArray(),
|
||||
// user-addresses 권한 식별자가 모듈 매니페스트에 없으므로
|
||||
// abilityMap() 대신 인증 기반 하드코딩 (인증된 사용자는 항상 생성 가능)
|
||||
'abilities' => [
|
||||
'can_create' => true,
|
||||
],
|
||||
|
||||
@@ -10,6 +10,24 @@ use Illuminate\Http\Request;
|
||||
*/
|
||||
class UserAddressResource extends BaseApiResource
|
||||
{
|
||||
/**
|
||||
* 비즈니스 로직 기반 abilities를 반환합니다.
|
||||
* user-addresses 권한 식별자가 모듈 매니페스트에 없으므로, abilityMap()은 빈 배열.
|
||||
* 인증된 사용자는 자신의 주소를 수정 가능하며, 기본 배송지는 삭제/변경 불가.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
protected function resolveAbilities(Request $request): array
|
||||
{
|
||||
$abilities = parent::resolveAbilities($request);
|
||||
$abilities['can_update'] = true;
|
||||
$abilities['can_delete'] = ! $this->is_default;
|
||||
$abilities['can_set_default'] = ! $this->is_default;
|
||||
|
||||
return $abilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 리소스를 배열로 변환
|
||||
*
|
||||
@@ -44,16 +62,8 @@ class UserAddressResource extends BaseApiResource
|
||||
'is_international' => $this->isInternational(),
|
||||
'full_address' => $this->getFullAddress(),
|
||||
|
||||
// 타임스탬프
|
||||
'created_at' => $this->created_at?->toIso8601String(),
|
||||
'updated_at' => $this->updated_at?->toIso8601String(),
|
||||
|
||||
// 권한 메타
|
||||
'abilities' => [
|
||||
'can_update' => true,
|
||||
'can_delete' => ! $this->is_default,
|
||||
'can_set_default' => ! $this->is_default,
|
||||
],
|
||||
...$this->formatTimestamps(),
|
||||
...$this->resourceMeta($request),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use App\Helpers\PermissionHelper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
@@ -12,7 +12,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
*
|
||||
* 마이페이지 주문내역 목록을 페이지네이션 및 통계와 함께 반환합니다.
|
||||
*/
|
||||
class UserOrderCollection extends ResourceCollection
|
||||
class UserOrderCollection extends BaseApiCollection
|
||||
{
|
||||
/**
|
||||
* 주문 컬렉션을 배열로 변환합니다.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
@@ -12,7 +12,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
* 위시리스트 목록을 페이지네이션과 함께 반환합니다.
|
||||
* Public API이므로 abilities는 포함하지 않습니다.
|
||||
*/
|
||||
class WishlistCollection extends ResourceCollection
|
||||
class WishlistCollection extends BaseApiCollection
|
||||
{
|
||||
/**
|
||||
* 위시리스트 컬렉션을 배열로 변환합니다.
|
||||
|
||||
+343
@@ -0,0 +1,343 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Listeners;
|
||||
|
||||
use App\Contracts\Extension\HookListenerInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Models\Order;
|
||||
use Modules\Sirsoft\Ecommerce\Models\OrderCancel;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ProductInquiry;
|
||||
|
||||
/**
|
||||
* 이커머스 알림 데이터 필터 리스너
|
||||
*
|
||||
* notification_definitions의 extract_data 필터를 처리하여
|
||||
* 알림 발송에 필요한 데이터와 컨텍스트를 제공합니다.
|
||||
* 수신자 결정은 notification_definitions.recipients 설정에 위임합니다.
|
||||
*/
|
||||
class EcommerceNotificationDataListener implements HookListenerInterface
|
||||
{
|
||||
/**
|
||||
* 구독할 훅 목록을 반환합니다.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSubscribedHooks(): array
|
||||
{
|
||||
return [
|
||||
'sirsoft-ecommerce.notification.extract_data' => [
|
||||
'method' => 'extractData',
|
||||
'priority' => 20,
|
||||
'type' => 'filter',
|
||||
],
|
||||
'core.notification.filter_default_definitions' => [
|
||||
'method' => 'contributeDefaultDefinitions',
|
||||
'priority' => 20,
|
||||
'type' => 'filter',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 훅 이벤트를 처리합니다.
|
||||
*
|
||||
* @param mixed ...$args 훅에서 전달된 인수들
|
||||
* @return void
|
||||
*/
|
||||
public function handle(...$args): void {}
|
||||
|
||||
/**
|
||||
* 이커머스 모듈의 기본 알림 정의를 코어 리셋 로직에 제공합니다.
|
||||
*
|
||||
* @param array $definitions 현재까지 수집된 기본 정의 목록
|
||||
* @param array $context type/channel 필터 컨텍스트
|
||||
* @return array 이커머스 시더 정의를 병합한 목록
|
||||
*/
|
||||
public function contributeDefaultDefinitions(array $definitions, array $context = []): array
|
||||
{
|
||||
$seeder = new \Modules\Sirsoft\Ecommerce\Database\Seeders\EcommerceNotificationDefinitionSeeder();
|
||||
|
||||
return array_merge($definitions, $seeder->getDefaultDefinitions());
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림 유형에 따라 데이터와 컨텍스트를 추출합니다.
|
||||
*
|
||||
* @param array $default 기본 extract_data 구조
|
||||
* @param string $type 알림 정의 유형
|
||||
* @param array $args 훅에서 전달된 원본 인수
|
||||
* @return array{notifiable: null, notifiables: null, data: array, context: array}
|
||||
*/
|
||||
public function extractData(array $default, string $type, array $args): array
|
||||
{
|
||||
return match ($type) {
|
||||
'order_confirmed' => $this->extractOrderConfirmed($args),
|
||||
'order_shipped' => $this->extractOrderShipped($args),
|
||||
'order_completed' => $this->extractOrderCompleted($args),
|
||||
'order_cancelled' => $this->extractOrderCancelled($args),
|
||||
'new_order_admin' => $this->extractNewOrderAdmin($args),
|
||||
'inquiry_received' => $this->extractInquiryReceived($args),
|
||||
'inquiry_replied' => $this->extractInquiryReplied($args),
|
||||
default => $default,
|
||||
};
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────
|
||||
// 주문자 알림 (4종)
|
||||
// ──────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 주문 확인(결제 완료) 알림 데이터를 추출합니다.
|
||||
*
|
||||
* @param array $args 훅 인수 [$order]
|
||||
* @return array
|
||||
*/
|
||||
private function extractOrderConfirmed(array $args): array
|
||||
{
|
||||
$order = $args[0] ?? null;
|
||||
if (! $order instanceof Order) {
|
||||
return $this->emptyResult();
|
||||
}
|
||||
|
||||
return [
|
||||
'notifiable' => null,
|
||||
'notifiables' => null,
|
||||
'data' => $this->buildOrderData($order),
|
||||
'context' => $this->buildOrderContext($order),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송 시작 알림 데이터를 추출합니다.
|
||||
*
|
||||
* @param array $args 훅 인수 [$order]
|
||||
* @return array
|
||||
*/
|
||||
private function extractOrderShipped(array $args): array
|
||||
{
|
||||
$order = $args[0] ?? null;
|
||||
if (! $order instanceof Order) {
|
||||
return $this->emptyResult();
|
||||
}
|
||||
|
||||
$shipping = $order->shippings()->latest()->first();
|
||||
|
||||
return [
|
||||
'notifiable' => null,
|
||||
'notifiables' => null,
|
||||
'data' => $this->buildOrderData($order, [
|
||||
'carrier_name' => $shipping?->carrier?->getLocalizedName() ?? '',
|
||||
'tracking_number' => $shipping?->tracking_number ?? '',
|
||||
]),
|
||||
'context' => $this->buildOrderContext($order),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 구매 확정 알림 데이터를 추출합니다.
|
||||
*
|
||||
* @param array $args 훅 인수 [$order]
|
||||
* @return array
|
||||
*/
|
||||
private function extractOrderCompleted(array $args): array
|
||||
{
|
||||
$order = $args[0] ?? null;
|
||||
if (! $order instanceof Order) {
|
||||
return $this->emptyResult();
|
||||
}
|
||||
|
||||
return [
|
||||
'notifiable' => null,
|
||||
'notifiables' => null,
|
||||
'data' => $this->buildOrderData($order),
|
||||
'context' => $this->buildOrderContext($order),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 주문 취소 알림 데이터를 추출합니다.
|
||||
*
|
||||
* @param array $args 훅 인수 [$order, $cancelSnapshot?]
|
||||
* @return array
|
||||
*/
|
||||
private function extractOrderCancelled(array $args): array
|
||||
{
|
||||
$order = $args[0] ?? null;
|
||||
if (! $order instanceof Order) {
|
||||
return $this->emptyResult();
|
||||
}
|
||||
|
||||
$latestCancel = OrderCancel::where('order_id', $order->id)->latest('id')->first();
|
||||
$cancelReason = $latestCancel?->cancel_reason ?? '';
|
||||
|
||||
return [
|
||||
'notifiable' => null,
|
||||
'notifiables' => null,
|
||||
'data' => $this->buildOrderData($order, [
|
||||
'cancel_reason' => $cancelReason,
|
||||
]),
|
||||
'context' => $this->buildOrderContext($order),
|
||||
];
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────
|
||||
// 관리자 알림 (2종)
|
||||
// ──────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 신규 주문 관리자 알림 데이터를 추출합니다.
|
||||
*
|
||||
* @param array $args 훅 인수 [$order]
|
||||
* @return array
|
||||
*/
|
||||
private function extractNewOrderAdmin(array $args): array
|
||||
{
|
||||
$order = $args[0] ?? null;
|
||||
if (! $order instanceof Order) {
|
||||
return $this->emptyResult();
|
||||
}
|
||||
|
||||
$baseUrl = config('app.url');
|
||||
|
||||
return [
|
||||
'notifiable' => null,
|
||||
'notifiables' => null,
|
||||
'data' => [
|
||||
'name' => '{recipient_name}',
|
||||
'app_name' => config('app.name'),
|
||||
'order_number' => $order->order_number,
|
||||
'customer_name' => $order->user?->name ?? '',
|
||||
'total_amount' => number_format($order->total_paid_amount ?? $order->total_amount) . '원',
|
||||
'order_url' => "{$baseUrl}/admin/ecommerce/orders/{$order->order_number}",
|
||||
'site_url' => $baseUrl,
|
||||
],
|
||||
'context' => [
|
||||
'trigger_user_id' => $order->user_id,
|
||||
'trigger_user' => $order->user,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 상품 문의 접수 관리자 알림 데이터를 추출합니다.
|
||||
*
|
||||
* @param array $args 훅 인수 [$inquiry]
|
||||
* @return array
|
||||
*/
|
||||
private function extractInquiryReceived(array $args): array
|
||||
{
|
||||
$inquiry = $args[0] ?? null;
|
||||
if (! $inquiry instanceof ProductInquiry) {
|
||||
return $this->emptyResult();
|
||||
}
|
||||
|
||||
$baseUrl = config('app.url');
|
||||
$product = $inquiry->product;
|
||||
|
||||
return [
|
||||
'notifiable' => null,
|
||||
'notifiables' => null,
|
||||
'data' => [
|
||||
'name' => '{recipient_name}',
|
||||
'app_name' => config('app.name'),
|
||||
'product_name' => $product?->getLocalizedName() ?? ($inquiry->product_name_snapshot[app()->getLocale()] ?? ''),
|
||||
'customer_name' => $inquiry->user?->name ?? '',
|
||||
'inquiry_content' => mb_substr($inquiry->inquirable?->content ?? '', 0, 200),
|
||||
'inquiry_url' => "{$baseUrl}/admin/ecommerce/product-inquiries",
|
||||
'site_url' => $baseUrl,
|
||||
],
|
||||
'context' => [
|
||||
'trigger_user_id' => $inquiry->user_id,
|
||||
'trigger_user' => $inquiry->user,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────
|
||||
// 사용자 알림 (1종)
|
||||
// ──────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 문의 답변 완료 알림 데이터를 추출합니다.
|
||||
*
|
||||
* @param array $args 훅 인수 [$inquiry]
|
||||
* @return array
|
||||
*/
|
||||
private function extractInquiryReplied(array $args): array
|
||||
{
|
||||
$inquiry = $args[0] ?? null;
|
||||
if (! $inquiry instanceof ProductInquiry) {
|
||||
return $this->emptyResult();
|
||||
}
|
||||
|
||||
$baseUrl = config('app.url');
|
||||
|
||||
return [
|
||||
'notifiable' => null,
|
||||
'notifiables' => null,
|
||||
'data' => [
|
||||
'name' => $inquiry->user?->name ?? '',
|
||||
'app_name' => config('app.name'),
|
||||
'product_name' => $inquiry->product?->getLocalizedName() ?? ($inquiry->product_name_snapshot[app()->getLocale()] ?? ''),
|
||||
'inquiry_content' => mb_substr($inquiry->inquirable?->content ?? '', 0, 200),
|
||||
'inquiry_url' => "{$baseUrl}/mypage/inquiries",
|
||||
'site_url' => $baseUrl,
|
||||
],
|
||||
'context' => [
|
||||
'trigger_user_id' => $inquiry->user_id,
|
||||
'trigger_user' => $inquiry->user,
|
||||
'related_users' => [
|
||||
'author' => $inquiry->user,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────
|
||||
// 헬퍼 메서드
|
||||
// ──────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 주문 알림 데이터 배열을 구성합니다.
|
||||
*
|
||||
* @param Order $order 주문 모델
|
||||
* @param array $extra 추가 변수
|
||||
* @return array
|
||||
*/
|
||||
private function buildOrderData(Order $order, array $extra = []): array
|
||||
{
|
||||
$baseUrl = config('app.url');
|
||||
|
||||
return array_merge([
|
||||
'name' => $order->user?->name ?? '',
|
||||
'app_name' => config('app.name'),
|
||||
'order_number' => $order->order_number,
|
||||
'total_amount' => number_format($order->total_paid_amount ?? $order->total_amount) . '원',
|
||||
'order_url' => "{$baseUrl}/mypage/orders/{$order->order_number}",
|
||||
'site_url' => $baseUrl,
|
||||
], $extra);
|
||||
}
|
||||
|
||||
/**
|
||||
* 주문 컨텍스트를 구성합니다.
|
||||
*
|
||||
* @param Order $order 주문 모델
|
||||
* @return array
|
||||
*/
|
||||
private function buildOrderContext(Order $order): array
|
||||
{
|
||||
return [
|
||||
'trigger_user_id' => $order->user_id,
|
||||
'trigger_user' => $order->user,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 빈 결과를 반환합니다.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function emptyResult(): array
|
||||
{
|
||||
return ['notifiable' => null, 'notifiables' => null, 'data' => [], 'context' => []];
|
||||
}
|
||||
}
|
||||
@@ -80,8 +80,12 @@ class ProductInquiryBoardListener implements HookListenerInterface
|
||||
* @param array $options 삭제 옵션
|
||||
* @return void
|
||||
*/
|
||||
public function handlePostDeleted(object $post, string $slug, array $options = []): void
|
||||
public function handlePostDeleted(?object $post, string $slug, array $options = []): void
|
||||
{
|
||||
if ($post === null) {
|
||||
return; // 큐 워커 시점에 모델이 이미 사라진 경우 스킵
|
||||
}
|
||||
|
||||
try {
|
||||
$this->repository->deleteByInquirableIds(
|
||||
get_class($post),
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Listeners;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Extension\HookListenerInterface;
|
||||
use App\Seo\Contracts\SeoCacheManagerInterface;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
@@ -75,7 +75,7 @@ class SeoCategoryCacheListener implements HookListenerInterface
|
||||
$cache->invalidateByLayout('search/index');
|
||||
|
||||
// Sitemap 캐시 무효화
|
||||
Cache::forget('seo:sitemap');
|
||||
app(CacheInterface::class)->forget('seo.sitemap');
|
||||
|
||||
$categoryId = is_object($category) ? ($category->id ?? null) : $category;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Listeners;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Extension\HookListenerInterface;
|
||||
use App\Seo\Contracts\SeoCacheManagerInterface;
|
||||
use App\Seo\SeoCacheRegenerator;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ class SeoProductCacheListener implements HookListenerInterface
|
||||
$cache->invalidateByLayout('search/index');
|
||||
|
||||
// Sitemap 캐시 무효화
|
||||
Cache::forget('seo:sitemap');
|
||||
app(CacheInterface::class)->forget('seo.sitemap');
|
||||
|
||||
Log::debug('[SEO] Product cache invalidated', [
|
||||
'product_id' => $product->id,
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Listeners;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Extension\HookListenerInterface;
|
||||
use App\Seo\Contracts\SeoCacheManagerInterface;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ class SeoSettingsCacheListener implements HookListenerInterface
|
||||
|
||||
// SEO 관련 변경이 있었으면 sitemap 캐시 삭제
|
||||
if (! empty($invalidatedLayouts) || $sitemapAffected) {
|
||||
Cache::forget('seo:sitemap');
|
||||
app(CacheInterface::class)->forget('seo.sitemap');
|
||||
}
|
||||
|
||||
if (! empty($invalidatedLayouts)) {
|
||||
|
||||
@@ -2,18 +2,30 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Models;
|
||||
|
||||
use App\Models\Concerns\HasUserOverrides;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ClaimReasonFaultTypeEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ClaimReasonTypeEnum;
|
||||
|
||||
/**
|
||||
* 클래임 사유 모델
|
||||
* 클래임 사유 모델.
|
||||
*
|
||||
* 환불/교환/반품 등 클래임 사유 템플릿을 관리합니다.
|
||||
*
|
||||
* @since 7.0.0-beta.2 (HasUserOverrides 적용)
|
||||
*/
|
||||
class ClaimReason extends Model
|
||||
{
|
||||
use HasUserOverrides;
|
||||
|
||||
/**
|
||||
* 사용자 수정 보존 대상 필드.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected array $trackableFields = ['name', 'sort_order', 'is_active'];
|
||||
|
||||
protected $table = 'ecommerce_claim_reasons';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -26,6 +38,7 @@ class ClaimReason extends Model
|
||||
'sort_order',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'user_overrides',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -37,6 +50,7 @@ class ClaimReason extends Model
|
||||
'sort_order' => 'integer',
|
||||
'created_by' => 'integer',
|
||||
'updated_by' => 'integer',
|
||||
'user_overrides' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Models;
|
||||
|
||||
use App\Models\Concerns\MailTemplateBehavior;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 이커머스 메일 템플릿 모델
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $type
|
||||
* @property array $subject
|
||||
* @property array $body
|
||||
* @property array $variables
|
||||
* @property bool $is_active
|
||||
* @property bool $is_default
|
||||
* @property int|null $updated_by
|
||||
*/
|
||||
class EcommerceMailTemplate extends Model
|
||||
{
|
||||
use MailTemplateBehavior;
|
||||
|
||||
/**
|
||||
* @var string 테이블명
|
||||
*/
|
||||
protected $table = 'ecommerce_mail_templates';
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> 기본 속성 값
|
||||
*/
|
||||
protected $attributes = [
|
||||
'variables' => '[]',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<int, string> 대량 할당 가능 필드
|
||||
*/
|
||||
protected $fillable = [
|
||||
'type',
|
||||
'subject',
|
||||
'body',
|
||||
'variables',
|
||||
'is_active',
|
||||
'is_default',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
/**
|
||||
* 마지막 수정자 관계를 반환합니다.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function updater(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by');
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Modules\Sirsoft\Ecommerce\Database\Factories\OrderShippingFactory;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingTypeEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ShippingType;
|
||||
|
||||
/**
|
||||
* 주문 배송 모델
|
||||
@@ -74,7 +74,6 @@ class OrderShipping extends Model
|
||||
'delivered_at' => 'datetime',
|
||||
'confirmed_at' => 'datetime',
|
||||
'shipping_status' => ShippingStatusEnum::class,
|
||||
'shipping_type' => ShippingTypeEnum::class,
|
||||
// 다중 통화 컬럼 (JSON)
|
||||
'mc_base_shipping_amount' => 'array',
|
||||
'mc_extra_shipping_amount' => 'array',
|
||||
@@ -180,11 +179,9 @@ class OrderShipping extends Model
|
||||
*/
|
||||
public function isDomestic(): bool
|
||||
{
|
||||
return in_array($this->shipping_type, [
|
||||
ShippingTypeEnum::DOMESTIC_PARCEL,
|
||||
ShippingTypeEnum::DOMESTIC_EXPRESS,
|
||||
ShippingTypeEnum::DOMESTIC_QUICK,
|
||||
]);
|
||||
$type = ShippingType::getCachedByCode($this->shipping_type);
|
||||
|
||||
return $type?->category === 'domestic';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,10 +191,9 @@ class OrderShipping extends Model
|
||||
*/
|
||||
public function isInternational(): bool
|
||||
{
|
||||
return in_array($this->shipping_type, [
|
||||
ShippingTypeEnum::INTERNATIONAL_EMS,
|
||||
ShippingTypeEnum::INTERNATIONAL_STANDARD,
|
||||
]);
|
||||
$type = ShippingType::getCachedByCode($this->shipping_type);
|
||||
|
||||
return $type?->category === 'international';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +203,7 @@ class OrderShipping extends Model
|
||||
*/
|
||||
public function isPickup(): bool
|
||||
{
|
||||
return $this->shipping_type === ShippingTypeEnum::PICKUP;
|
||||
return $this->shipping_type === 'pickup';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Models;
|
||||
|
||||
use App\Models\Concerns\HasUserOverrides;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
@@ -9,9 +10,15 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
* 배송사 모델
|
||||
*
|
||||
* 배송사 마스터 데이터를 관리합니다.
|
||||
*
|
||||
* ShippingCarrierSeeder 는 GenericEntitySyncHelper 기반으로 동작하므로,
|
||||
* 사용자가 관리자 UI 에서 수정한 필드는 `user_overrides` 에 기록되어
|
||||
* 재설치/재시드 시 보존됩니다.
|
||||
*/
|
||||
class ShippingCarrier extends Model
|
||||
{
|
||||
use HasUserOverrides;
|
||||
|
||||
/** @var array<string, array> 활동 로그 추적 필드 */
|
||||
public static array $activityLogFields = [
|
||||
'code' => ['label_key' => 'sirsoft-ecommerce::activity_log.fields.code', 'type' => 'text'],
|
||||
@@ -21,6 +28,15 @@ class ShippingCarrier extends Model
|
||||
'sort_order' => ['label_key' => 'sirsoft-ecommerce::activity_log.fields.sort_order', 'type' => 'number'],
|
||||
];
|
||||
|
||||
/** @var list<string> 사용자 수정 추적 필드 (시더 재실행 시 보존 대상) */
|
||||
protected array $trackableFields = [
|
||||
'name',
|
||||
'type',
|
||||
'tracking_url',
|
||||
'is_active',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
protected $table = 'ecommerce_shipping_carriers';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -30,6 +46,7 @@ class ShippingCarrier extends Model
|
||||
'tracking_url',
|
||||
'is_active',
|
||||
'sort_order',
|
||||
'user_overrides',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
@@ -38,6 +55,7 @@ class ShippingCarrier extends Model
|
||||
'name' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
'user_overrides' => 'array',
|
||||
'created_by' => 'integer',
|
||||
'updated_by' => 'integer',
|
||||
];
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Modules\Sirsoft\Ecommerce\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ChargePolicyEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingMethodEnum;
|
||||
|
||||
/**
|
||||
* 배송정책 국가별 설정 모델
|
||||
@@ -20,6 +19,7 @@ class ShippingPolicyCountrySetting extends Model
|
||||
'shipping_policy_id',
|
||||
'country_code',
|
||||
'shipping_method',
|
||||
'custom_shipping_name',
|
||||
'currency_code',
|
||||
'charge_policy',
|
||||
'base_fee',
|
||||
@@ -43,7 +43,7 @@ class ShippingPolicyCountrySetting extends Model
|
||||
'extra_fee_enabled' => 'boolean',
|
||||
'extra_fee_multiply' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'shipping_method' => ShippingMethodEnum::class,
|
||||
'custom_shipping_name' => 'array',
|
||||
'charge_policy' => ChargePolicyEnum::class,
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Models;
|
||||
|
||||
use App\Models\Concerns\HasUserOverrides;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 배송유형 모델
|
||||
*
|
||||
* 배송유형 마스터 데이터를 관리합니다.
|
||||
*
|
||||
* @since 7.0.0-beta.2 (HasUserOverrides 적용)
|
||||
*/
|
||||
class ShippingType extends Model
|
||||
{
|
||||
use HasUserOverrides;
|
||||
|
||||
/** @var array<string, array> 활동 로그 추적 필드 */
|
||||
public static array $activityLogFields = [
|
||||
'code' => ['label_key' => 'sirsoft-ecommerce::activity_log.fields.code', 'type' => 'text'],
|
||||
'category' => ['label_key' => 'sirsoft-ecommerce::activity_log.fields.category', 'type' => 'text'],
|
||||
'is_active' => ['label_key' => 'sirsoft-ecommerce::activity_log.fields.is_active', 'type' => 'boolean'],
|
||||
'sort_order' => ['label_key' => 'sirsoft-ecommerce::activity_log.fields.sort_order', 'type' => 'number'],
|
||||
];
|
||||
|
||||
/**
|
||||
* 사용자 수정 보존 대상 필드.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected array $trackableFields = ['name', 'category', 'is_active', 'sort_order'];
|
||||
|
||||
protected $table = 'ecommerce_shipping_types';
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'category',
|
||||
'is_active',
|
||||
'sort_order',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'user_overrides',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'name' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
'created_by' => 'integer',
|
||||
'updated_by' => 'integer',
|
||||
'user_overrides' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* 요청 단위 캐시 (코드 → 모델)
|
||||
*
|
||||
* @var \Illuminate\Database\Eloquent\Collection|null
|
||||
*/
|
||||
protected static $codeCache = null;
|
||||
|
||||
/**
|
||||
* 생성자 관계
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class, 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* 수정자 관계
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function updater(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class, 'updated_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 로케일의 배송유형명 반환
|
||||
*
|
||||
* @param string|null $locale 로케일 (기본값: 현재 앱 로케일)
|
||||
* @return string
|
||||
*/
|
||||
public function getLocalizedName(?string $locale = null): string
|
||||
{
|
||||
$locale = $locale ?? app()->getLocale();
|
||||
$name = $this->name;
|
||||
|
||||
if (! is_array($name)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $name[$locale] ?? $name['ko'] ?? $name['en'] ?? $name[array_key_first($name)] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 국내 배송유형 여부
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDomestic(): bool
|
||||
{
|
||||
return $this->category === 'domestic';
|
||||
}
|
||||
|
||||
/**
|
||||
* 해외 배송유형 여부
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isInternational(): bool
|
||||
{
|
||||
return $this->category === 'international';
|
||||
}
|
||||
|
||||
/**
|
||||
* 코드로 캐시된 ShippingType 조회
|
||||
*
|
||||
* shipping_types는 드물게 변경되므로 요청 단위 캐시 적용
|
||||
*
|
||||
* @param string $code 배송유형 코드
|
||||
* @return self|null
|
||||
*/
|
||||
public static function getCachedByCode(string $code): ?self
|
||||
{
|
||||
if (static::$codeCache === null) {
|
||||
static::$codeCache = self::all()->keyBy('code');
|
||||
}
|
||||
|
||||
return static::$codeCache[$code] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 캐시를 초기화합니다.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clearCodeCache(): void
|
||||
{
|
||||
static::$codeCache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성 배송유형만 조회 스코프
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 정렬 순서대로 조회 스코프
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeOrdered($query)
|
||||
{
|
||||
return $query->orderBy('sort_order')->orderBy('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 카테고리별 조회 스코프
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $category 카테고리 (domestic, international, other)
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeOfCategory($query, string $category)
|
||||
{
|
||||
return $query->where('category', $category);
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,12 @@ use Modules\Sirsoft\Ecommerce\Repositories\Contracts\CategoryImageRepositoryInte
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\CategoryRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\CouponIssueRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\CouponRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\EcommerceMailTemplateRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ExtraFeeTemplateRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderOptionRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderShippingRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\CouponIssueRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\CouponRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\EcommerceMailTemplateRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\ExtraFeeTemplateRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\ProductInquiryRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\ProductLogRepository;
|
||||
@@ -39,6 +37,7 @@ use Modules\Sirsoft\Ecommerce\Repositories\Contracts\SearchPresetRepositoryInter
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\SequenceRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ShippingCarrierRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ShippingPolicyRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ShippingTypeRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ProductWishlistRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\TempOrderRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\UserAddressRepositoryInterface;
|
||||
@@ -48,6 +47,7 @@ use Modules\Sirsoft\Ecommerce\Repositories\OrderRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\OrderShippingRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\ShippingCarrierRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\ShippingPolicyRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\ShippingTypeRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\TempOrderRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\UserAddressRepository;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\ProductImageRepository;
|
||||
@@ -104,7 +104,6 @@ class EcommerceServiceProvider extends BaseModuleServiceProvider
|
||||
CategoryImageRepositoryInterface::class => CategoryImageRepository::class,
|
||||
CouponIssueRepositoryInterface::class => CouponIssueRepository::class,
|
||||
CouponRepositoryInterface::class => CouponRepository::class,
|
||||
EcommerceMailTemplateRepositoryInterface::class => EcommerceMailTemplateRepository::class,
|
||||
ExtraFeeTemplateRepositoryInterface::class => ExtraFeeTemplateRepository::class,
|
||||
OrderOptionRepositoryInterface::class => OrderOptionRepository::class,
|
||||
OrderRepositoryInterface::class => OrderRepository::class,
|
||||
@@ -123,6 +122,7 @@ class EcommerceServiceProvider extends BaseModuleServiceProvider
|
||||
SequenceRepositoryInterface::class => SequenceRepository::class,
|
||||
ShippingCarrierRepositoryInterface::class => ShippingCarrierRepository::class,
|
||||
ShippingPolicyRepositoryInterface::class => ShippingPolicyRepository::class,
|
||||
ShippingTypeRepositoryInterface::class => ShippingTypeRepository::class,
|
||||
TempOrderRepositoryInterface::class => TempOrderRepository::class,
|
||||
ProductWishlistRepositoryInterface::class => ProductWishlistRepository::class,
|
||||
UserAddressRepositoryInterface::class => UserAddressRepository::class,
|
||||
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Sirsoft\Ecommerce\Models\EcommerceMailTemplate;
|
||||
|
||||
/**
|
||||
* 이커머스 메일 템플릿 리포지토리 인터페이스
|
||||
*/
|
||||
interface EcommerceMailTemplateRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* ID로 메일 템플릿을 조회합니다.
|
||||
*
|
||||
* @param int $id 템플릿 ID
|
||||
* @return EcommerceMailTemplate|null
|
||||
*/
|
||||
public function findById(int $id): ?EcommerceMailTemplate;
|
||||
|
||||
/**
|
||||
* 유형으로 메일 템플릿을 조회합니다.
|
||||
*
|
||||
* @param string $type 템플릿 유형
|
||||
* @return EcommerceMailTemplate|null
|
||||
*/
|
||||
public function findByType(string $type): ?EcommerceMailTemplate;
|
||||
|
||||
/**
|
||||
* 활성 상태인 특정 유형의 템플릿을 조회합니다.
|
||||
*
|
||||
* @param string $type 템플릿 유형
|
||||
* @return EcommerceMailTemplate|null
|
||||
*/
|
||||
public function getActiveByType(string $type): ?EcommerceMailTemplate;
|
||||
|
||||
/**
|
||||
* 전체 템플릿 목록을 조회합니다.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllTemplates(): Collection;
|
||||
|
||||
/**
|
||||
* 메일 템플릿을 수정합니다.
|
||||
*
|
||||
* @param EcommerceMailTemplate $template 수정 대상
|
||||
* @param array $data 수정 데이터
|
||||
* @return bool
|
||||
*/
|
||||
public function update(EcommerceMailTemplate $template, array $data): bool;
|
||||
|
||||
/**
|
||||
* 메일 템플릿 목록을 페이지네이션하여 조회합니다.
|
||||
*
|
||||
* @param array $filters 필터 조건
|
||||
* @param int $perPage 페이지 당 항목 수
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getPaginated(array $filters = [], int $perPage = 20): LengthAwarePaginator;
|
||||
}
|
||||
+8
@@ -53,4 +53,12 @@ interface OrderShippingRepositoryInterface
|
||||
* @return int 업데이트된 레코드 수
|
||||
*/
|
||||
public function transferByOrderOptionId(int $fromOrderOptionId, int $toOrderOptionId): int;
|
||||
|
||||
/**
|
||||
* 배송유형 코드로 사용 중인 배송 레코드 수를 조회합니다.
|
||||
*
|
||||
* @param string $shippingType 배송유형 코드
|
||||
* @return int 사용 중인 레코드 수
|
||||
*/
|
||||
public function countByShippingType(string $shippingType): int;
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ShippingType;
|
||||
|
||||
/**
|
||||
* 배송유형 Repository 인터페이스
|
||||
*/
|
||||
interface ShippingTypeRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* 배송유형 목록 조회
|
||||
*
|
||||
* @param array $filters 필터 조건
|
||||
* @param array $with Eager loading 관계
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAll(array $filters = [], array $with = []): Collection;
|
||||
|
||||
/**
|
||||
* ID로 배송유형 조회
|
||||
*
|
||||
* @param int $id 배송유형 ID
|
||||
* @param array $with Eager loading 관계
|
||||
* @return ShippingType|null
|
||||
*/
|
||||
public function findById(int $id, array $with = []): ?ShippingType;
|
||||
|
||||
/**
|
||||
* 배송유형 생성
|
||||
*
|
||||
* @param array $data 배송유형 데이터
|
||||
* @return ShippingType
|
||||
*/
|
||||
public function create(array $data): ShippingType;
|
||||
|
||||
/**
|
||||
* 배송유형 수정
|
||||
*
|
||||
* @param int $id 배송유형 ID
|
||||
* @param array $data 수정 데이터
|
||||
* @return ShippingType
|
||||
*/
|
||||
public function update(int $id, array $data): ShippingType;
|
||||
|
||||
/**
|
||||
* 배송유형 삭제
|
||||
*
|
||||
* @param int $id 배송유형 ID
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(int $id): bool;
|
||||
|
||||
/**
|
||||
* 코드 중복 확인
|
||||
*
|
||||
* @param string $code 배송유형 코드
|
||||
* @param int|null $excludeId 제외할 배송유형 ID
|
||||
* @return bool
|
||||
*/
|
||||
public function existsByCode(string $code, ?int $excludeId = null): bool;
|
||||
|
||||
/**
|
||||
* 활성 배송유형 목록 조회
|
||||
*
|
||||
* @param string|null $category 카테고리 필터 (domestic, international, other, null=전체)
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveTypes(?string $category = null): Collection;
|
||||
}
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Repositories;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Sirsoft\Ecommerce\Models\EcommerceMailTemplate;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\EcommerceMailTemplateRepositoryInterface;
|
||||
|
||||
/**
|
||||
* 이커머스 메일 템플릿 리포지토리 구현체
|
||||
*/
|
||||
class EcommerceMailTemplateRepository implements EcommerceMailTemplateRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findById(int $id): ?EcommerceMailTemplate
|
||||
{
|
||||
return EcommerceMailTemplate::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findByType(string $type): ?EcommerceMailTemplate
|
||||
{
|
||||
return EcommerceMailTemplate::where('type', $type)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getActiveByType(string $type): ?EcommerceMailTemplate
|
||||
{
|
||||
return EcommerceMailTemplate::active()->byType($type)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllTemplates(): Collection
|
||||
{
|
||||
return EcommerceMailTemplate::orderBy('id')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update(EcommerceMailTemplate $template, array $data): bool
|
||||
{
|
||||
return $template->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPaginated(array $filters = [], int $perPage = 20): LengthAwarePaginator
|
||||
{
|
||||
$sortBy = $filters['sort_by'] ?? 'id';
|
||||
$sortOrder = $filters['sort_order'] ?? 'asc';
|
||||
$query = EcommerceMailTemplate::query()->orderBy($sortBy, $sortOrder);
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$searchType = $filters['search_type'] ?? 'all';
|
||||
$query->where(function ($q) use ($search, $searchType) {
|
||||
$locales = config('app.supported_locales', ['ko', 'en']);
|
||||
|
||||
if ($searchType === 'subject' || $searchType === 'all') {
|
||||
foreach ($locales as $locale) {
|
||||
$q->orWhere("subject->{$locale}", 'like', "%{$search}%");
|
||||
}
|
||||
}
|
||||
|
||||
if ($searchType === 'body' || $searchType === 'all') {
|
||||
foreach ($locales as $locale) {
|
||||
$q->orWhere("body->{$locale}", 'like', "%{$search}%");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\OrderStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingTypeEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Models\Order;
|
||||
use Modules\Sirsoft\Ecommerce\Models\OrderOption;
|
||||
use Modules\Sirsoft\Ecommerce\Models\OrderShipping;
|
||||
@@ -335,7 +334,7 @@ class OrderRepository implements OrderRepositoryInterface
|
||||
'order_id' => $order->id,
|
||||
'order_option_id' => $option->id,
|
||||
'shipping_status' => ShippingStatusEnum::PENDING->value,
|
||||
'shipping_type' => ShippingTypeEnum::DOMESTIC_PARCEL->value,
|
||||
'shipping_type' => 'parcel',
|
||||
], $updateData));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,4 +65,14 @@ class OrderShippingRepository implements OrderShippingRepositoryInterface
|
||||
->where('order_option_id', $fromOrderOptionId)
|
||||
->update(['order_option_id' => $toOrderOptionId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function countByShippingType(string $shippingType): int
|
||||
{
|
||||
return $this->model
|
||||
->where('shipping_type', $shippingType)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ShippingType;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ShippingTypeRepositoryInterface;
|
||||
|
||||
/**
|
||||
* 배송유형 Repository 구현체
|
||||
*/
|
||||
class ShippingTypeRepository implements ShippingTypeRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param ShippingType $model 배송유형 모델
|
||||
*/
|
||||
public function __construct(
|
||||
protected ShippingType $model
|
||||
) {}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getAll(array $filters = [], array $with = []): Collection
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
// 활성 상태 필터
|
||||
if (isset($filters['is_active'])) {
|
||||
$query->where('is_active', $filters['is_active']);
|
||||
}
|
||||
|
||||
// 카테고리 필터
|
||||
if (! empty($filters['category'])) {
|
||||
$query->where('category', $filters['category']);
|
||||
}
|
||||
|
||||
// 검색 키워드
|
||||
if (! empty($filters['search'])) {
|
||||
$keyword = $filters['search'];
|
||||
$locales = config('app.translatable_locales', ['ko', 'en']);
|
||||
$query->where(function ($q) use ($keyword, $locales) {
|
||||
foreach ($locales as $locale) {
|
||||
$q->orWhere("name->{$locale}", 'like', "%{$keyword}%");
|
||||
}
|
||||
$q->orWhere('code', 'like', "%{$keyword}%");
|
||||
});
|
||||
}
|
||||
|
||||
// 정렬
|
||||
$query->orderBy('sort_order')->orderBy('id');
|
||||
|
||||
// Eager loading
|
||||
if (! empty($with)) {
|
||||
$query->with($with);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findById(int $id, array $with = []): ?ShippingType
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
if (! empty($with)) {
|
||||
$query->with($with);
|
||||
}
|
||||
|
||||
return $query->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function create(array $data): ShippingType
|
||||
{
|
||||
return $this->model->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function update(int $id, array $data): ShippingType
|
||||
{
|
||||
$type = $this->findById($id);
|
||||
$type->update($data);
|
||||
|
||||
return $type->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete(int $id): bool
|
||||
{
|
||||
$type = $this->findById($id);
|
||||
|
||||
return $type->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function existsByCode(string $code, ?int $excludeId = null): bool
|
||||
{
|
||||
$query = $this->model->where('code', $code);
|
||||
|
||||
if ($excludeId !== null) {
|
||||
$query->where('id', '!=', $excludeId);
|
||||
}
|
||||
|
||||
return $query->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getActiveTypes(?string $category = null): Collection
|
||||
{
|
||||
$query = $this->model->newQuery()
|
||||
->active()
|
||||
->ordered();
|
||||
|
||||
if ($category !== null) {
|
||||
$query->ofCategory($category);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Services;
|
||||
|
||||
use App\Services\Concerns\HandlesMailTemplates;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Sirsoft\Ecommerce\Database\Seeders\EcommerceMailTemplateSeeder;
|
||||
use Modules\Sirsoft\Ecommerce\Models\EcommerceMailTemplate;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\EcommerceMailTemplateRepositoryInterface;
|
||||
|
||||
/**
|
||||
* 이커머스 메일 템플릿 서비스
|
||||
*/
|
||||
class EcommerceMailTemplateService
|
||||
{
|
||||
use HandlesMailTemplates;
|
||||
|
||||
/**
|
||||
* @var string 캐시 키 prefix
|
||||
*/
|
||||
protected string $cachePrefix = 'mail_template:sirsoft-ecommerce:';
|
||||
|
||||
/**
|
||||
* @var string 모델 클래스
|
||||
*/
|
||||
protected string $modelClass = EcommerceMailTemplate::class;
|
||||
|
||||
/**
|
||||
* EcommerceMailTemplateService 생성자.
|
||||
*
|
||||
* @param EcommerceMailTemplateRepositoryInterface $repository 메일 템플릿 리포지토리
|
||||
*/
|
||||
public function __construct(
|
||||
private EcommerceMailTemplateRepositoryInterface $repository
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 환경설정 탭용 전체 템플릿 목록을 반환합니다.
|
||||
*
|
||||
* @return Collection 메일 템플릿 컬렉션
|
||||
*/
|
||||
public function getTemplatesForSettings(): Collection
|
||||
{
|
||||
return $this->repository->getAllTemplates();
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿을 수정합니다.
|
||||
*
|
||||
* @param EcommerceMailTemplate $template 수정 대상
|
||||
* @param array $data 수정 데이터
|
||||
* @param int|null $userId 수정자 ID
|
||||
* @return EcommerceMailTemplate 수정된 템플릿
|
||||
*/
|
||||
public function updateTemplate(EcommerceMailTemplate $template, array $data, ?int $userId = null): EcommerceMailTemplate
|
||||
{
|
||||
$updateData = [
|
||||
'subject' => $data['subject'],
|
||||
'body' => $data['body'],
|
||||
'is_active' => $data['is_active'] ?? $template->is_active,
|
||||
'is_default' => false,
|
||||
'updated_by' => $userId,
|
||||
];
|
||||
|
||||
$this->repository->update($template, $updateData);
|
||||
$this->invalidateCache($template->type);
|
||||
|
||||
return $template->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿의 활성 상태를 토글합니다.
|
||||
*
|
||||
* @param EcommerceMailTemplate $template 토글 대상
|
||||
* @return EcommerceMailTemplate 토글된 템플릿
|
||||
*/
|
||||
public function toggleActive(EcommerceMailTemplate $template): EcommerceMailTemplate
|
||||
{
|
||||
$this->repository->update($template, [
|
||||
'is_active' => ! $template->is_active,
|
||||
]);
|
||||
|
||||
$this->invalidateCache($template->type);
|
||||
|
||||
return $template->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿 목록을 페이지네이션하여 조회합니다.
|
||||
*
|
||||
* @param array $filters 필터 조건
|
||||
* @param int $perPage 페이지 당 항목 수
|
||||
* @return LengthAwarePaginator 페이지네이션 결과
|
||||
*/
|
||||
public function getTemplates(array $filters = [], int $perPage = 20): LengthAwarePaginator
|
||||
{
|
||||
return $this->repository->getPaginated($filters, $perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 미리보기용 렌더링 결과를 반환합니다.
|
||||
*
|
||||
* @param array $data 미리보기 데이터 (subject, body, variables)
|
||||
* @return array{subject: string, body: string} 렌더링 결과
|
||||
*/
|
||||
public function getPreview(array $data): array
|
||||
{
|
||||
$subject = $data['subject'] ?? '';
|
||||
$body = $data['body'] ?? '';
|
||||
$sampleVariables = [];
|
||||
|
||||
foreach ($data['variables'] ?? [] as $variable) {
|
||||
$key = $variable['key'] ?? '';
|
||||
$sampleVariables[$key] = '{' . $key . '}';
|
||||
}
|
||||
|
||||
$replacements = [];
|
||||
foreach ($sampleVariables as $key => $value) {
|
||||
$replacements['{' . $key . '}'] = $value;
|
||||
}
|
||||
|
||||
return [
|
||||
'subject' => strtr($subject, $replacements),
|
||||
'body' => strtr($body, $replacements),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 시더에 정의된 기본 템플릿 데이터를 반환합니다.
|
||||
*
|
||||
* @param string $type 템플릿 유형
|
||||
* @return array|null 기본 데이터 또는 null
|
||||
*/
|
||||
public function getDefaultTemplateData(string $type): ?array
|
||||
{
|
||||
$seeder = app(EcommerceMailTemplateSeeder::class);
|
||||
|
||||
$defaults = $seeder->getDefaultTemplates();
|
||||
|
||||
foreach ($defaults as $default) {
|
||||
if ($default['type'] === $type) {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -843,7 +843,8 @@ class OrderCalculationService
|
||||
totalShippingAmount: $baseAmount + $extraAmount,
|
||||
policySnapshot: [
|
||||
'country_code' => $countrySetting->country_code,
|
||||
'shipping_method' => $countrySetting->shipping_method?->value,
|
||||
'shipping_method' => $countrySetting->shipping_method,
|
||||
'custom_shipping_name' => $countrySetting->custom_shipping_name,
|
||||
'currency_code' => $countrySetting->currency_code,
|
||||
'charge_policy' => $countrySetting->charge_policy->value,
|
||||
'base_fee' => (int) $countrySetting->base_fee,
|
||||
|
||||
@@ -17,7 +17,7 @@ use Modules\Sirsoft\Ecommerce\Enums\PaymentMethodEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\PaymentStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\SequenceType;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\ShippingTypeEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ShippingType;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\OrderAmountChangedException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\PaymentAmountMismatchException;
|
||||
use Modules\Sirsoft\Ecommerce\Models\Order;
|
||||
@@ -762,7 +762,7 @@ class OrderProcessingService
|
||||
'order_option_id' => $orderOption->id,
|
||||
'shipping_policy_id' => $shippingPolicy->policyId ?? null,
|
||||
'shipping_status' => ShippingStatusEnum::PENDING->value,
|
||||
'shipping_type' => $shippingType->value,
|
||||
'shipping_type' => $shippingType,
|
||||
'base_shipping_amount' => $shippingPolicy->shippingAmount ?? 0,
|
||||
'extra_shipping_amount' => $shippingPolicy->extraShippingAmount ?? 0,
|
||||
'total_shipping_amount' => $totalShippingFee,
|
||||
@@ -784,23 +784,32 @@ class OrderProcessingService
|
||||
*
|
||||
* @param object|null $shippingPolicy 배송 정책
|
||||
* @param TempOrder $tempOrder 임시 주문
|
||||
* @return ShippingTypeEnum
|
||||
* @return string
|
||||
*/
|
||||
protected function determineShippingType(?object $shippingPolicy, TempOrder $tempOrder): ShippingTypeEnum
|
||||
protected function determineShippingType(?object $shippingPolicy, TempOrder $tempOrder): string
|
||||
{
|
||||
// 배송 정책에 type이 있으면 사용
|
||||
if ($shippingPolicy && ! empty($shippingPolicy->type)) {
|
||||
return ShippingTypeEnum::tryFrom($shippingPolicy->type) ?? ShippingTypeEnum::DOMESTIC_PARCEL;
|
||||
$validCodes = ShippingType::where('is_active', true)->pluck('code')->toArray();
|
||||
if (in_array($shippingPolicy->type, $validCodes)) {
|
||||
return $shippingPolicy->type;
|
||||
}
|
||||
}
|
||||
|
||||
// 배송지 국가로 판단 (임시 주문에서)
|
||||
$shippingCountry = $tempOrder->shipping_address['country_code'] ?? 'KR';
|
||||
|
||||
if ($shippingCountry !== 'KR') {
|
||||
return ShippingTypeEnum::INTERNATIONAL_STANDARD;
|
||||
return ShippingType::where('category', 'international')
|
||||
->where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->value('code') ?? 'international_standard';
|
||||
}
|
||||
|
||||
return ShippingTypeEnum::DOMESTIC_PARCEL;
|
||||
return ShippingType::where('category', 'domestic')
|
||||
->where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->value('code') ?? 'parcel';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1070,6 +1079,9 @@ class OrderProcessingService
|
||||
|
||||
HookManager::doAction('sirsoft-ecommerce.order.after_payment_complete', $order);
|
||||
|
||||
// 주문 확인 알림 훅 (결제 완료 = 주문 확인 시점)
|
||||
HookManager::doAction('sirsoft-ecommerce.order.after_confirm', $order);
|
||||
|
||||
// 임시주문 정리 (PG 결제 완료 시점에 삭제, 이미 삭제된 경우 no-op)
|
||||
if ($order->user_id) {
|
||||
$this->tempOrderService->deleteTempOrder($order->user_id, null);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Modules\Sirsoft\Ecommerce\Services;
|
||||
|
||||
use App\Extension\HookManager;
|
||||
use App\Services\ActivityLogService;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -22,8 +21,7 @@ class OrderService
|
||||
{
|
||||
public function __construct(
|
||||
protected OrderRepositoryInterface $repository,
|
||||
protected UserAddressRepositoryInterface $userAddressRepository,
|
||||
protected ActivityLogService $activityLogService
|
||||
protected UserAddressRepositoryInterface $userAddressRepository
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -165,28 +163,20 @@ class OrderService
|
||||
}
|
||||
}
|
||||
|
||||
// 활동 로그 기록
|
||||
$newStatus = $order->order_status?->value;
|
||||
$changes = array_intersect_key($data, array_flip(['order_status', 'admin_memo']));
|
||||
// 수정 후 훅 (스냅샷 전달 — OrderActivityLogListener가 활동 로그 기록)
|
||||
HookManager::doAction('sirsoft-ecommerce.order.after_update', $order, $snapshot);
|
||||
|
||||
if (! empty($changes)) {
|
||||
$description = $oldStatus !== $newStatus
|
||||
? __('sirsoft-ecommerce::messages.orders.log_status_changed', [
|
||||
'old' => $oldStatus,
|
||||
'new' => $newStatus,
|
||||
])
|
||||
: __('sirsoft-ecommerce::messages.orders.log_updated');
|
||||
// 주문 상태 변경 시 알림 훅 발화
|
||||
$previousStatus = $snapshot['order_status'] ?? null;
|
||||
$currentStatus = $order->order_status;
|
||||
|
||||
$this->activityLogService->logAdmin(
|
||||
'order.update',
|
||||
$description,
|
||||
$order,
|
||||
['old_status' => $oldStatus, 'new_status' => $newStatus, 'changes' => $changes]
|
||||
);
|
||||
if ($currentStatus === OrderStatusEnum::SHIPPING && $previousStatus !== OrderStatusEnum::SHIPPING->value) {
|
||||
HookManager::doAction('sirsoft-ecommerce.order.after_ship', $order);
|
||||
}
|
||||
|
||||
// 수정 후 훅 (스냅샷 전달)
|
||||
HookManager::doAction('sirsoft-ecommerce.order.after_update', $order, $snapshot);
|
||||
if ($currentStatus === OrderStatusEnum::CONFIRMED && $previousStatus !== OrderStatusEnum::CONFIRMED->value) {
|
||||
HookManager::doAction('sirsoft-ecommerce.order.after_complete', $order);
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
@@ -166,13 +166,16 @@ class ShippingPolicyService
|
||||
// 삭제 전 훅
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_policy.before_delete', $shippingPolicy);
|
||||
|
||||
// 삭제 전 ID 캡처 (삭제 후 모델 id가 null이 될 수 있음)
|
||||
$shippingPolicyId = $shippingPolicy->id;
|
||||
|
||||
// 국가별 설정 명시적 삭제 (DB CASCADE에 의존하지 않음)
|
||||
$shippingPolicy->countrySettings()->delete();
|
||||
|
||||
$result = $this->repository->delete($shippingPolicy);
|
||||
|
||||
// 삭제 후 훅
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_policy.after_delete', $shippingPolicy->id);
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_policy.after_delete', $shippingPolicyId);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Services;
|
||||
|
||||
use App\Extension\HookManager;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ShippingType;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderShippingRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ShippingTypeRepositoryInterface;
|
||||
|
||||
/**
|
||||
* 배송유형 서비스
|
||||
*/
|
||||
class ShippingTypeService
|
||||
{
|
||||
/**
|
||||
* @param ShippingTypeRepositoryInterface $repository 배송유형 Repository
|
||||
* @param OrderShippingRepositoryInterface $orderShippingRepository 주문 배송 Repository
|
||||
*/
|
||||
public function __construct(
|
||||
protected ShippingTypeRepositoryInterface $repository,
|
||||
protected OrderShippingRepositoryInterface $orderShippingRepository,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 배송유형 목록 조회
|
||||
*
|
||||
* @param array $filters 필터 조건
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllTypes(array $filters = []): Collection
|
||||
{
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.before_list', $filters);
|
||||
|
||||
$filters = HookManager::applyFilters('sirsoft-ecommerce.shipping_type.filter_list_query', $filters);
|
||||
|
||||
$types = $this->repository->getAll($filters);
|
||||
|
||||
$types = HookManager::applyFilters('sirsoft-ecommerce.shipping_type.filter_list_result', $types, $filters);
|
||||
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.after_list', $types, $filters);
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송유형 상세 조회
|
||||
*
|
||||
* @param int $id 배송유형 ID
|
||||
* @return ShippingType|null
|
||||
*/
|
||||
public function getType(int $id): ?ShippingType
|
||||
{
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.before_show', $id);
|
||||
|
||||
$type = $this->repository->findById($id);
|
||||
|
||||
if ($type) {
|
||||
$type = HookManager::applyFilters('sirsoft-ecommerce.shipping_type.filter_show_result', $type);
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.after_show', $type);
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성 배송유형 목록 조회
|
||||
*
|
||||
* @param string|null $category 카테고리 필터
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveTypes(?string $category = null): Collection
|
||||
{
|
||||
return $this->repository->getActiveTypes($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정 페이지용 배송유형 목록을 반환합니다.
|
||||
*
|
||||
* @return array 설정 페이지에서 사용할 배열 형태의 배송유형 목록
|
||||
*/
|
||||
public function getTypesForSettings(): array
|
||||
{
|
||||
$types = $this->getAllTypes();
|
||||
|
||||
return $types->map(fn ($t) => [
|
||||
'id' => $t->id,
|
||||
'code' => $t->code,
|
||||
'name' => $t->name,
|
||||
'category' => $t->category,
|
||||
'is_active' => $t->is_active,
|
||||
'sort_order' => $t->sort_order,
|
||||
])->values()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송유형 생성
|
||||
*
|
||||
* @param array $data 배송유형 데이터
|
||||
* @return ShippingType
|
||||
*/
|
||||
public function createType(array $data): ShippingType
|
||||
{
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.before_create', $data);
|
||||
|
||||
$data = HookManager::applyFilters('sirsoft-ecommerce.shipping_type.filter_create_data', $data);
|
||||
|
||||
$data['created_by'] = Auth::id();
|
||||
$data['updated_by'] = Auth::id();
|
||||
|
||||
$type = DB::transaction(function () use ($data) {
|
||||
$type = $this->repository->create($data);
|
||||
|
||||
return $type->fresh();
|
||||
});
|
||||
|
||||
// 캐시 초기화
|
||||
ShippingType::clearCodeCache();
|
||||
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.after_create', $type, $data);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송유형 수정
|
||||
*
|
||||
* @param int $id 배송유형 ID
|
||||
* @param array $data 수정할 데이터
|
||||
* @return ShippingType
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateType(int $id, array $data): ShippingType
|
||||
{
|
||||
$type = $this->repository->findById($id);
|
||||
|
||||
if (! $type) {
|
||||
throw new \Exception(__('sirsoft-ecommerce::exceptions.shipping_type_not_found'));
|
||||
}
|
||||
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.before_update', $id, $data);
|
||||
|
||||
$snapshot = $type->toArray();
|
||||
|
||||
$data = HookManager::applyFilters('sirsoft-ecommerce.shipping_type.filter_update_data', $data, $id);
|
||||
|
||||
$data['updated_by'] = Auth::id();
|
||||
|
||||
$type = DB::transaction(function () use ($type, $data) {
|
||||
$type = $this->repository->update($type->id, $data);
|
||||
|
||||
return $type->fresh();
|
||||
});
|
||||
|
||||
// 캐시 초기화
|
||||
ShippingType::clearCodeCache();
|
||||
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.after_update', $type, $data, $snapshot);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송유형 일괄 동기화 (설정 저장 시 사용)
|
||||
*
|
||||
* payload에 있는 types를 DB와 동기화합니다.
|
||||
* - id 있음 → 기존 type 업데이트
|
||||
* - id 없음 → 새 type 생성
|
||||
* - DB에 있지만 payload에 없음 → 삭제 (주문에서 사용 중이면 예외)
|
||||
*
|
||||
* @param array $typesData types 배열
|
||||
* @return void
|
||||
* @throws \Exception 사용 중인 배송유형 삭제 시도 시
|
||||
*/
|
||||
public function syncShippingTypes(array $typesData): void
|
||||
{
|
||||
DB::transaction(function () use ($typesData) {
|
||||
$existingIds = ShippingType::pluck('id')->toArray();
|
||||
$incomingIds = array_filter(array_column($typesData, 'id'));
|
||||
|
||||
// 삭제: DB에 있지만 payload에 없는 항목
|
||||
$toDeleteIds = array_diff($existingIds, $incomingIds);
|
||||
foreach ($toDeleteIds as $id) {
|
||||
$type = ShippingType::find($id);
|
||||
if ($type) {
|
||||
$usageCount = $this->orderShippingRepository->countByShippingType($type->code);
|
||||
if ($usageCount > 0) {
|
||||
throw new \Exception(__('sirsoft-ecommerce::exceptions.shipping_type_in_use', [
|
||||
'name' => $type->getLocalizedName(),
|
||||
'count' => $usageCount,
|
||||
]));
|
||||
}
|
||||
$type->delete();
|
||||
}
|
||||
}
|
||||
|
||||
// 생성/수정
|
||||
foreach ($typesData as $index => $data) {
|
||||
$typeData = [
|
||||
'code' => $data['code'],
|
||||
'name' => $data['name'],
|
||||
'category' => $data['category'],
|
||||
'is_active' => $data['is_active'] ?? true,
|
||||
'sort_order' => $index,
|
||||
'updated_by' => Auth::id(),
|
||||
];
|
||||
|
||||
if (! empty($data['id']) && in_array($data['id'], $existingIds)) {
|
||||
ShippingType::where('id', $data['id'])->update($typeData);
|
||||
} else {
|
||||
$typeData['created_by'] = Auth::id();
|
||||
ShippingType::create($typeData);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 캐시 초기화
|
||||
ShippingType::clearCodeCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송유형 삭제
|
||||
*
|
||||
* @param int $id 배송유형 ID
|
||||
* @return array 삭제 결과 정보
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deleteType(int $id): array
|
||||
{
|
||||
$type = $this->repository->findById($id);
|
||||
|
||||
if (! $type) {
|
||||
throw new \Exception(__('sirsoft-ecommerce::exceptions.shipping_type_not_found'));
|
||||
}
|
||||
|
||||
// 주문에서 사용 중인지 확인
|
||||
$usageCount = $this->orderShippingRepository->countByShippingType($type->code);
|
||||
|
||||
if ($usageCount > 0) {
|
||||
throw new \Exception(__('sirsoft-ecommerce::exceptions.shipping_type_in_use', [
|
||||
'name' => $type->getLocalizedName(),
|
||||
'count' => $usageCount,
|
||||
]));
|
||||
}
|
||||
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.before_delete', $type);
|
||||
|
||||
DB::transaction(function () use ($type) {
|
||||
$this->repository->delete($type->id);
|
||||
});
|
||||
|
||||
// 캐시 초기화
|
||||
ShippingType::clearCodeCache();
|
||||
|
||||
HookManager::doAction('sirsoft-ecommerce.shipping_type.after_delete', $type->id);
|
||||
|
||||
return [
|
||||
'type_id' => $type->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Modules\Sirsoft\Ecommerce\Services;
|
||||
|
||||
use App\Helpers\ResponseHelper;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\DuplicateAddressException;
|
||||
use Modules\Sirsoft\Ecommerce\Models\UserAddress;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\UserAddressRepositoryInterface;
|
||||
|
||||
@@ -73,14 +73,7 @@ class UserAddressService
|
||||
return $this->updateAddress($userId, $existingAddress->id, $data);
|
||||
}
|
||||
|
||||
// 409 Conflict 응답
|
||||
throw new \Illuminate\Http\Exceptions\HttpResponseException(
|
||||
ResponseHelper::error(
|
||||
__('sirsoft-ecommerce::messages.address.name_duplicate'),
|
||||
409,
|
||||
['duplicate_address_id' => $existingAddress->id]
|
||||
)
|
||||
);
|
||||
throw new DuplicateAddressException($existingAddress->id);
|
||||
}
|
||||
|
||||
unset($data['force_overwrite']);
|
||||
|
||||
@@ -94,18 +94,6 @@ return [
|
||||
'pickup_complete' => 'Picked Up',
|
||||
],
|
||||
|
||||
// Shipping Type (matches ShippingTypeEnum values)
|
||||
'shipping_type' => [
|
||||
'domestic_parcel' => 'Domestic Parcel',
|
||||
'domestic_express' => 'Domestic Express',
|
||||
'domestic_quick' => 'Quick Service',
|
||||
'international_ems' => 'International EMS',
|
||||
'international_standard' => 'International Standard',
|
||||
'pickup' => 'Store Pickup',
|
||||
'cvs' => 'Convenience Store',
|
||||
'digital' => 'Digital Product',
|
||||
],
|
||||
|
||||
// Option Status
|
||||
'option_status' => [
|
||||
'ordered' => 'Ordered',
|
||||
@@ -197,20 +185,6 @@ return [
|
||||
'cancelled' => 'Cancelled',
|
||||
],
|
||||
|
||||
// Shipping Method
|
||||
'shipping_method' => [
|
||||
'parcel' => 'Parcel',
|
||||
'freight' => 'Freight',
|
||||
'express' => 'Express',
|
||||
'economy' => 'Economy',
|
||||
'ems' => 'EMS',
|
||||
'collect' => 'Collect on Delivery',
|
||||
'quick' => 'Quick Service',
|
||||
'direct' => 'Direct Delivery',
|
||||
'pickup' => 'Pickup',
|
||||
'other' => 'Other',
|
||||
],
|
||||
|
||||
// Charge Policy
|
||||
'charge_policy' => [
|
||||
'free' => 'Free',
|
||||
|
||||
@@ -62,4 +62,8 @@ return [
|
||||
// Claim Reason related
|
||||
'claim_reason_not_found' => 'Claim reason not found.',
|
||||
'claim_reason_in_use' => 'Cannot delete a reason in use by order cancellations. (Used :count times)',
|
||||
|
||||
// Shipping Type related
|
||||
'shipping_type_not_found' => 'Shipping type not found.',
|
||||
'shipping_type_in_use' => 'Cannot delete shipping type (:name) in use by orders. (Used :count times)',
|
||||
];
|
||||
@@ -1121,19 +1121,6 @@ return [
|
||||
'settings_retrieved' => 'Active extra fee template settings retrieved successfully.',
|
||||
],
|
||||
|
||||
// Mail template management
|
||||
'mail_template_fetch_success' => 'Mail templates retrieved successfully.',
|
||||
'mail_template_fetch_failed' => 'Failed to retrieve mail templates.',
|
||||
'mail_template_save_success' => 'Mail template has been saved.',
|
||||
'mail_template_save_error' => 'Failed to save mail template.',
|
||||
'mail_template_toggle_success' => 'Mail template status has been changed.',
|
||||
'mail_template_toggle_failed' => 'Failed to change mail template status.',
|
||||
'mail_template_reset_success' => 'Mail template has been reset to default.',
|
||||
'mail_template_reset_failed' => 'Failed to reset mail template.',
|
||||
'mail_template_reset_no_default' => 'Default template data not found.',
|
||||
'mail_template_preview_success' => 'Mail template preview generated.',
|
||||
'mail_template_preview_failed' => 'Failed to generate mail template preview.',
|
||||
|
||||
// Product 1:1 Inquiries
|
||||
'inquiries' => [
|
||||
'fetch_success' => 'Inquiry list retrieved successfully.',
|
||||
|
||||
@@ -869,6 +869,7 @@ return [
|
||||
'is_active_required' => 'Please select active status.',
|
||||
'is_active_boolean' => 'Active status must be true or false.',
|
||||
'base_fee_zero_not_allowed' => 'Shipping fee cannot be 0 for non-free shipping policies.',
|
||||
'custom_shipping_name_required' => 'Please enter a shipping method name when selecting custom.',
|
||||
'ranges' => [
|
||||
'first_min_zero' => 'The first tier must start at 0.',
|
||||
'last_max_unlimited' => 'The last tier must have no upper limit.',
|
||||
@@ -1124,6 +1125,9 @@ return [
|
||||
'seo.meta_search_description' => 'Search Page Description',
|
||||
'seo.meta_product_title' => 'Product Page Title',
|
||||
'seo.meta_product_description' => 'Product Page Description',
|
||||
'seo.meta_shop_index_title' => 'Shop Main Page Title',
|
||||
'seo.meta_shop_index_description' => 'Shop Main Page Description',
|
||||
'seo.seo_shop_index' => 'Shop Main Page SEO',
|
||||
'seo.seo_user_agents' => 'SEO User Agents',
|
||||
|
||||
// Order settings
|
||||
@@ -1351,6 +1355,17 @@ return [
|
||||
'seo_product_detail' => [
|
||||
'boolean' => 'Product detail page SEO option must be true or false.',
|
||||
],
|
||||
'meta_shop_index_title' => [
|
||||
'string' => 'Shop main page title must be a string.',
|
||||
'max' => 'Shop main page title cannot exceed 500 characters.',
|
||||
],
|
||||
'meta_shop_index_description' => [
|
||||
'string' => 'Shop main page description must be a string.',
|
||||
'max' => 'Shop main page description cannot exceed 1000 characters.',
|
||||
],
|
||||
'seo_shop_index' => [
|
||||
'boolean' => 'Shop main page SEO option must be true or false.',
|
||||
],
|
||||
'seo_user_agents' => [
|
||||
'string' => 'SEO user agent must be a string.',
|
||||
'max' => 'SEO user agent cannot exceed 100 characters.',
|
||||
@@ -1496,6 +1511,27 @@ return [
|
||||
'string' => 'Address API provider must be a string.',
|
||||
'max' => 'Address API provider must not exceed 50 characters.',
|
||||
],
|
||||
'types' => [
|
||||
'duplicate_code' => 'Duplicate shipping type code found.',
|
||||
'name_required' => 'Shipping type name is required.',
|
||||
'code' => [
|
||||
'required_with' => 'Shipping type code is required.',
|
||||
'string' => 'Shipping type code must be a string.',
|
||||
'max' => 'Shipping type code must not exceed 50 characters.',
|
||||
'regex' => 'Shipping type code must contain only lowercase letters, numbers, hyphens, and underscores.',
|
||||
],
|
||||
'name' => [
|
||||
'required_with' => 'Shipping type name is required.',
|
||||
'array' => 'Shipping type name must be a multilingual array.',
|
||||
],
|
||||
'category' => [
|
||||
'required_with' => 'Shipping type category is required.',
|
||||
'in' => 'Shipping type category must be one of: domestic, international, other.',
|
||||
],
|
||||
'is_active' => [
|
||||
'boolean' => 'Shipping type active status must be true or false.',
|
||||
],
|
||||
],
|
||||
'carriers' => [
|
||||
'duplicate_code' => 'Duplicate carrier code found.',
|
||||
'name_required' => 'Carrier name is required.',
|
||||
|
||||
@@ -94,18 +94,6 @@ return [
|
||||
'pickup_complete' => '방문수령완료',
|
||||
],
|
||||
|
||||
// 배송유형 (ShippingTypeEnum 값과 일치)
|
||||
'shipping_type' => [
|
||||
'domestic_parcel' => '국내택배',
|
||||
'domestic_express' => '국내특급',
|
||||
'domestic_quick' => '퀵서비스',
|
||||
'international_ems' => '국제EMS',
|
||||
'international_standard' => '국제일반',
|
||||
'pickup' => '방문수령',
|
||||
'cvs' => '편의점택배',
|
||||
'digital' => '디지털상품',
|
||||
],
|
||||
|
||||
// 옵션상태
|
||||
'option_status' => [
|
||||
'ordered' => '주문완료',
|
||||
@@ -197,20 +185,6 @@ return [
|
||||
'cancelled' => '취소됨',
|
||||
],
|
||||
|
||||
// 배송방법
|
||||
'shipping_method' => [
|
||||
'parcel' => '택배',
|
||||
'freight' => '화물',
|
||||
'express' => '특급',
|
||||
'economy' => '이코노미',
|
||||
'ems' => 'EMS',
|
||||
'collect' => '착불',
|
||||
'quick' => '퀵서비스',
|
||||
'direct' => '직접배송',
|
||||
'pickup' => '방문수령',
|
||||
'other' => '기타',
|
||||
],
|
||||
|
||||
// 과금정책
|
||||
'charge_policy' => [
|
||||
'free' => '무료',
|
||||
|
||||
@@ -62,4 +62,8 @@ return [
|
||||
// 클래임 사유 관련
|
||||
'claim_reason_not_found' => '클래임 사유를 찾을 수 없습니다.',
|
||||
'claim_reason_in_use' => '주문 취소에서 사용 중인 사유는 삭제할 수 없습니다. (사용 횟수: :count건)',
|
||||
|
||||
// 배송유형 관련
|
||||
'shipping_type_not_found' => '배송유형을 찾을 수 없습니다.',
|
||||
'shipping_type_in_use' => '주문에서 사용 중인 배송유형(:name)은 삭제할 수 없습니다. (사용 횟수: :count건)',
|
||||
];
|
||||
@@ -1110,19 +1110,6 @@ return [
|
||||
'settings_retrieved' => '활성 추가배송비 템플릿 설정을 조회했습니다.',
|
||||
],
|
||||
|
||||
// 메일 템플릿 관리
|
||||
'mail_template_fetch_success' => '메일 템플릿 목록을 조회했습니다.',
|
||||
'mail_template_fetch_failed' => '메일 템플릿 목록 조회에 실패했습니다.',
|
||||
'mail_template_save_success' => '메일 템플릿이 저장되었습니다.',
|
||||
'mail_template_save_error' => '메일 템플릿 저장에 실패했습니다.',
|
||||
'mail_template_toggle_success' => '메일 템플릿 상태가 변경되었습니다.',
|
||||
'mail_template_toggle_failed' => '메일 템플릿 상태 변경에 실패했습니다.',
|
||||
'mail_template_reset_success' => '메일 템플릿이 기본값으로 복원되었습니다.',
|
||||
'mail_template_reset_failed' => '메일 템플릿 복원에 실패했습니다.',
|
||||
'mail_template_reset_no_default' => '기본 템플릿 데이터를 찾을 수 없습니다.',
|
||||
'mail_template_preview_success' => '메일 템플릿 미리보기가 생성되었습니다.',
|
||||
'mail_template_preview_failed' => '메일 템플릿 미리보기 생성에 실패했습니다.',
|
||||
|
||||
// 상품 1:1 문의
|
||||
'inquiries' => [
|
||||
'fetch_success' => '문의 목록을 조회했습니다.',
|
||||
|
||||
@@ -869,6 +869,7 @@ return [
|
||||
'is_active_required' => '사용여부를 선택해주세요.',
|
||||
'is_active_boolean' => '사용여부는 true 또는 false여야 합니다.',
|
||||
'base_fee_zero_not_allowed' => '무료배송이 아닌 정책은 배송비를 0원으로 설정할 수 없습니다.',
|
||||
'custom_shipping_name_required' => '직접입력 배송방법 선택 시 배송방법명을 입력해주세요.',
|
||||
'ranges' => [
|
||||
'first_min_zero' => '첫 구간의 시작값은 0이어야 합니다.',
|
||||
'last_max_unlimited' => '마지막 구간의 종료값은 비워야 합니다.',
|
||||
@@ -1124,6 +1125,9 @@ return [
|
||||
'seo.meta_search_description' => '검색 페이지 설명',
|
||||
'seo.meta_product_title' => '상품 페이지 타이틀',
|
||||
'seo.meta_product_description' => '상품 페이지 설명',
|
||||
'seo.meta_shop_index_title' => '쇼핑몰 메인 페이지 타이틀',
|
||||
'seo.meta_shop_index_description' => '쇼핑몰 메인 페이지 설명',
|
||||
'seo.seo_shop_index' => '쇼핑몰 메인 페이지 SEO 사용',
|
||||
'seo.seo_user_agents' => 'SEO 사용자 에이전트',
|
||||
|
||||
// 주문 설정
|
||||
@@ -1351,6 +1355,17 @@ return [
|
||||
'seo_product_detail' => [
|
||||
'boolean' => '상품상세 페이지 SEO 사용 여부는 참/거짓 값이어야 합니다.',
|
||||
],
|
||||
'meta_shop_index_title' => [
|
||||
'string' => '쇼핑몰 메인 페이지 타이틀은 문자열이어야 합니다.',
|
||||
'max' => '쇼핑몰 메인 페이지 타이틀은 최대 500자까지 입력 가능합니다.',
|
||||
],
|
||||
'meta_shop_index_description' => [
|
||||
'string' => '쇼핑몰 메인 페이지 설명은 문자열이어야 합니다.',
|
||||
'max' => '쇼핑몰 메인 페이지 설명은 최대 1000자까지 입력 가능합니다.',
|
||||
],
|
||||
'seo_shop_index' => [
|
||||
'boolean' => '쇼핑몰 메인 페이지 SEO 사용 여부는 참/거짓 값이어야 합니다.',
|
||||
],
|
||||
'seo_user_agents' => [
|
||||
'string' => 'SEO 사용자 에이전트는 문자열이어야 합니다.',
|
||||
'max' => 'SEO 사용자 에이전트는 최대 100자까지 입력 가능합니다.',
|
||||
@@ -1498,6 +1513,27 @@ return [
|
||||
'string' => '주소검증 API 제공자는 문자열이어야 합니다.',
|
||||
'max' => '주소검증 API 제공자는 최대 50자까지 입력 가능합니다.',
|
||||
],
|
||||
'types' => [
|
||||
'duplicate_code' => '중복된 배송유형 코드가 있습니다.',
|
||||
'name_required' => '배송유형명은 필수 항목입니다.',
|
||||
'code' => [
|
||||
'required_with' => '배송유형 코드는 필수입니다.',
|
||||
'string' => '배송유형 코드는 문자열이어야 합니다.',
|
||||
'max' => '배송유형 코드는 최대 50자까지 입력 가능합니다.',
|
||||
'regex' => '배송유형 코드는 영문 소문자, 숫자, 하이픈, 언더스코어만 사용 가능합니다.',
|
||||
],
|
||||
'name' => [
|
||||
'required_with' => '배송유형명은 필수입니다.',
|
||||
'array' => '배송유형명은 다국어 배열 형식이어야 합니다.',
|
||||
],
|
||||
'category' => [
|
||||
'required_with' => '배송유형 카테고리는 필수입니다.',
|
||||
'in' => '배송유형 카테고리는 국내배송, 해외배송, 기타 중 하나여야 합니다.',
|
||||
],
|
||||
'is_active' => [
|
||||
'boolean' => '배송유형 사용여부는 참/거짓 값이어야 합니다.',
|
||||
],
|
||||
],
|
||||
'carriers' => [
|
||||
'duplicate_code' => '중복된 배송사 코드가 있습니다.',
|
||||
'name_required' => '배송사명은 필수 항목입니다.',
|
||||
|
||||
@@ -4,7 +4,6 @@ use Illuminate\Support\Facades\Route;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Controllers\Admin\BrandController;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Controllers\Admin\CategoryController;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Controllers\Admin\CouponController;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Controllers\Admin\EcommerceMailTemplateController;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Controllers\Admin\EcommerceSettingsController;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Controllers\Admin\ExtraFeeTemplateController;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Controllers\Admin\OrderController;
|
||||
@@ -470,6 +469,10 @@ Route::prefix('admin')->middleware(['auth:sanctum', 'admin'])->group(function ()
|
||||
->middleware('permission:admin,sirsoft-ecommerce.settings.update')
|
||||
->name('admin.settings.store-banks');
|
||||
|
||||
Route::get('settings/seo-cache-info', [EcommerceSettingsController::class, 'seoCacheInfo'])
|
||||
->middleware('permission:admin,sirsoft-ecommerce.settings.read')
|
||||
->name('admin.settings.seo-cache-info');
|
||||
|
||||
Route::get('settings/{category}', [EcommerceSettingsController::class, 'show'])
|
||||
->middleware('permission:admin,sirsoft-ecommerce.settings.read')
|
||||
->name('admin.settings.show');
|
||||
@@ -479,32 +482,6 @@ Route::prefix('admin')->middleware(['auth:sanctum', 'admin'])->group(function ()
|
||||
->name('admin.settings.clear-cache');
|
||||
|
||||
// 메일 템플릿 관리
|
||||
// GET /api/modules/sirsoft-ecommerce/admin/mail-templates - 목록 조회
|
||||
// PUT /api/modules/sirsoft-ecommerce/admin/mail-templates/{ecommerceMailTemplate} - 수정
|
||||
// PATCH /api/modules/sirsoft-ecommerce/admin/mail-templates/{ecommerceMailTemplate}/toggle-active - 활성 토글
|
||||
// POST /api/modules/sirsoft-ecommerce/admin/mail-templates/{ecommerceMailTemplate}/reset - 기본값 복원
|
||||
Route::prefix('mail-templates')->group(function () {
|
||||
Route::get('/', [EcommerceMailTemplateController::class, 'index'])
|
||||
->middleware('permission:admin,sirsoft-ecommerce.settings.read')
|
||||
->name('admin.mail-templates.index');
|
||||
|
||||
Route::put('{ecommerceMailTemplate}', [EcommerceMailTemplateController::class, 'update'])
|
||||
->middleware('permission:admin,sirsoft-ecommerce.settings.update')
|
||||
->name('admin.mail-templates.update');
|
||||
|
||||
Route::patch('{ecommerceMailTemplate}/toggle-active', [EcommerceMailTemplateController::class, 'toggleActive'])
|
||||
->middleware('permission:admin,sirsoft-ecommerce.settings.update')
|
||||
->name('admin.mail-templates.toggle-active');
|
||||
|
||||
Route::post('preview', [EcommerceMailTemplateController::class, 'preview'])
|
||||
->middleware('permission:admin,sirsoft-ecommerce.settings.read')
|
||||
->name('admin.mail-templates.preview');
|
||||
|
||||
Route::post('{ecommerceMailTemplate}/reset', [EcommerceMailTemplateController::class, 'reset'])
|
||||
->middleware('permission:admin,sirsoft-ecommerce.settings.update')
|
||||
->name('admin.mail-templates.reset');
|
||||
});
|
||||
|
||||
// 배송정책 관리 API
|
||||
// GET /api/modules/sirsoft-ecommerce/admin/shipping-policies - 배송정책 목록 조회
|
||||
// POST /api/modules/sirsoft-ecommerce/admin/shipping-policies - 배송정책 생성
|
||||
|
||||
Reference in new issue
Block a user