register, Grundpreis

This commit is contained in:
Kevin Adametz 2020-04-01 15:35:11 +02:00
parent f06d2d15a5
commit 8e4bb0c2f6
32 changed files with 965 additions and 216 deletions

View file

@ -2,6 +2,7 @@
namespace App\Models;
use App\Services\Util;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@ -104,11 +105,6 @@ class Product extends Model
upgrade # need upgrade_to_id set user->payment_order_id to the package in the payment api
*/
protected $identifiers_types = [
'show_upgrade' => 'Kann gepdatet werden',
'show_order' => 'Wird immer als Option angezeigt',
'upgrade' => 'Produktupgrade zu upgrade_to_id',
];
protected $table = 'products';
protected $casts = [
@ -138,6 +134,8 @@ class Product extends Model
'points',
'weight',
'contents',
'contents_total',
'unit',
'number',
'icons',
'description',
@ -152,12 +150,28 @@ class Product extends Model
'upgrade_to_id'
];
public $identifiers_types = [
'' => '-',
'show_upgrade' => 'Kann gepdatet werden',
'show_order' => 'Wird immer als Option angezeigt',
'upgrade' => 'Produktupgrade zur Upgrade to ID',
];
public $unitTypes = [
0 => '',
1 => 'ml',
2 => 'g',
3 => 'Liter',
4 => 'KG',
];
public $showATs = [
0 => 'nur User Shop',
1 => 'User + Berater Shop',
2 => 'nur Berater Shop',
3 => 'Registrierung Shop',
4 => 'Mitgliedschaft Berater',
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 = [
@ -221,50 +235,63 @@ class Product extends Model
public function getFormattedPrice()
{
if(!isset($this->attributes['price'])){
return "";
}
if(\App::getLocale() == "en"){
return number_format($this->attributes['price'], 2, '.', ',');
}
return number_format($this->attributes['price'], 2, ',', '.');
return isset($this->attributes['price']) ? Util::formatNumber($this->attributes['price']) : "";
}
public function getFormattedPriceEk()
{
if(!isset($this->attributes['price_ek'])){
return "";
}
if(\App::getLocale() == "en"){
return number_format($this->attributes['price_ek'], 2, '.', ',');
}
return number_format($this->attributes['price_ek'], 2, ',', '.');
return isset($this->attributes['price_ek']) ? Util::formatNumber($this->attributes['price_ek']) : "";
}
public function getFormattedTax()
{
if(!isset($this->attributes['tax'])){
return "";
}
if(\App::getLocale() == "en"){
return number_format($this->attributes['tax'], 2, '.', ',');
}
return number_format($this->attributes['tax'], 2, ',', '.');
return isset($this->attributes['tax']) ? Util::formatNumber($this->attributes['tax']) : "";
}
public function getFormattedPriceOld()
{
if(!isset($this->attributes['price_old'])){
return "";
}
if(\App::getLocale() == "en"){
return number_format($this->attributes['price_old'], 2, '.', ',');
}
return number_format($this->attributes['price_old'], 2, ',', '.');
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;