<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class OrderProduct extends Model
{
    public $timestamps = false;

    protected $fillable = [
        'count'	,'total',	'product_cost'	,'tax',	'product_id',	'choice_id',	'order_id'
    ];

    public function getGetCodeAttribute()
    {
        return $this->choice ? ($this->choice->code  ? $this->choice->code : $this->product->code) : $this->product->code;
    }
    
    public function product()
    {
        return $this->belongsTo(Product::class)->withTrashed();
    }

    public function choice()
    {
        return $this->belongsTo(ProductAttributeChoice::class,'choice_id');
    }

}
