belongsTo('App\Models\ShoppingUser','shopping_user_id'); } public function country() { return $this->belongsTo('App\Models\Sh','country_id'); } public function shipping_country() { return $this->belongsTo('App\Models\ShippingCountry','country_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 _format_number($value) { return preg_replace("/[^0-9,]/", "", $value); } public function getFormattedShipping() { if (\App::getLocale() === "en") { return number_format($this->attributes['shipping'], 2, '.', ','); } return number_format($this->attributes['shipping'], 2, ',', '.'); } public function getFormattedTotalShipping() { if (\App::getLocale() === "en") { return number_format($this->attributes['total_shipping'], 2, '.', ','); } return number_format($this->attributes['total_shipping'], 2, ',', '.'); } public function getFormattedPrice() { if (\App::getLocale() === "en") { return number_format($this->attributes['price'], 2, '.', ','); } return number_format($this->attributes['price'], 2, ',', '.'); } 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; } }