PK œqhYî¶J‚ßF ßF ) nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/
| Dir : /home/distinctdesign/waywardhoundbakery.com/app/ |
| Server: Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 IP: 162.0.232.53 |
| Dir : /home/distinctdesign/waywardhoundbakery.com/app/Product.php |
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class Product extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'products';
/**
* The database primary key value.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['product_title', 'description','price', 'is_giftcard'];
public function categorys()
{
return $this->belongsTo('App\Category', 'category', 'id');
}
public function attributes()
{
return $this->hasMany('App\ProductAttribute', 'product_id', 'id');
}
public function attributesPrice()
{
$data = $this->hasOne('App\ProductAttribute', 'product_id', 'id')->orderby('id', 'asc')->first();
if($data->price == 0){
return $data->regular_price;
}
return $data->price;
}
public function getProductPrice(){
$price = 0;
if($this->price == 0){
if($this->price == 0){
$price = $this->attributesPrice();
}else{
$price = $this->regular_price;
}
}else{
$price = $this->price . ' <strike>$' . $this->regular_price. '</strike>';
}
return $price;
}
public function getMinPrice(){
$price = [];
$discount_price = [];
$att = DB::table('product_attributes')->where('product_id', $this->id)->get();
foreach($att as $key => $value){
if($value->price != 0){
array_push($price, $value->price);
}
}
if(count($att) == 0){
return '$'.$this->getProductPrice();
}else{
if(min($price) == max($price)){
if((count($discount_price) != 0) && ($discount_price[0] != 0)){
return '$'.min($price) . ' <strike>'.$discount_price[0].'</strike>';
}else{
return '$'.min($price);
}
}else{
return '$'.min($price) . ' – ' . '$'.max($price);
}
}
}
}