'array', 'is_like' => 'bool', 'faker_mail' => 'bool', 'accepted_data_checkbox' => 'bool', 'same_as_billing' => 'bool', 'has_buyed' => 'bool', 'subscribed' => 'bool', 'wp_order_number' => 'int', ]; // can null public function member() { return $this->belongsTo('App\User', 'member_id'); } public function auth_user() { return $this->belongsTo('App\User', 'auth_user_id'); } public function billing_country() { return $this->belongsTo('App\Models\Country', 'billing_country_id'); } public function shipping_country() { return $this->belongsTo('App\Models\Country', 'shipping_country_id'); } public function shopping_orders() { return $this->hasMany('App\Models\ShoppingOrder', 'shopping_user_id'); } public function shopping_order() { return $this->hasOne('App\Models\ShoppingOrder', 'shopping_user_id'); } /** * Accessor für das language Attribut. * Gibt die App-Locale zurück, wenn keine Sprache gesetzt ist. * * @param string|null $value * @return string Sprachcode (de, en, es) */ public function getLanguageAttribute($value): string { return $value ?: \App::getLocale(); } /** * Alias für getLanguageAttribute - für Konsistenz mit anderen Models. * * @return string Sprachcode (de, en, es) */ public function getLocale(): string { return $this->language; } /** * Liefert die verfügbaren Sprachen aus der Config als Array für Select-Felder. * * @return array ['code' => 'Native Name', ...] */ public static function getAvailableLanguages(): array { $locales = config('localization.supportedLocales', []); $languages = []; foreach ($locales as $code => $locale) { $languages[$code] = $locale['native'] ?? $locale['name'] ?? $code; } return $languages; } public function setNotice($key, $value) { $notice = $this->notice; $notice[$key] = $value; $this->notice = $notice; $this->save(); } public function getNotice($key) { return isset($this->notice[$key]) ? $this->notice[$key] : false; } public function removeNotice($key) { $notice = $this->notice; if (isset($notice[$key])) { unset($notice[$key]); } $this->notice = $notice; $this->save(); } public function firstEntryByNumber() { if ($this->number > 0) { if ($shopping_user = ShoppingUser::where('number', $this->number)->orderBy('created_at', 'ASC')->first()) { return $shopping_user; } } return $this; } public function lastEntryByNumber() { if ($this->number > 0) { if ($shopping_user = ShoppingUser::where('number', $this->number)->orderBy('created_at', 'DESC')->first()) { return $shopping_user; } } return $this; } public function getOrderPaymentFor() { switch ($this->is_from) { case 'wizard': return 1; case 'membership': return 2; case 'user_order': return ($this->is_for === 'me' || $this->is_for === 'abo_me') ? 3 : 4; case 'homeparty': return 5; case 'shopping': return 6; case 'extern': return 7; case 'collection': return 8; } return 0; } public function setIsForAttribute($value) { if ($value === 'abo-me' || $value === 'me') { $this->attributes['is_for'] = 'me'; return; } if ($value === 'ot-member' || $value === 'ot-customer' || $value === 'abo-ot-member' || $value === 'abo-ot-customer') { $this->attributes['is_for'] = 'ot'; return; } $this->attributes['is_for'] = $value; } public function getAPIShippedType() { if ($this->shopping_order) { return $this->shopping_order->getAPIShippedType(); } return 'free'; } public function getFullNameAsArray() { return [ 'company' => $this->billing_company, 'salutation' => $this->billing_salutation, 'firstname' => $this->billing_firstname, 'lastname' => $this->billing_lastname, 'email' => $this->billing_email, ]; } public function getAllOrdersByMember() { return ShoppingUserService::getAllOrdersByMember($this); } public function getDeliveryCountry($get_country = false) { if ($this->same_as_billing == 1) { if ($this->billing_country_id) { if ($get_country) { return $this->billing_country; } return $this->billing_country->getLocated(); } } else { if ($this->shipping_country_id) { if ($get_country) { return $this->shipping_country; } return $this->shipping_country->getLocated(); } } return 'not set'; } /** * Prüft ob es sich um eine Packstation/Paketbox-Lieferung handelt */ public function isPackstationDelivery(): bool { return ! empty($this->shipping_postnumber); } /** * Liefert die effektive Lieferadresse (berücksichtigt same_as_billing) */ public function getEffectiveShippingAddress(): array { if ($this->same_as_billing) { return [ 'salutation' => $this->billing_salutation, 'company' => $this->billing_company, 'firstname' => $this->billing_firstname, 'lastname' => $this->billing_lastname, 'address' => $this->billing_address, 'address_2' => $this->billing_address_2, 'zipcode' => $this->billing_zipcode, 'city' => $this->billing_city, 'country_id' => $this->billing_country_id, 'phone' => $this->billing_phone, 'postnumber' => null, // Bei same_as_billing keine Packstation ]; } return [ 'salutation' => $this->shipping_salutation, 'company' => $this->shipping_company, 'firstname' => $this->shipping_firstname, 'lastname' => $this->shipping_lastname, 'address' => $this->shipping_address, 'address_2' => $this->shipping_address_2, 'zipcode' => $this->shipping_zipcode, 'city' => $this->shipping_city, 'country_id' => $this->shipping_country_id, 'phone' => $this->shipping_phone, 'postnumber' => $this->shipping_postnumber, ]; } }