'offen', 1 => 'versendet', 2 => 'abgeschlossen', 4 => 'In Bearbeitung', 50 => 'storiniert' ]; public static $shippedColors = [ 0 => 'warning', 1 => 'success', 2 => 'success', 4 => 'info', 50 => 'danger', ]; public function shopping_user() { return $this->belongsTo('App\Models\ShoppingUser','shopping_user_id'); } public function country() { return $this->belongsTo('App\Models\ShippingCountry','country_id'); } public function shipping_country() { return $this->belongsTo('App\Models\ShippingCountry','country_id'); } public function homeparty() { return $this->belongsTo('App\Models\Homeparty','homeparty_id'); } public function user_shop() { return $this->belongsTo('App\Models\UserShop','user_shop_id'); } //can null public function member() { return $this->belongsTo('App\User','member_id'); } //can null public function auth_user() { return $this->belongsTo('App\User','auth_user_id'); } public function user_history() { return $this->hasOne('App\Models\UserHistory','shopping_order_id')->latest(); } public function shopping_order_items(){ return $this->hasMany('App\Models\ShoppingOrderItem', 'shopping_order_id'); } public function shopping_payments(){ return $this->hasMany('App\Models\ShoppingPayment', 'shopping_order_id'); } public function setUserHistoryValue($values = []){ if($user_history = $this->user_history){ foreach ($values as $key=>$val){ $user_history->{$key} = $val; } $user_history->save(); } } public function getLastShoppingPayment($key=false){ $shopping_payment = $this->shopping_payments->last(); if($shopping_payment){ if($key === 'getPaymentType'){ return $shopping_payment->getPaymentType(); } if($key === 'reference'){ return $shopping_payment->reference; } } return ""; } public function getShippedType(){ return isset(self::$shippedTypes[$this->shipped]) ? self::$shippedTypes[$this->shipped] : ""; } public function getShippedColor(){ return isset(self::$shippedColors[$this->shipped]) ? self::$shippedColors[$this->shipped] : "default"; } public function getFormattedTotal() { return formatNumber($this->attributes['total']); } public function getFormattedSubtotal() { return formatNumber($this->attributes['subtotal']); } public function getFormattedShipping() { return formatNumber($this->attributes['shipping']); } public function getFormattedShippingNet() { return formatNumber($this->attributes['shipping_net']); } public function getFormattedSubtotalWs() { return formatNumber($this->attributes['subtotal_ws']); } public function getFormattedTax() { return formatNumber($this->attributes['tax']); } public function getFormattedTotalShipping() { return formatNumber($this->attributes['total_shipping']); } public function getItemsCount(){ $count = 0; if($this->shopping_order_items){ foreach ($this->shopping_order_items as $shopping_order_item){ $count += $shopping_order_item->qty; } } return $count; } }