23-01-2026
This commit is contained in:
parent
a939cd51ef
commit
a8b395e20d
248 changed files with 29342 additions and 4805 deletions
|
|
@ -40,6 +40,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductCategory[] $categories
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductImage[] $images
|
||||
* @property-write mixed $price_vk
|
||||
*
|
||||
* @method static bool|null forceDelete()
|
||||
* @method static \Illuminate\Database\Query\Builder|\App\Models\Product onlyTrashed()
|
||||
* @method static bool|null restore()
|
||||
|
|
@ -71,39 +72,56 @@ 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()
|
||||
*
|
||||
* @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)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product query()
|
||||
*
|
||||
* @property int|null $weight
|
||||
* @property int|null $show_at
|
||||
* @property array|null $action
|
||||
* @property-read int|null $attributes_count
|
||||
* @property-read int|null $categories_count
|
||||
* @property-read int|null $images_count
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereAction($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereShowAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereWeight($value)
|
||||
*
|
||||
* @property int|null $points
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductImage[] $imagesActive
|
||||
* @property-read int|null $images_active_count
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product wherePoints($value)
|
||||
*
|
||||
* @property string|null $identifier
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereIdentifier($value)
|
||||
*
|
||||
* @property int|null $upgrade_to_id
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereUpgradeToId($value)
|
||||
*
|
||||
* @property int|null $contents_total
|
||||
* @property int|null $unit
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereContentsTotal($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereUnit($value)
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\CountryPrice[] $country_prices
|
||||
* @property-read int|null $country_prices_count
|
||||
* @property int|null $wp_number
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereWpNumber($value)
|
||||
*
|
||||
* @property bool|null $shipping_addon
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereShippingAddon($value)
|
||||
*
|
||||
* @property-read int|null $ingredients_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductIngredient[] $product_ingredients
|
||||
* @property-read int|null $product_ingredients_count
|
||||
|
|
@ -111,35 +129,43 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @property array|null $show_on
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Ingredient[] $p_ingredients
|
||||
* @property-read int|null $p_ingredients_count
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereNoCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereShowOn($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
|
||||
*
|
||||
* @property string|null $ean
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereEan($value)
|
||||
*
|
||||
* @property bool|null $no_free_shipping
|
||||
* @property bool|null $buying_restriction
|
||||
* @property int|null $buying_restriction_amount
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereBuyingRestriction($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereBuyingRestrictionAmount($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereNoFreeShipping($value)
|
||||
*
|
||||
* @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
|
||||
{
|
||||
|
||||
/*identifiers
|
||||
show_upgrade # in membership payment can upgrade this package to show order
|
||||
show_order # in membership payment show always
|
||||
|
|
@ -167,11 +193,9 @@ class Product extends Model
|
|||
'buying_restriction_amount' => 'int',
|
||||
'sponsor_buying_points' => 'bool',
|
||||
'sponsor_buying_points_amount' => 'int',
|
||||
|
||||
|
||||
];
|
||||
use Sluggable;
|
||||
|
||||
use Sluggable;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
|
@ -210,7 +234,7 @@ class Product extends Model
|
|||
'sponsor_buying_points_amount',
|
||||
'identifier',
|
||||
'action',
|
||||
'upgrade_to_id'
|
||||
'upgrade_to_id',
|
||||
];
|
||||
|
||||
public $identifiers_types = [
|
||||
|
|
@ -221,6 +245,7 @@ class Product extends Model
|
|||
'upgrade_member' => 'Berater upgrade zur Karriere ID',
|
||||
'proportional_voucher' => 'Anteiliger Gutschein Berater',
|
||||
];
|
||||
|
||||
public $unitTypes = [
|
||||
0 => '',
|
||||
1 => 'ml',
|
||||
|
|
@ -269,7 +294,7 @@ class Product extends Model
|
|||
|
||||
];
|
||||
|
||||
/************* ✨ Codeium Command ⭐ *************/
|
||||
/************* ✨ Codeium Command ⭐ *************/
|
||||
/**
|
||||
* Configure the model for auto-generating a slug.
|
||||
*
|
||||
|
|
@ -280,48 +305,58 @@ class Product extends Model
|
|||
* @return array Configuration for slug generation.
|
||||
*/
|
||||
|
||||
/****** e935bd41-f49b-4736-9603-2da86dc27f25 *******/ public function sluggable() : array
|
||||
/****** e935bd41-f49b-4736-9603-2da86dc27f25 *******/
|
||||
public function sluggable(): array
|
||||
{
|
||||
return [
|
||||
'slug' => [
|
||||
'source' => 'name'
|
||||
]
|
||||
'source' => 'name',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function product_buyings(){
|
||||
public function product_buyings()
|
||||
{
|
||||
return $this->hasMany('App\Models\ProductBuying', 'product_id', 'id');
|
||||
}
|
||||
|
||||
public function attributes(){
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return $this->hasMany('App\Models\ProductAttribute', 'product_id', 'id');
|
||||
}
|
||||
|
||||
public function categories(){
|
||||
public function categories()
|
||||
{
|
||||
return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id')->orderBy('pos', 'DESC');
|
||||
}
|
||||
|
||||
public function product_categories(){
|
||||
public function product_categories()
|
||||
{
|
||||
return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id')->orderBy('pos', 'DESC');
|
||||
}
|
||||
|
||||
public function images(){
|
||||
public function images()
|
||||
{
|
||||
return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->orderBy('pos');
|
||||
}
|
||||
|
||||
public function imagesActive(){
|
||||
public function imagesActive()
|
||||
{
|
||||
return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->where('active', true)->orderBy('pos');
|
||||
}
|
||||
|
||||
public function getImageUrl(){
|
||||
if(count($this->imagesActive)){
|
||||
public function getImageUrl()
|
||||
{
|
||||
if (count($this->imagesActive)) {
|
||||
return route('product_image', [$this->imagesActive->first()->slug]);
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getProductUrl(){
|
||||
return 'https://mivita.shop/produkte/alle-produkte/'.$this->slug;
|
||||
public function getProductUrl()
|
||||
{
|
||||
return 'https://mivita.shop/produkte/alle-produkte/'.$this->slug;
|
||||
}
|
||||
|
||||
public function country_prices()
|
||||
|
|
@ -346,96 +381,160 @@ class Product extends Model
|
|||
return $this->hasMany(ProductIngredient::class, 'product_ingredients', 'id');
|
||||
}
|
||||
|
||||
public function getActionName($id = 0){
|
||||
if(isset($this->actions[$id])){
|
||||
/**
|
||||
* Bundle-Items: Enthaltene Produkte in diesem Set/Kit
|
||||
*/
|
||||
public function bundleItems()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'product_bundles', 'product_id', 'bundle_product_id')
|
||||
->withPivot('quantity', 'pos')
|
||||
->orderBy('product_bundles.pos');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bundle-Parents: Sets/Kits, die dieses Produkt enthalten
|
||||
*/
|
||||
public function bundleParents()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'product_bundles', 'bundle_product_id', 'product_id')
|
||||
->withPivot('quantity', 'pos');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft ob dieses Produkt ein Set/Kit ist (enthält andere Produkte)
|
||||
*/
|
||||
public function isBundle(): bool
|
||||
{
|
||||
return $this->bundleItems()->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt Bundle-Items mit eager loading
|
||||
*/
|
||||
public function product_bundles()
|
||||
{
|
||||
return $this->hasMany(ProductBundle::class, 'product_id', 'id')->orderBy('pos');
|
||||
}
|
||||
|
||||
public function getActionName($id = 0)
|
||||
{
|
||||
if (isset($this->actions[$id])) {
|
||||
return $this->actions[$id];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getUpgradeToIdName($from){
|
||||
if($from === 'payment_for_shop_upgrade'){
|
||||
public function getUpgradeToIdName($from)
|
||||
{
|
||||
if ($from === 'payment_for_shop_upgrade') {
|
||||
$value = Product::find($this->upgrade_to_id);
|
||||
}
|
||||
if($from === 'payment_for_lead_upgrade'){
|
||||
if ($from === 'payment_for_lead_upgrade') {
|
||||
$value = UserLevel::find($this->upgrade_to_id);
|
||||
}
|
||||
if($value){
|
||||
if ($value) {
|
||||
return $value->name;
|
||||
}
|
||||
return "not found";
|
||||
|
||||
return 'not found';
|
||||
}
|
||||
|
||||
public function _format_number($value){
|
||||
return preg_replace("/[^0-9,]/", "", $value);
|
||||
public function _format_number($value)
|
||||
{
|
||||
return preg_replace('/[^0-9,]/', '', $value);
|
||||
}
|
||||
|
||||
public function setPriceAttribute( $value ) {
|
||||
public function setPriceAttribute($value)
|
||||
{
|
||||
|
||||
$this->attributes['price'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
$this->attributes['price'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
public function setPriceEkAttribute( $value ) {
|
||||
|
||||
$this->attributes['price_ek'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
public function setPriceEkAttribute($value)
|
||||
{
|
||||
|
||||
$this->attributes['price_ek'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
public function setTaxAttribute( $value ) {
|
||||
|
||||
public function setTaxAttribute($value)
|
||||
{
|
||||
|
||||
$this->attributes['tax'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
public function setPriceOldAttribute( $value ) {
|
||||
|
||||
$this->attributes['price_old'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
public function setPriceOldAttribute($value)
|
||||
{
|
||||
|
||||
$this->attributes['price_old'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function setPointsAttribute($value)
|
||||
{
|
||||
$this->attributes['points'] = $value !== null ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function getFormattedPoints()
|
||||
{
|
||||
return isset($this->attributes['points']) ? Util::formatNumber($this->attributes['points']) : '';
|
||||
}
|
||||
|
||||
public function getFormattedPrice()
|
||||
{
|
||||
return isset($this->attributes['price']) ? Util::formatNumber($this->attributes['price']) : "";
|
||||
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']) : "";
|
||||
return isset($this->attributes['price_ek']) ? Util::formatNumber($this->attributes['price_ek']) : '';
|
||||
}
|
||||
|
||||
|
||||
public function getFormattedPriceOld()
|
||||
{
|
||||
return isset($this->attributes['price_old']) ? Util::formatNumber($this->attributes['price_old']) : "";
|
||||
return isset($this->attributes['price_old']) ? Util::formatNumber($this->attributes['price_old']) : '';
|
||||
}
|
||||
|
||||
/*price by user Factor*/
|
||||
private function calcPriceUserFactor($price, $user=null){
|
||||
if($this->no_commission){
|
||||
/* price by user Factor */
|
||||
private function calcPriceUserFactor($price, $user = null)
|
||||
{
|
||||
if ($this->no_commission) {
|
||||
return $price;
|
||||
}
|
||||
$user = $user ? $user : \Auth::user();
|
||||
if($user && $user->user_level){
|
||||
$margin = (($user->user_level->margin -100)*-1) / 100;
|
||||
if ($user && $user->user_level) {
|
||||
$margin = (($user->user_level->margin - 100) * -1) / 100;
|
||||
$price = $price * $margin;
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
private function calcPriceUserCommission($price, $user){
|
||||
if($this->no_commission){
|
||||
private function calcPriceUserCommission($price, $user)
|
||||
{
|
||||
if ($this->no_commission) {
|
||||
return $price;
|
||||
}
|
||||
$user = $user ? $user : \Auth::user();
|
||||
if($user && $user->user_level){
|
||||
if ($user && $user->user_level) {
|
||||
$margin = $user->user_level->margin;
|
||||
$price = $price / 100 * $margin;
|
||||
$price = $price / 100 * $margin;
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
|
||||
/*price net*/
|
||||
private function calcPriceNet($price, $country=null){
|
||||
/* price net */
|
||||
private function calcPriceNet($price, $country = null)
|
||||
{
|
||||
$tax = $this->getTaxWith($country);
|
||||
$tax_rate = ($tax + 100) / 100;
|
||||
$tax_rate = ($tax + 100) / 100;
|
||||
|
||||
return $price / $tax_rate;
|
||||
}
|
||||
//price calu with
|
||||
public function getPriceWith(Bool $net = true, Bool $ufactor = true, $country = null, $commission=false, $user = null){
|
||||
|
||||
// price calu with
|
||||
public function getPriceWith(bool $net = true, bool $ufactor = true, $country = null, $commission = false, $user = null)
|
||||
{
|
||||
$price = isset($this->attributes['price']) ? $this->attributes['price'] : null;
|
||||
$cprice = $country ? $this->getCPrice($country) : null;
|
||||
$price = $cprice ? $cprice : $price;
|
||||
|
|
@ -446,19 +545,21 @@ class Product extends Model
|
|||
return round($price, 2);
|
||||
}
|
||||
|
||||
/*out*/
|
||||
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, $commission)) : "";
|
||||
/* out */
|
||||
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, $commission)) : '';
|
||||
}
|
||||
|
||||
public function getTaxWith($country = null){
|
||||
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 getFormattedPriceOldWith(Bool $net = true, Bool $ufactor = true, $country = null)
|
||||
public function getFormattedPriceOldWith(bool $net = true, bool $ufactor = true, $country = null)
|
||||
{
|
||||
$price = isset($this->attributes['price_old']) ? $this->attributes['price_old'] : null;
|
||||
$cprice = $country ? $this->getCPriceOld($country) : null;
|
||||
|
|
@ -466,105 +567,120 @@ class Product extends Model
|
|||
$price = $net ? $this->calcPriceNet($price, $country) : $price;
|
||||
$price = $ufactor ? $this->calcPriceUserFactor($price) : $price;
|
||||
$price = round($price, 2);
|
||||
return isset($price) ? Util::formatNumber($price) : "";
|
||||
}
|
||||
|
||||
return isset($price) ? Util::formatNumber($price) : '';
|
||||
}
|
||||
|
||||
public function getFormattedTax($country = null)
|
||||
{
|
||||
return isset($this->attributes['tax']) ? Util::formatNumber($this->getTaxWith($country), 0) : "";
|
||||
return isset($this->attributes['tax']) ? Util::formatNumber($this->getTaxWith($country), 0) : '';
|
||||
}
|
||||
|
||||
public function getBasePriceFormattedFullWith(Bool $net = true, Bool $ufactor = true, $country = null){
|
||||
public function getBasePriceFormattedFullWith(bool $net = true, bool $ufactor = true, $country = null)
|
||||
{
|
||||
$price = $this->getPriceWith($net, $ufactor, $country);
|
||||
if($price = $this->getBasePriceWith($price)){
|
||||
if ($price = $this->getBasePriceWith($price)) {
|
||||
$unit = $this->attributes['unit'];
|
||||
//ml g
|
||||
if($unit === 1 || $unit === 2){
|
||||
return Util::formatNumber($price) . ' € / 100 '.$this->getUnitType();
|
||||
// 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();
|
||||
// l kg
|
||||
if ($unit === 3 || $unit === 4) {
|
||||
return Util::formatNumber($price).' € / 1 '.$this->getUnitType();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getBasePriceWith($price){
|
||||
if(isset($this->attributes['unit']) && isset($this->attributes['contents_total']) && $this->attributes['contents_total'] != 0){
|
||||
public function getBasePriceWith($price)
|
||||
{
|
||||
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){
|
||||
// ml g
|
||||
if ($unit === 1 || $unit === 2) {
|
||||
return $price * 100 / $this->attributes['contents_total'];
|
||||
}
|
||||
//l kg
|
||||
if($unit === 3 || $unit === 4){
|
||||
return $price * 1000 / $this->attributes['contents_total'];
|
||||
// l kg
|
||||
if ($unit === 3 || $unit === 4) {
|
||||
return $price * 1000 / $this->attributes['contents_total'];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getBasePriceFormattedFull(){
|
||||
if($price = $this->getBasePrice()){
|
||||
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();
|
||||
// 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();
|
||||
// l kg
|
||||
if ($unit === 3 || $unit === 4) {
|
||||
return Util::formatNumber($price).' € / 1 '.$this->getUnitType();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getBasePriceFormatted(){
|
||||
if($price = $this->getBasePrice()){
|
||||
public function getBasePriceFormatted()
|
||||
{
|
||||
if ($price = $this->getBasePrice()) {
|
||||
return Util::formatNumber($price);
|
||||
}
|
||||
return "";
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getBasePrice(){
|
||||
if(isset($this->attributes['unit']) && isset($this->attributes['contents_total']) && $this->attributes['contents_total'] != 0){
|
||||
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){
|
||||
// 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'];
|
||||
// l kg
|
||||
if ($unit === 3 || $unit === 4) {
|
||||
return $this->attributes['price'] * 1000 / $this->attributes['contents_total'];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public function getUnitType(){
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getUnitType()
|
||||
{
|
||||
return isset($this->unitTypes[$this->unit]) ? __($this->unitTypes[$this->unit]) : '-';
|
||||
}
|
||||
public function getShowAtType(){
|
||||
|
||||
public function getShowAtType()
|
||||
{
|
||||
return isset($this->showATs[$this->show_at]) ? $this->showATs[$this->show_at] : '-';
|
||||
}
|
||||
|
||||
public function getShowOnTypes(){
|
||||
public function getShowOnTypes()
|
||||
{
|
||||
$ret = [];
|
||||
if($this->show_on && is_array($this->show_on)){
|
||||
foreach($this->show_on as $show){
|
||||
if ($this->show_on && is_array($this->show_on)) {
|
||||
foreach ($this->show_on as $show) {
|
||||
$ret[] = isset($this->showONs[$show]) ? $this->showONs[$show] : '-';
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function setPosAttribute($value){
|
||||
public function setPosAttribute($value)
|
||||
{
|
||||
$this->attributes['pos'] = is_numeric($value) ? $value : null;
|
||||
}
|
||||
|
||||
|
||||
public function getLang($key)
|
||||
{
|
||||
$lang = \App::getLocale();
|
||||
|
|
@ -572,58 +688,75 @@ class Product extends Model
|
|||
return $this->{$key};
|
||||
}
|
||||
$trans = $this->getTrans($key, $lang);
|
||||
return $trans != '' ? $trans : $this->{$key};
|
||||
|
||||
return $trans != '' ? $trans : $this->{$key};
|
||||
}
|
||||
|
||||
public function getTrans($key, $lang)
|
||||
{
|
||||
$trans = $this->translations->where('language','=', $lang)->where('key', $key)->first();
|
||||
$trans = $this->translations->where('language', '=', $lang)->where('key', $key)->first();
|
||||
|
||||
return $trans ? $trans->value : '';
|
||||
}
|
||||
|
||||
public function getTranNames()
|
||||
{
|
||||
$ret = "";
|
||||
foreach ((array) $this->trans_name as $value){
|
||||
$ret = '';
|
||||
foreach ((array) $this->trans_name as $value) {
|
||||
$ret .= $value.', ';
|
||||
}
|
||||
|
||||
return rtrim($ret, ', ');
|
||||
}
|
||||
|
||||
public function getCountryPrice(Country $country){
|
||||
if($country->own_eur){
|
||||
return $this->country_prices->where('country_id', '=', $country->id)->first() ?: new CountryPrice();
|
||||
public function getCountryPrice(Country $country)
|
||||
{
|
||||
if ($country->own_eur) {
|
||||
return $this->country_prices->where('country_id', '=', $country->id)->first() ?: new CountryPrice;
|
||||
}
|
||||
return new CountryPrice();
|
||||
|
||||
return new CountryPrice;
|
||||
}
|
||||
|
||||
public function getCPrice(Country $country){
|
||||
public function getCPrice(Country $country)
|
||||
{
|
||||
return $this->getCountryPrice($country)->c_price;
|
||||
}
|
||||
public function getCTax(Country $country){
|
||||
|
||||
public function getCTax(Country $country)
|
||||
{
|
||||
return $this->getCountryPrice($country)->c_tax;
|
||||
}
|
||||
public function getCPriceOld(Country $country){
|
||||
|
||||
public function getCPriceOld(Country $country)
|
||||
{
|
||||
return $this->getCountryPrice($country)->c_price_old;
|
||||
}
|
||||
public function getCCurrency(Country $country){
|
||||
|
||||
public function getCCurrency(Country $country)
|
||||
{
|
||||
return $this->getCountryPrice($country)->c_currency;
|
||||
}
|
||||
|
||||
public function getRealPrice(Country $country){
|
||||
if($country->own_eur && $this->getCPrice($country)){
|
||||
public function getRealPrice(Country $country)
|
||||
{
|
||||
if ($country->own_eur && $this->getCPrice($country)) {
|
||||
return $this->getCPrice($country);
|
||||
}
|
||||
|
||||
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;
|
||||
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 "" ;
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue