payment_order_id to the package in the payment api */ protected $table = 'products'; protected $casts = [ 'trans_name' => 'array', 'trans_title' => 'array', 'trans_copy' => 'array', 'icons' => 'array', 'trans_description' => 'array', 'trans_usage' => 'array', 'trans_ingredients' => 'array', 'action' => 'array' ]; use Sluggable; use SoftDeletes; protected $dates = ['deleted_at']; protected $fillable = [ 'name', 'title', 'copy', 'price', 'price_ek', 'tax', 'price_old', 'points', 'weight', 'contents', 'contents_total', 'unit', 'number', 'icons', 'description', 'usage', 'ingredients', 'pos', 'amount', 'active', 'show_at', 'identifier', 'action', 'upgrade_to_id' ]; public $identifiers_types = [ '' => '-', 'show_upgrade' => 'Kann gepdatet werden', 'show_order' => 'Wird immer als Option angezeigt', 'upgrade' => 'Produktupgrade zur Produkt ID', 'upgrade_member' => 'Beraterupgrade zur Karriere ID', ]; public $unitTypes = [ 0 => '', 1 => 'ml', 2 => 'g', 3 => 'Liter', 4 => 'KG', ]; public $showATs = [ 0 => 'Nur Kunden Shop', 1 => 'Kunden + Berater Shop', 2 => 'Nur Berater Shop', 3 => 'Registrierung / Mitgliedschaft Berater', 4 => 'Nur Mitgliedschaft Berater', 5 => 'Onboarding Berater', ]; public $actions = [ 0 => 'payment_for_account', 1 => 'payment_for_shop', 2 => 'payment_for_shop_upgrade', 4 => 'payment_for_lead_upgrade', ]; public function sluggable() { return [ 'slug' => [ 'source' => 'name' ] ]; } public function attributes(){ return $this->hasMany('App\Models\ProductAttribute', 'product_id', 'id'); } public function categories(){ return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id'); } public function images(){ return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->orderBy('pos'); } public function imagesActive(){ return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->where('active', true)->orderBy('pos'); } public function getActionName($id = 0){ if(isset($this->actions[$id])){ return $this->actions[$id]; } return false; } public function _format_number($value){ return preg_replace("/[^0-9,]/", "", $value); } public function setPriceAttribute( $value ) { $value = $this->_format_number($value); $this->attributes['price'] = floatval(str_replace(',', '.', $value)); } public function setPriceEkAttribute( $value ) { $value = $this->_format_number($value); $this->attributes['price_ek'] = floatval(str_replace(',', '.', $value)); } public function setTaxAttribute( $value ) { $value = $this->_format_number($value); $this->attributes['tax'] = floatval(str_replace(',', '.', $value)); } public function setPriceOldAttribute( $value ) { $value = $this->_format_number($value); $this->attributes['price_old'] = floatval(str_replace(',', '.', $value)); } public function getFormattedPrice() { return isset($this->attributes['price']) ? Util::formatNumber($this->attributes['price']) : ""; } public function getFormattedPriceEk() { return isset($this->attributes['price_ek']) ? Util::formatNumber($this->attributes['price_ek']) : ""; } public function getFormattedTax() { return isset($this->attributes['tax']) ? Util::formatNumber($this->attributes['tax']) : ""; } public function getFormattedPriceOld() { return isset($this->attributes['price_old']) ? Util::formatNumber($this->attributes['price_old']) : ""; } public function getBasePriceFormattedFull(){ if($price = $this->getBasePrice()){ $unit = $this->attributes['unit']; //ml g if($unit === 1 || $unit === 2){ return Util::formatNumber($price) . ' € / 100 '.$this->getUnitType(); } //l kg if($unit === 3 || $unit === 4){ return Util::formatNumber($price) . ' € / 1 '.$this->getUnitType(); } } return ""; } public function getBasePriceFormatted(){ if($price = $this->getBasePrice()){ return Util::formatNumber($price); } return ""; } public function getBasePrice(){ if(isset($this->attributes['unit']) && isset($this->attributes['contents_total']) && $this->attributes['contents_total'] != 0){ $unit = $this->attributes['unit']; //ml g if($unit === 1 || $unit === 2){ return $this->attributes['price'] * 100 / $this->attributes['contents_total']; } //l kg if($unit === 3 || $unit === 4){ return $this->attributes['price'] * 1000 / $this->attributes['contents_total']; } } return ""; } public function getUnitType(){ return isset($this->unitTypes[$this->unit]) ? $this->unitTypes[$this->unit] : '-'; } public function setPosAttribute($value){ $this->attributes['pos'] = is_numeric($value) ? $value : null; } public function getLang($key) { $lang = \App::getLocale(); if ($lang == 'de') { return $this->{$key}; } $trans = $this->getTrans($key, $lang); if (!$trans || $trans == '') { return $this->{$key}; } return $trans; } public function getTrans($key, $lang) { $key = 'trans_' . $key; if (!empty($this->{$key}[$lang])) { return $this->{$key}[$lang]; } } public function getTranNames() { $ret = ""; foreach ((array) $this->trans_name as $value){ $ret .= $value.', '; } return rtrim($ret, ', '); } }