'integer', 'name' => 'array', 'price_adjustment' => 'integer', 'mc_price_adjustment' => 'array', 'is_default' => 'boolean', 'is_active' => 'boolean', 'allow_custom_text' => 'boolean', 'sort_order' => 'integer', ]; /** * 추가옵션 그룹 관계 * * @return BelongsTo 추가옵션 그룹 모델과의 관계 */ public function additionalOption(): BelongsTo { return $this->belongsTo(ProductAdditionalOption::class, 'additional_option_id'); } /** * 현재 로케일의 선택지명 반환 * * @param string|null $locale 로케일 (null이면 현재 로케일) * @return string 로컬라이즈된 선택지명 */ public function getLocalizedName(?string $locale = null): string { $locale = $locale ?? app()->getLocale(); $name = $this->name; if (! is_array($name)) { return is_string($name) ? $name : ''; } return $name[$locale] ?? $name[config('app.fallback_locale', 'ko')] ?? $name[array_key_first($name)] ?? ''; } /** * 추가금 반환 (기본 통화 기준) * * 저장값은 쇼핑몰 기본 통화(`language_currency.default_currency`) 기준이다 — KRW 로 * 고정된 값이 아니다. 표시통화가 기본통화와 다르면 그대로 쓰면 안 되고, 리소스의 * `buildMultiCurrencyPriceAdjustments()` 로 환산한 값을 화면에 내보낸다. * * @return int 기본 통화 기준 추가금 */ public function getPriceAdjustment(): int { return (int) ($this->price_adjustment ?? 0); } /** * 주문 스냅샷용 배열 반환 * * 주문 생성 시점의 선택지 정보를 동결하기 위한 데이터입니다. * * @return array 스냅샷 데이터 */ public function toSnapshotArray(): array { return [ 'additional_option_id' => (int) $this->additional_option_id, 'value_id' => (int) $this->id, 'name' => $this->name, 'price_adjustment' => $this->getPriceAdjustment(), 'mc_price_adjustment' => $this->mc_price_adjustment, ]; } }