command?->info('이커머스 알림 정의 시딩 시작...');
$helper = app(NotificationSyncHelper::class);
$definitions = $this->getDefaultDefinitions();
$definedTypes = [];
foreach ($definitions as $data) {
$definition = $helper->syncDefinition($data);
$definedTypes[] = $definition->type;
$definedChannels = [];
foreach ($data['templates'] as $template) {
$helper->syncTemplate($definition->id, $template);
$definedChannels[] = $template['channel'];
}
// 완전 동기화: seeder 에서 제거된 channel 의 template 삭제
$helper->cleanupStaleTemplates($definition->id, $definedChannels);
$this->command?->info(" - {$data['type']} 알림 정의 등록 완료");
}
// 완전 동기화: seeder 에서 제거된 이커머스 definition 삭제 (cascade 로 template 도 정리)
$helper->cleanupStaleDefinitions('module', 'sirsoft-ecommerce', $definedTypes);
$this->command?->info('이커머스 알림 정의 시딩 완료 ('.count($definitions).'종)');
}
/**
* 이커머스 기본 알림 정의 데이터를 반환합니다.
*
* @return array
*/
public function getDefaultDefinitions(): array
{
return [
$this->orderConfirmedDefinition(),
$this->orderShippedDefinition(),
$this->orderCompletedDefinition(),
$this->orderCancelledDefinition(),
$this->newOrderAdminDefinition(),
$this->inquiryReceivedDefinition(),
$this->inquiryRepliedDefinition(),
];
}
/**
* 주문 확인 알림 정의.
*
* @return array
*/
private function orderConfirmedDefinition(): array
{
return [
'type' => 'order_confirmed',
'hook_prefix' => 'sirsoft-ecommerce',
'extension_type' => 'module',
'extension_identifier' => 'sirsoft-ecommerce',
'name' => ['ko' => '주문 확인', 'en' => 'Order Confirmed'],
'description' => ['ko' => '주문 확인 시 고객에게 발송', 'en' => 'Sent to customer when order is confirmed'],
'channels' => ['mail', 'database'],
'hooks' => ['sirsoft-ecommerce.order.after_confirm'],
'variables' => [
['key' => 'name', 'description' => '수신자 이름'],
['key' => 'app_name', 'description' => '사이트 이름'],
['key' => 'order_number', 'description' => '주문번호'],
['key' => 'total_amount', 'description' => '결제 금액'],
['key' => 'order_url', 'description' => '주문 상세 URL'],
['key' => 'site_url', 'description' => '사이트 URL'],
],
'templates' => [
[
'channel' => 'mail',
'recipients' => [['type' => 'trigger_user']],
'subject' => [
'ko' => '[{app_name}] 주문이 확인되었습니다 (주문번호: {order_number})',
'en' => '[{app_name}] Your order has been confirmed (Order #{order_number})',
],
'body' => [
'ko' => '
'
.'
주문 확인
'
.'
{name}님, 주문해 주셔서 감사합니다.
'
.'
'
.'
주문번호: {order_number}
'
.'
결제금액: {total_amount}
'
.'
'
.'
주문 상세 내용은 아래 버튼을 클릭하여 확인하실 수 있습니다.
'
.$this->button('주문 상세 보기', '{order_url}')
.'
'
.'
본 메일은 {app_name}에서 발송되었습니다.
'
.'
',
'en' => ''
.'
Order Confirmed
'
.'
Dear {name}, thank you for your order.
'
.'
'
.'
Order Number: {order_number}
'
.'
Total Amount: {total_amount}
'
.'
'
.'
Click the button below to view your order details.
'
.$this->button('View Order', '{order_url}')
.'
'
.'
This email was sent from {app_name}.
'
.'
',
],
],
[
'channel' => 'database',
'recipients' => [['type' => 'trigger_user']],
'subject' => ['ko' => '주문이 확인되었습니다', 'en' => 'Your order has been confirmed'],
'body' => ['ko' => '{name}님, 주문번호 {order_number}의 주문이 확인되었습니다.', 'en' => '{name}, your order {order_number} has been confirmed.'],
'click_url' => '{order_url}',
],
],
];
}
/**
* 배송 시작 알림 정의.
*
* @return array
*/
private function orderShippedDefinition(): array
{
return [
'type' => 'order_shipped',
'hook_prefix' => 'sirsoft-ecommerce',
'extension_type' => 'module',
'extension_identifier' => 'sirsoft-ecommerce',
'name' => ['ko' => '배송 시작', 'en' => 'Order Shipped'],
'description' => ['ko' => '배송 시작 시 고객에게 발송', 'en' => 'Sent to customer when order is shipped'],
'channels' => ['mail', 'database'],
'hooks' => ['sirsoft-ecommerce.order.after_ship'],
'variables' => [
['key' => 'name', 'description' => '수신자 이름'],
['key' => 'app_name', 'description' => '사이트 이름'],
['key' => 'order_number', 'description' => '주문번호'],
['key' => 'carrier_name', 'description' => '택배사 이름'],
['key' => 'tracking_number', 'description' => '운송장 번호'],
['key' => 'order_url', 'description' => '주문 상세 URL'],
['key' => 'site_url', 'description' => '사이트 URL'],
],
'templates' => [
[
'channel' => 'mail',
'recipients' => [['type' => 'trigger_user']],
'subject' => [
'ko' => '[{app_name}] 주문하신 상품이 발송되었습니다 (주문번호: {order_number})',
'en' => '[{app_name}] Your order has been shipped (Order #{order_number})',
],
'body' => [
'ko' => ''
.'
배송 시작 안내
'
.'
{name}님, 주문하신 상품이 발송되었습니다.
'
.'
'
.'
주문번호: {order_number}
'
.'
택배사: {carrier_name}
'
.'
운송장번호: {tracking_number}
'
.'
'
.'
주문 상세 및 배송 현황은 아래 버튼을 클릭하여 확인하실 수 있습니다.
'
.$this->button('주문 상세 보기', '{order_url}')
.'
'
.'
본 메일은 {app_name}에서 발송되었습니다.
'
.'
',
'en' => ''
.'
Order Shipped
'
.'
Dear {name}, your order has been shipped.
'
.'
'
.'
Order Number: {order_number}
'
.'
Carrier: {carrier_name}
'
.'
Tracking Number: {tracking_number}
'
.'
'
.'
Click the button below to view your order and tracking details.
'
.$this->button('View Order', '{order_url}')
.'
'
.'
This email was sent from {app_name}.
'
.'
',
],
],
[
'channel' => 'database',
'recipients' => [['type' => 'trigger_user']],
'subject' => ['ko' => '상품이 발송되었습니다', 'en' => 'Your order has been shipped'],
'body' => ['ko' => '{name}님, 주문번호 {order_number}이 {carrier_name}(송장번호: {tracking_number})으로 발송되었습니다.', 'en' => '{name}, your order {order_number} has been shipped via {carrier_name} (tracking: {tracking_number}).'],
'click_url' => '{order_url}',
],
],
];
}
/**
* 구매 확정 알림 정의.
*
* @return array
*/
private function orderCompletedDefinition(): array
{
return [
'type' => 'order_completed',
'hook_prefix' => 'sirsoft-ecommerce',
'extension_type' => 'module',
'extension_identifier' => 'sirsoft-ecommerce',
'name' => ['ko' => '구매 확정', 'en' => 'Order Completed'],
'description' => ['ko' => '구매 확정 시 고객에게 발송', 'en' => 'Sent to customer when order is completed'],
'channels' => ['mail', 'database'],
'hooks' => ['sirsoft-ecommerce.order.after_complete'],
'variables' => [
['key' => 'name', 'description' => '수신자 이름'],
['key' => 'app_name', 'description' => '사이트 이름'],
['key' => 'order_number', 'description' => '주문번호'],
['key' => 'total_amount', 'description' => '결제 금액'],
['key' => 'order_url', 'description' => '주문 상세 URL'],
['key' => 'site_url', 'description' => '사이트 URL'],
],
'templates' => [
[
'channel' => 'mail',
'recipients' => [['type' => 'trigger_user']],
'subject' => [
'ko' => '[{app_name}] 구매가 확정되었습니다 (주문번호: {order_number})',
'en' => '[{app_name}] Your purchase has been completed (Order #{order_number})',
],
'body' => [
'ko' => ''
.'
구매 확정 안내
'
.'
{name}님, 구매가 확정되었습니다. 이용해 주셔서 감사합니다.
'
.'
'
.'
주문번호: {order_number}
'
.'
결제금액: {total_amount}
'
.'
'
.'
주문 내역은 아래 버튼을 클릭하여 확인하실 수 있습니다.
'
.$this->button('주문 내역 보기', '{order_url}')
.'
'
.'
본 메일은 {app_name}에서 발송되었습니다.
'
.'
',
'en' => ''
.'
Purchase Completed
'
.'
Dear {name}, your purchase has been completed. Thank you for shopping with us.
'
.'
'
.'
Order Number: {order_number}
'
.'
Total Amount: {total_amount}
'
.'
'
.'
Click the button below to view your order history.
'
.$this->button('View Order', '{order_url}')
.'
'
.'
This email was sent from {app_name}.
'
.'
',
],
],
[
'channel' => 'database',
'recipients' => [['type' => 'trigger_user']],
'subject' => ['ko' => '구매가 확정되었습니다', 'en' => 'Your purchase has been confirmed'],
'body' => ['ko' => '{name}님, 주문번호 {order_number}의 구매가 확정되었습니다.', 'en' => '{name}, your order {order_number} has been confirmed.'],
'click_url' => '{order_url}',
],
],
];
}
/**
* 주문 취소 알림 정의.
*
* @return array
*/
private function orderCancelledDefinition(): array
{
return [
'type' => 'order_cancelled',
'hook_prefix' => 'sirsoft-ecommerce',
'extension_type' => 'module',
'extension_identifier' => 'sirsoft-ecommerce',
'name' => ['ko' => '주문 취소', 'en' => 'Order Cancelled'],
'description' => ['ko' => '주문 취소 시 고객에게 발송', 'en' => 'Sent to customer when order is cancelled'],
'channels' => ['mail', 'database'],
'hooks' => ['sirsoft-ecommerce.order.after_cancel'],
'variables' => [
['key' => 'name', 'description' => '수신자 이름'],
['key' => 'app_name', 'description' => '사이트 이름'],
['key' => 'order_number', 'description' => '주문번호'],
['key' => 'cancel_reason', 'description' => '취소 사유'],
['key' => 'order_url', 'description' => '주문 상세 URL'],
['key' => 'site_url', 'description' => '사이트 URL'],
],
'templates' => [
[
'channel' => 'mail',
'recipients' => [['type' => 'trigger_user']],
'subject' => [
'ko' => '[{app_name}] 주문이 취소되었습니다 (주문번호: {order_number})',
'en' => '[{app_name}] Your order has been cancelled (Order #{order_number})',
],
'body' => [
'ko' => ''
.'
주문 취소 안내
'
.'
{name}님, 주문이 취소되었습니다.
'
.'
'
.'
주문번호: {order_number}
'
.'
취소 사유: {cancel_reason}
'
.'
'
.'
환불은 결제 수단에 따라 3~7영업일 이내에 처리됩니다. 주문 상세는 아래 버튼을 클릭하여 확인하실 수 있습니다.
'
.$this->button('주문 상세 보기', '{order_url}')
.'
'
.'
본 메일은 {app_name}에서 발송되었습니다.
'
.'
',
'en' => ''
.'
Order Cancelled
'
.'
Dear {name}, your order has been cancelled.
'
.'
'
.'
Order Number: {order_number}
'
.'
Cancel Reason: {cancel_reason}
'
.'
'
.'
Refunds will be processed within 3-7 business days depending on your payment method. Click the button below to view your order details.
'
.$this->button('View Order', '{order_url}')
.'
'
.'
This email was sent from {app_name}.
'
.'
',
],
],
[
'channel' => 'database',
'recipients' => [['type' => 'trigger_user']],
'subject' => ['ko' => '주문이 취소되었습니다', 'en' => 'Your order has been cancelled'],
'body' => ['ko' => '{name}님, 주문번호 {order_number}이 취소되었습니다. 사유: {cancel_reason}', 'en' => '{name}, your order {order_number} has been cancelled. Reason: {cancel_reason}'],
'click_url' => '{order_url}',
],
],
];
}
/**
* 관리자 신규 주문 알림 정의.
*
* @return array
*/
private function newOrderAdminDefinition(): array
{
return [
'type' => 'new_order_admin',
'hook_prefix' => 'sirsoft-ecommerce',
'extension_type' => 'module',
'extension_identifier' => 'sirsoft-ecommerce',
'name' => ['ko' => '신규 주문 관리자 알림', 'en' => 'New Order Admin Notification'],
'description' => ['ko' => '신규 주문 접수 시 관리자에게 발송', 'en' => 'Sent to admin when a new order is placed'],
'channels' => ['mail', 'database'],
'hooks' => ['sirsoft-ecommerce.order.after_create'],
'variables' => [
['key' => 'name', 'description' => '수신자(관리자) 이름'],
['key' => 'app_name', 'description' => '사이트 이름'],
['key' => 'order_number', 'description' => '주문번호'],
['key' => 'customer_name', 'description' => '주문자 이름'],
['key' => 'total_amount', 'description' => '결제 금액'],
['key' => 'order_url', 'description' => '주문 관리 URL'],
['key' => 'site_url', 'description' => '사이트 URL'],
],
'templates' => [
[
'channel' => 'mail',
'recipients' => [['type' => 'role', 'value' => 'admin', 'exclude_trigger_user' => true]],
'subject' => [
'ko' => '[{app_name}] 신규 주문이 접수되었습니다 (주문번호: {order_number})',
'en' => '[{app_name}] New order received (Order #{order_number})',
],
'body' => [
'ko' => ''
.'
신규 주문 접수
'
.'
{name}님, 새로운 주문이 접수되었습니다.
'
.'
'
.'
주문번호: {order_number}
'
.'
주문자: {customer_name}
'
.'
결제금액: {total_amount}
'
.'
'
.'
관리자 페이지에서 주문 상세를 확인해 주세요.
'
.$this->button('주문 관리 바로가기', '{order_url}')
.'
'
.'
본 메일은 {app_name}에서 발송되었습니다.
'
.'
',
'en' => ''
.'
New Order Received
'
.'
Dear {name}, a new order has been received.
'
.'
'
.'
Order Number: {order_number}
'
.'
Customer: {customer_name}
'
.'
Total Amount: {total_amount}
'
.'
'
.'
Please review the order details in the admin panel.
'
.$this->button('Go to Order Management', '{order_url}')
.'
'
.'
This email was sent from {app_name}.
'
.'
',
],
],
[
'channel' => 'database',
'recipients' => [['type' => 'role', 'value' => 'admin', 'exclude_trigger_user' => true]],
'subject' => ['ko' => '새로운 주문이 접수되었습니다', 'en' => 'New order received'],
'body' => ['ko' => '{customer_name}님이 주문번호 {order_number} (결제금액: {total_amount})을 접수했습니다.', 'en' => '{customer_name} placed order {order_number} (total: {total_amount}).'],
'click_url' => '{order_url}',
],
],
];
}
/**
* 상품 문의 접수 관리자 알림 정의.
*
* @return array
*/
private function inquiryReceivedDefinition(): array
{
return [
'type' => 'inquiry_received',
'hook_prefix' => 'sirsoft-ecommerce',
'extension_type' => 'module',
'extension_identifier' => 'sirsoft-ecommerce',
'name' => ['ko' => '상품 문의 접수', 'en' => 'Inquiry Received'],
'description' => ['ko' => '상품 문의 접수 시 관리자에게 발송', 'en' => 'Sent to admin when a product inquiry is received'],
'channels' => ['mail', 'database'],
'hooks' => ['sirsoft-ecommerce.product_inquiry.after_create'],
'variables' => [
['key' => 'name', 'description' => '수신자(관리자) 이름'],
['key' => 'app_name', 'description' => '사이트 이름'],
['key' => 'product_name', 'description' => '상품명'],
['key' => 'customer_name', 'description' => '문의자 이름'],
['key' => 'inquiry_content', 'description' => '문의 내용 (요약)'],
['key' => 'inquiry_url', 'description' => '문의 관리 URL'],
['key' => 'site_url', 'description' => '사이트 URL'],
],
'templates' => [
[
'channel' => 'mail',
'recipients' => [['type' => 'role', 'value' => 'admin', 'exclude_trigger_user' => true]],
'subject' => [
'ko' => '[{app_name}] 새로운 상품 문의가 접수되었습니다',
'en' => '[{app_name}] New product inquiry received',
],
'body' => [
'ko' => ''
.'
새 상품 문의 접수
'
.'
{name}님, 새로운 상품 문의가 접수되었습니다.
'
.'
'
.'
상품명: {product_name}
'
.'
문의자: {customer_name}
'
.'
문의 내용: {inquiry_content}
'
.'
'
.'
관리자 페이지에서 문의 내용을 확인하고 답변해 주세요.
'
.$this->button('문의 확인하기', '{inquiry_url}')
.'
'
.'
본 메일은 {app_name}에서 발송되었습니다.
'
.'
',
'en' => ''
.'
New Product Inquiry
'
.'
Dear {name}, a new product inquiry has been received.
'
.'
'
.'
Product: {product_name}
'
.'
Customer: {customer_name}
'
.'
Inquiry: {inquiry_content}
'
.'
'
.'
Please review the inquiry and provide a response in the admin panel.
'
.$this->button('View Inquiry', '{inquiry_url}')
.'
'
.'
This email was sent from {app_name}.
'
.'
',
],
],
[
'channel' => 'database',
'recipients' => [['type' => 'role', 'value' => 'admin', 'exclude_trigger_user' => true]],
'subject' => ['ko' => '새로운 상품 문의가 접수되었습니다', 'en' => 'New product inquiry received'],
'body' => ['ko' => '{customer_name}님이 "{product_name}" 상품에 문의를 남겼습니다.', 'en' => '{customer_name} left an inquiry on "{product_name}".'],
'click_url' => '{inquiry_url}',
],
],
];
}
/**
* 문의 답변 완료 알림 정의.
*
* @return array
*/
private function inquiryRepliedDefinition(): array
{
return [
'type' => 'inquiry_replied',
'hook_prefix' => 'sirsoft-ecommerce',
'extension_type' => 'module',
'extension_identifier' => 'sirsoft-ecommerce',
'name' => ['ko' => '문의 답변 완료', 'en' => 'Inquiry Replied'],
'description' => ['ko' => '문의 답변 시 고객에게 발송', 'en' => 'Sent to customer when inquiry is replied'],
'channels' => ['mail', 'database'],
'hooks' => ['sirsoft-ecommerce.product_inquiry.after_reply'],
'variables' => [
['key' => 'name', 'description' => '수신자(문의자) 이름'],
['key' => 'app_name', 'description' => '사이트 이름'],
['key' => 'product_name', 'description' => '상품명'],
['key' => 'inquiry_content', 'description' => '원래 문의 내용 (요약)'],
['key' => 'inquiry_url', 'description' => '문의 상세 URL (마이페이지)'],
['key' => 'site_url', 'description' => '사이트 URL'],
],
'templates' => [
[
'channel' => 'mail',
'recipients' => [['type' => 'related_user', 'relation' => 'author']],
'subject' => [
'ko' => '[{app_name}] 상품 문의에 답변이 등록되었습니다',
'en' => '[{app_name}] Your product inquiry has been answered',
],
'body' => [
'ko' => ''
.'
문의 답변 안내
'
.'
{name}님, 문의하신 내용에 답변이 등록되었습니다.
'
.'
'
.'
상품명: {product_name}
'
.'
문의 내용: {inquiry_content}
'
.'
'
.'
아래 버튼을 클릭하여 답변 내용을 확인하세요.
'
.$this->button('답변 확인하기', '{inquiry_url}')
.'
'
.'
본 메일은 {app_name}에서 발송되었습니다.
'
.'
',
'en' => ''
.'
Inquiry Answered
'
.'
Dear {name}, your product inquiry has been answered.
'
.'
'
.'
Product: {product_name}
'
.'
Your Inquiry: {inquiry_content}
'
.'
'
.'
Click the button below to view the response.
'
.$this->button('View Response', '{inquiry_url}')
.'
'
.'
This email was sent from {app_name}.
'
.'
',
],
],
[
'channel' => 'database',
'recipients' => [['type' => 'related_user', 'relation' => 'author']],
'subject' => ['ko' => '문의 답변이 등록되었습니다', 'en' => 'Your inquiry has been answered'],
'body' => ['ko' => '{name}님, "{product_name}" 상품 문의에 답변이 등록되었습니다.', 'en' => '{name}, your inquiry on "{product_name}" has been answered.'],
'click_url' => '{inquiry_url}',
],
],
];
}
/**
* 이메일용 CTA 버튼 HTML을 반환합니다.
*
* @param string $text 버튼 텍스트
* @param string $url 버튼 링크
* @return string 인라인 스타일 버튼 HTML
*/
private function button(string $text, string $url): string
{
return '';
}
}