Updates to 03-2025

This commit is contained in:
Kevin Adametz 2025-04-01 10:39:21 +02:00
parent 6167273a48
commit 9b54eb0512
348 changed files with 34535 additions and 5774 deletions

View file

@ -72,7 +72,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereUsage($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Product withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\Product withoutTrashed()
* @mixin \Eloquent
* @property string|null $slug
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product findSimilarSlugs($attribute, $config, $slug)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereSlug($value)
@ -130,6 +129,17 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property array|null $show_on
* @method static \Illuminate\Database\Eloquent\Builder|Product whereShortCopy($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product whereShowOn($value)
* @property bool $exclude_stats_sales
* @property bool|null $whitelabel
* @property string|null $whitelabel_name
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductAttribute> $attribute_variants
* @property-read int|null $attribute_variants_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductImage> $whitelabel_images
* @property-read int|null $whitelabel_images_count
* @method static \Illuminate\Database\Eloquent\Builder|Product whereExcludeStatsSales($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product whereWhitelabel($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product whereWhitelabelName($value)
* @mixin \Eloquent
*/
class Product extends Model
{
@ -155,10 +165,12 @@ class Product extends Model
'wp_number' => 'int',
'single_commission' => 'bool',
'amount_commission' => 'bool',
'exclude_stats_sales' => 'bool',
'active' => 'bool',
'shipping_addon' => 'bool',
'max_buy' => 'bool',
'max_buy_num' => 'int'
'max_buy_num' => 'int',
'whitelabel' => 'bool',
];
use Sluggable;
@ -168,6 +180,8 @@ class Product extends Model
protected $fillable = [
'name',
'whitelabel',
'whitelabel_name',
'title',
'copy',
'short_copy',
@ -195,12 +209,14 @@ class Product extends Model
'amount_commission',
'value_commission',
'partner_commission',
'exclude_stats_sales',
'identifier',
'action',
'upgrade_to_id',
'shipping_addon',
'max_buy',
'max_buy_num'
];
public $identifiers_types = [
@ -219,9 +235,6 @@ class Product extends Model
4 => 'KG',
];
public $actions = [
0 => 'payment_for_account',
1 => 'charging_credits',
@ -231,7 +244,7 @@ class Product extends Model
];
public function sluggable()
public function sluggable(): array
{
return [
'slug' => [
@ -241,19 +254,28 @@ class Product extends Model
}
public function attributes(){
return $this->hasMany('App\Models\ProductAttribute', 'product_id', 'id');
return $this->hasMany(ProductAttribute::class, 'product_id', 'id')->where('type_id','!=', 1);
}
public function attribute_variants(){
return $this->hasMany(ProductAttribute::class, 'product_id', 'id')->where('type_id','=', 1);
}
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');
return $this->hasMany(ProductImage::class, 'product_id', 'id')->where('type','=', 'product')->orderBy('pos');
}
public function imagesActive(){
return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->where('active', true)->orderBy('pos');
return $this->hasMany(ProductImage::class, 'product_id', 'id')->where('type','=', 'product')->where('active', true)->orderBy('pos');
}
public function whitelabel_images(){
return $this->hasMany(ProductImage::class, 'product_id', 'id')->where('type','=', 'wllogo')->orderBy('pos');
}
public function country_prices()
@ -291,6 +313,11 @@ class Product extends Model
}
return false;
}
public function getWhiteLableName($id = 0){
return $this->whitelabel_name ? $this->whitelabel_name : $this->name;
}
public function _format_number($value){
return preg_replace("/[^0-9,]/", "", $value);
}
@ -330,9 +357,9 @@ class Product extends Model
return isset($this->attributes['price_ek']) ? Util::formatNumber($this->attributes['price_ek']) : "";
}
public function getFormattedTax()
public function getFormattedTax($country = null)
{
return isset($this->attributes['tax']) ? Util::formatNumber($this->attributes['tax'], 0) : "";
return isset($this->attributes['tax']) ? Util::formatNumber($this->getTaxWith($country), 0) : "";
}
public function getFormattedPriceOld()
@ -362,24 +389,38 @@ class Product extends Model
return $price;
}
/*price net*/
private function calcPriceNet($price){
$tax_rate = ($this->attributes['tax'] + 100) / 100;
private function calcPriceNet($price, $country=null){
$tax = $this->getTaxWith($country);
$tax_rate = ($tax + 100) / 100;
return $price / $tax_rate;
}
//price calu with
public function getPriceWith(Bool $net = true, Bool $ufactor = true){
$price = $this->attributes['price'];
$price = $net ? $this->calcPriceNet($price) : $price;
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; //eigener Preis für Land
$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)
{
return isset($this->attributes['price']) ? Util::formatNumber($this->getPriceWith($net, $ufactor)) : "";
}
public function getTaxWith($country = null){
$tax = isset($this->attributes['tax']) ? $this->attributes['tax'] : null;
$ctax = $country ? $this->getCTax($country) : null;
return $ctax !== null ? $ctax : $tax;
}
public function getBasePriceFormattedFull(){
if($price = $this->getBasePrice()){
@ -424,14 +465,14 @@ class Product extends Model
return isset(Type::$showATs[$this->show_at]) ? Type::$showATs[$this->show_at] : '-';
}
public function getShowOnTypes(){
public function getShowOnTypes($seperator = false){
$ret = [];
if($this->show_on && is_array($this->show_on)){
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
}
}
return $ret;
return $seperator ? implode($seperator, $ret) : $ret;
}
@ -493,5 +534,15 @@ class Product extends Model
return $this->price;
}
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, $commission);
$ret = formatNumber($price * $country->currency_faktor)." ".$country->currency_unit;
return '<br><span class="small">~'.$ret.'<span>';
}
return "" ;
}
}