Customers Add+Edit, API WP

This commit is contained in:
Kevin Adametz 2020-06-12 14:46:51 +02:00
parent 37e00c0eb7
commit 4bd888e6d6
114 changed files with 7821 additions and 2967 deletions

View file

@ -95,6 +95,14 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @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)
*/
class Product extends Model
{
@ -115,7 +123,8 @@ class Product extends Model
'trans_description' => 'array',
'trans_usage' => 'array',
'trans_ingredients' => 'array',
'action' => 'array'
'action' => 'array',
'wp_number' => 'int'
];
use Sluggable;
@ -137,6 +146,7 @@ class Product extends Model
'contents_total',
'unit',
'number',
'wp_number',
'icons',
'description',
'usage',
@ -209,6 +219,10 @@ class Product extends Model
return $this->hasMany('App\Models\ProductImage', 'product_id', 'id')->where('active', true)->orderBy('pos');
}
public function country_prices()
{
return $this->hasMany(CountryPrice::class, 'product_id');
}
public function getActionName($id = 0){
if(isset($this->actions[$id])){
@ -330,4 +344,30 @@ class Product extends Model
}
return rtrim($ret, ', ');
}
public function getCountryPrice($country_id){
return $this->country_prices->where('country_id', '=', $country_id)->first() ?: new CountryPrice();
}
public function getCPrice($country_id){
return $this->getCountryPrice($country_id)->c_price;
}
public function getCTax($country_id){
return $this->getCountryPrice($country_id)->c_tax;
}
public function getCPriceOld($country_id){
return $this->getCountryPrice($country_id)->c_price_old;
}
public function getCCurrency($country_id){
return $this->getCountryPrice($country_id)->c_currency;
}
public function getRealPrice(Country $country){
if($country->own_eur && $this->getCPrice($country->id)){
return $this->getCPrice($country->id);
}
return $this->price;
}
}