08 2024
This commit is contained in:
parent
04d677d37a
commit
bfa3bb1df4
1191 changed files with 637397 additions and 10619 deletions
|
|
@ -125,6 +125,16 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductBuying> $product_buyings
|
||||
* @property-read int|null $product_buyings_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductBuying> $product_buyings
|
||||
* @property bool|null $sponsor_buying_points
|
||||
* @property int|null $sponsor_buying_points_amount
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductBuying> $product_buyings
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereSponsorBuyingPoints($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereSponsorBuyingPointsAmount($value)
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductBuying> $product_buyings
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\TransProduct> $translations
|
||||
* @property-read int|null $translations_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductCategory> $product_categories
|
||||
* @property-read int|null $product_categories_count
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Product extends Model
|
||||
|
|
@ -215,8 +225,8 @@ class Product extends Model
|
|||
0 => '',
|
||||
1 => 'ml',
|
||||
2 => 'g',
|
||||
3 => 'Liter',
|
||||
4 => 'KG',
|
||||
3 => 'liter',
|
||||
4 => 'kg',
|
||||
];
|
||||
|
||||
public $showATs = [
|
||||
|
|
@ -239,6 +249,9 @@ class Product extends Model
|
|||
8 => 'Mitgliedschaft Berater',
|
||||
9 => 'Onboarding Berater',
|
||||
10 => 'zur internen Berechnung',
|
||||
12 => 'Abo-ShopBerater',
|
||||
13 => 'Abo-ShopBeraterKunden',
|
||||
|
||||
];
|
||||
|
||||
public $actions = [
|
||||
|
|
@ -278,6 +291,10 @@ class Product extends Model
|
|||
return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id')->orderBy('pos', 'DESC');
|
||||
}
|
||||
|
||||
public function product_categories(){
|
||||
return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id')->orderBy('pos', 'DESC');
|
||||
}
|
||||
|
||||
public function images(){
|
||||
return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->orderBy('pos');
|
||||
}
|
||||
|
|
@ -302,6 +319,10 @@ class Product extends Model
|
|||
return $this->hasMany(CountryPrice::class, 'product_id');
|
||||
}
|
||||
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(TransProduct::class, 'product_id');
|
||||
}
|
||||
|
||||
public function p_ingredients()
|
||||
{
|
||||
|
|
@ -382,6 +403,19 @@ class Product extends Model
|
|||
}
|
||||
return $price;
|
||||
}
|
||||
|
||||
private function calcPriceUserCommission($price){
|
||||
if($this->no_commission){
|
||||
return $price;
|
||||
}
|
||||
if(\Auth::user() && \Auth::user()->user_level){
|
||||
$margin = \Auth::user()->user_level->margin;
|
||||
$price = $price / 100 * $margin;
|
||||
}
|
||||
return $price;
|
||||
}
|
||||
|
||||
|
||||
/*price net*/
|
||||
private function calcPriceNet($price, $country=null){
|
||||
$tax = $this->getTaxWith($country);
|
||||
|
|
@ -389,18 +423,21 @@ class Product extends Model
|
|||
return $price / $tax_rate;
|
||||
}
|
||||
//price calu with
|
||||
public function getPriceWith(Bool $net = true, Bool $ufactor = true, $country = null){
|
||||
public function getPriceWith(Bool $net = true, Bool $ufactor = true, $country = null, $commission=false){
|
||||
$price = isset($this->attributes['price']) ? $this->attributes['price'] : null;
|
||||
$cprice = $country ? $this->getCPrice($country) : null;
|
||||
$price = $cprice ? $cprice : $price;
|
||||
$price = $net ? $this->calcPriceNet($price, $country) : $price;
|
||||
$price = $ufactor ? $this->calcPriceUserFactor($price) : $price;
|
||||
$price = $commission ? $this->calcPriceUserCommission($price) : $price;
|
||||
|
||||
return round($price, 2);
|
||||
}
|
||||
|
||||
/*out*/
|
||||
public function getFormattedPriceWith(Bool $net = true, Bool $ufactor = true, $country = null)
|
||||
public function getFormattedPriceWith(Bool $net = true, Bool $ufactor = true, $country = null, $commission=false)
|
||||
{
|
||||
return isset($this->attributes['price']) ? Util::formatNumber($this->getPriceWith($net, $ufactor, $country)) : "";
|
||||
return isset($this->attributes['price']) ? Util::formatNumber($this->getPriceWith($net, $ufactor, $country, $commission)) : "";
|
||||
}
|
||||
|
||||
public function getTaxWith($country = null){
|
||||
|
|
@ -496,7 +533,7 @@ class Product extends Model
|
|||
|
||||
|
||||
public function getUnitType(){
|
||||
return isset($this->unitTypes[$this->unit]) ? $this->unitTypes[$this->unit] : '-';
|
||||
return isset($this->unitTypes[$this->unit]) ? __($this->unitTypes[$this->unit]) : '-';
|
||||
}
|
||||
public function getShowAtType(){
|
||||
return isset($this->showATs[$this->show_at]) ? $this->showATs[$this->show_at] : '-';
|
||||
|
|
@ -523,18 +560,13 @@ class Product extends Model
|
|||
return $this->{$key};
|
||||
}
|
||||
$trans = $this->getTrans($key, $lang);
|
||||
if (!$trans || $trans == '') {
|
||||
return $this->{$key};
|
||||
}
|
||||
return $trans;
|
||||
return $trans != '' ? $trans : $this->{$key};
|
||||
}
|
||||
|
||||
public function getTrans($key, $lang)
|
||||
{
|
||||
$key = 'trans_' . $key;
|
||||
if (!empty($this->{$key}[$lang])) {
|
||||
return $this->{$key}[$lang];
|
||||
}
|
||||
$trans = $this->translations->where('language','=', $lang)->where('key', $key)->first();
|
||||
return $trans ? $trans->value : '';
|
||||
}
|
||||
|
||||
public function getTranNames()
|
||||
|
|
@ -573,10 +605,10 @@ class Product extends Model
|
|||
return $this->price;
|
||||
}
|
||||
|
||||
public function getFormattedPriceCurrencyWith(Bool $net = true, Bool $ufactor = true, Country $country = null){
|
||||
public function getFormattedPriceCurrencyWith(Bool $net = true, Bool $ufactor = true, Country $country = null, $commission = false){
|
||||
$ret = "";
|
||||
if($country && isset($country->currency) && $country->currency){
|
||||
$price = $this->getPriceWith($net, $ufactor, $country);
|
||||
$price = $this->getPriceWith($net, $ufactor, $country, $commission);
|
||||
$ret = formatNumber($price * $country->currency_faktor)." ".$country->currency_unit;
|
||||
return '<br><span class="small">~'.$ret.'<span>';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue