First Commit
This commit is contained in:
commit
610aa1e202
4204 changed files with 636764 additions and 0 deletions
194
app/Models/Product.php
Normal file
194
app/Models/Product.php
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* App\Models\Product
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property array|null $trans_name
|
||||
* @property string $title
|
||||
* @property array|null $trans_title
|
||||
* @property string|null $copy
|
||||
* @property array|null $trans_copy
|
||||
* @property float|null $price
|
||||
* @property float|null $price_ek
|
||||
* @property float|null $tax
|
||||
* @property float|null $price_old
|
||||
* @property string|null $contents
|
||||
* @property string|null $number
|
||||
* @property array|null $icons
|
||||
* @property string|null $description
|
||||
* @property array|null $trans_description
|
||||
* @property string|null $usage
|
||||
* @property array|null $trans_usage
|
||||
* @property string|null $ingredients
|
||||
* @property array|null $trans_ingredients
|
||||
* @property int|null $pos
|
||||
* @property int $active
|
||||
* @property int|null $amount
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property \Illuminate\Support\Carbon|null $deleted_at
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductAttribute[] $attributes
|
||||
* @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()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereActive($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereAmount($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereContents($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereCopy($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereDescription($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereIcons($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereIngredients($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereNumber($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product wherePos($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product wherePrice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product wherePriceEk($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product wherePriceOld($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereTax($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereTitle($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereTransCopy($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereTransDescription($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereTransIngredients($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereTransName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereTransTitle($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereTransUsage($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereUpdatedAt($value)
|
||||
* @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
|
||||
*/
|
||||
class Product extends Model
|
||||
{
|
||||
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'
|
||||
];
|
||||
|
||||
use SoftDeletes;
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
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 setPriceVkAttribute( $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()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['price'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['price'], 2, ',', '.');
|
||||
}
|
||||
|
||||
public function getFormattedPriceVk()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['price_ek'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['price_ek'], 2, ',', '.');
|
||||
}
|
||||
|
||||
public function getFormattedTax()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['tax'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['tax'], 2, ',', '.');
|
||||
}
|
||||
|
||||
public function getFormattedPriceOld()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['price_old'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['price_old'], 2, ',', '.');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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, ', ');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue